使用JExcel解析Excel文件
2006-02-28 22:27
288 查看
http://www.hyweb.net/blogs/
在使用Java读取和分析Excel文件时,通常是通过组件来完成的,比较常用的包括POI和JExcel,本文简单阐述了如何使用JExcel读入一个Excel文件,当文件读取后,可以做出自己的解析和修改操作,再加修改后的结果发回到JSP页面。
JSP页面:
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*"%>
<%@ page import="net.hyweb.*"%>
<%
String temp = "C://TEMP";
com.sysway.oa.service.tools.Fileupload fileUpload = new com.sysway.oa.service.tools.Fileupload(temp, "/WEB-INF", request);
//通过检测checkbox的选择情况,确定文件上传路径
if(request.getParameterValues("ch1") != null){
String[] ch1 = request.getParameterValues("ch1");
if(ch1[0].equals("ch1")){
System.out.println("ch1 checked...");
String des1 = request.getRealPath("/FinancialReports/excelFile");
des1 = des1 + "//";
fileUpload.setDestinationPath(des1);
boolean uploadResult1 = fileUpload.Upload(true);
}
}
%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>File upload JavaBean Page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<LINK HREF="/res/skin/skycloud/base.css" REL=stylesheet TYPE="text/css">
<LINK HREF="/res/skin/skycloud/list.css" REL=stylesheet TYPE="text/css">
</head>
<body>
文件上传成功 <br>
</body>
</html>
Java文件:
/*
* Author: Huang ye(www.hyweb.net)
* 代码开源, 引用请注明出处
*
* 2005-11-14
*
*/
package net.hyweb;
import java.io.File;
import java.io.OutputStream;
import jxl.Workbook;
public class ExcelConvertor {
public ExcelConvertor() {
super();
// TODO 自动生成构造函数存根
}
/**
* 传入目标xls文件位置,返回读出的excel文件
*/
public static void writeExcel(String inputPath, OutputStream os) throws Exception {
//A factory method which takes in an excel file and reads in the contents.
Workbook inWorkbook = Workbook.getWorkbook(new File(inputPath));
//Creates a writable workbook as a copy of the workbook passed in.
jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os, inWorkbook);
//将具体的处理逻辑(针对sheet和cell)放入这里
//写入Exel工作表
wwb.write();
//关闭Excel工作薄对象
wwb.close();
System.out.println("YES!");
}
}
相关文章推荐
- 使用JExcel API创建 Excel 文件
- 使用Java泛型和反射机制编写Excel文件生成和解析的通用工具类
- 使用jacob对word.excel文件进行完美解析(缺点是不支持linux)
- 【python】解析Excel中使用xlrd库、xlwt库操作,写入Excel文件详解(二)
- 使用maven+springmvc+POI对上传的Excel文件进行解析并操作
- 使用JAVA通过JXL(JExcel)动态生成Excel文件 转载至台湾某博客
- poi读取Excel时日期为数字 的解决方法 转载 2017年12月14日 10:31:14 标签:poi /excel /java 19 在使用poi解析Excel文件时,会发现,表格中的日期解析出
- Java基础系列19:使用JXL或者POI生成和解析Excel文件
- Excel文件上传,解析,下载(一 文件上传,使用MultipartFile来实现)
- 使用Apache FileUpload 上传以及 JExcelApi 生成Excel文件
- 【Java】使用Apache POI生成和解析Excel文件
- 使用jexcel读写excel文件的例子
- 使用 jExcelAPI 操作 Excel 文件
- 使用POI解析excel文件方法总结
- Java 使用poi解析Excel文件(兼容2007)
- 使用JExcel导出excel文件
- C#读取excel文件的内容(使用DataSet)
- 使用LayaAir解析xml文件
- 解析excel/读取Excel文件【绝对成功】
- 使用boost库解析xml配置文件