JSP 用poi 读取Excel
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="org.apache.poi.poifs.filesystem.*" %>
<%@ page import="org.apache.poi.ss.usermodel.CellType" %> <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Generate SQL </title>
</head>
<body>
<h1>TemplateName <%= request.getParameter("TemplateName")%> </h1>
<p> <%
String templateName = request.getParameter("TemplateName");
String srcTemplateName=templateName+"_src";
String trgTemplateName=templateName+"_trg";
String primaryKeyDefine="PK nvarchar(150)";
String PrimaryKey ="PK";
String FilterCondition="a.PK=b.PK";
String SystemIdentity="WFS";
String srcQuery="";
String trgQuery="";
String SQL ="INSERT INTO [dbo].[BusinessLogicCmpDefine] ([TemplateName],[SrcTemplateName],[TrgTemplateName],[PrimaryKeyDefine],[PrimaryKey] ,[FilterCondition] ,[SystemIdentity])"; SQL=SQL+" <br> VALUES ('" +templateName+ "','"+srcTemplateName+"','"+trgTemplateName+"','"+primaryKeyDefine+"','"+PrimaryKey+"','"+FilterCondition+"','"+SystemIdentity+"')"; out.println(SQL); %> </p>
<h2>View <%=srcTemplateName%> </h2>
<p>
Create view [dbo].[<%=srcTemplateName%>]
<br>
as
<br>
<% try (FileInputStream fileIn = new FileInputStream("c:\\demo.xls")) {
POIFSFileSystem fs = new POIFSFileSystem(fileIn);
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0); for (int k = 1; k <= sheet.getLastRowNum(); k++) {
HSSFRow row = sheet.getRow(k);
if(row !=null){
HSSFCell cell = row.getCell(1);
if(cell==null){
out.println("no data<br>");
}else{
String value =cell.getStringCellValue(); if(value.equals(templateName)){ HSSFCell srcQueryCell = row.getCell(5);
srcQuery=srcQueryCell.getStringCellValue().replaceAll("\r|\n","<br>");; HSSFCell trgQueryCell = row.getCell(6);
trgQuery=trgQueryCell.getStringCellValue().replaceAll("\r|\n","<br>");
out.println(srcQuery+"<br> "); } }
}
}
}
%> </p>
<h2>View <%=trgTemplateName%></h2>
<p>
Create view [dbo].[<%=trgTemplateName%>]
<br>
as
<br>
<%out.println(trgQuery+"<br> ");%>
</p> <h2>Excute SQL</h2>
<p>
exec USP_CompareR1AndR3Data '<%=templateName%>' ,'WFS'
</p>
<p>
今天的日期是: <%= (new java.util.Date()).toLocaleString()%> </p>
</body>
</html>
上面是今天下午刚学的代码,还不能兼容xlsx的格式,晚上学习的代码可以兼容xlsx的格式。下载的poi中有弟三方类库,需要放到tomcat的lib目录中才,并且使用下面的代码。
<%--
Created by IntelliJ IDEA.
User: hellohongfu
Date: 2017/12/21
Time: 0:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.io.*,java.util.*" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="org.apache.poi.poifs.filesystem.*" %>
<%@ page import="org.apache.poi.ss.usermodel.*" %>
<%@ page import="org.apache.poi.xssf.usermodel.*" %>
<html>
<head>
<title>excel demo</title>
</head>
<body> <%
InputStream inp = new FileInputStream("c:\\demo.xlsx");
//InputStream inp = new FileInputStream("workbook.xlsx"); Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
for (int k = 1; k <= sheet.getLastRowNum(); k++){
Row row=sheet.getRow(k);
Cell cell = row.getCell(1);
if (cell != null){
String value =cell.getStringCellValue();
out.println("cell value:"+value+"<br>");
} } Row row = sheet.getRow(2);
Cell cell = row.getCell(3); out.println(cell.getStringCellValue());
if (cell == null)
cell = row.createCell(3);
cell.setCellType(CellType.STRING); // Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
%>
</body>
</html>
JSP 用poi 读取Excel的更多相关文章
- 使用jxl,poi读取excel文件
作用:在java后台添加一个方法,读取导入的excel内容,根据需要返回相应的sql语句,以完成对临时表的插入操作. 使用jxl读取excel文件 package com.sixthf.bi.sapp ...
- POI读取Excel内容格式化
在用POI读取Excel内容时,经常会遇到数据格式化的问题. 比如:数字12365会变为12365.0;字符串数字123也会变为123.0,甚至会被变为科学计数法.另外日期格式化也是一个头疼的问题.其 ...
- java使用poi读取ppt文件和poi读取excel、word示例
java使用poi读取ppt文件和poi读取excel.word示例 http://www.jb51.net/article/48092.htm
- JAVA使用POI读取EXCEL文件的简单model
一.JAVA使用POI读取EXCEL文件的简单model 1.所需要的jar commons-codec-1.10.jarcommons-logging-1.2.jarjunit-4.12.jarlo ...
- java用poi读取Excel表格中的数据
Java读写Excel的包是Apache POI(项目地址:http://poi.apache.org/),因此需要先获取POI的jar包,本实验使用的是POI 3.9稳定版.Apache POI 代 ...
- Java开发小技巧(六):使用Apache POI读取Excel
前言 在数据仓库中,ETL最基础的步骤就是从数据源抽取所需的数据,这里所说的数据源并非仅仅是指数据库,还包括excel.csv.xml等各种类型的数据接口文件,而这些文件中的数据不一定是结构化存储的, ...
- 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据
1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...
- 使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10
使用POI 读取 Excel 文件,读取手机号码 变成 1.3471022771E10 [问题点数:40分,结帖人xieyongqiu] 不显示删除回复 ...
- Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决
Java之POI读取Excel的Package should contain a content type part [M1.13]] with root cause异常问题解决 引言: 在Java中 ...
随机推荐
- 【Luogu】P3800点收集(DP)
题目链接 原题解 代码 #include<iostream> #include<cstdio> #include<cstring> #include<ccty ...
- 2013 Dhaka 区域赛
A.uva 12709 Falling ANTS 首先按照H排序,然后按照L*H*W排序 #include<iostream> #include<cstdio> #includ ...
- leetcode 94 中序遍历模板
/**递归的写法 * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * Tre ...
- 如何解决"The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path"
今天我在eclipse上搭建新项目时,莫名其妙的出现这个错误,如下: The superclass "javax.servlet.http.HttpServlet" was not ...
- Little Bird(BZOJ 3831)
题目大意: 有一排n棵树,第i棵树的高度是Di. MHY要从第一棵树到第n棵树去找他的妹子玩. 如果MHY在第i棵树,那么他可以跳到第i+1,i+2,...,i+k棵树. 如果MHY跳到一棵不矮于当前 ...
- 玩转css样式选择器----当父元素有多个子元素时选中最后一个
- hdu 4951
Multiplication table Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- msp430项目编程57
msp430综合项目---扩展项目七57 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- call 和 apply 方法区别
在js中call和apply它们的作用都是将函数绑定到另外一个对象上去运行,两者仅在定义参数方式有所区别,下面我来给大家介绍一下call和apply用法. 在web前端开发过程中,我们经常需要改变th ...
- ngxtop
http://www.cnblogs.com/felixzh/p/8709201.html