LiHan_siyuan
2011-11-24 17:39poi 解析excel问题
以下是程序中的一段代码,正常的的excel2003或者2007文件都能解析,以及2007的文件另存在2003的文件之后也能够正常导入;
问题:2003的文件另存为2007的文件之后,导入就出现异常了;
[code="java"]publicWorkbook getWorkbook(File file,String fileName){
Workbook wb = null;
InputStream input = null;
if(file == null || fileName == null)
{
return wb;
}
//获取excel文件
try
{
input = new FileInputStream(file);
if (!input.markSupported()) {
input = new PushbackInputStream(input, 8);
}
if (POIFSFileSystem.hasPOIFSHeader(input)) {//2003
wb = new HSSFWorkbook(input);
}else if (POIXMLDocument.hasOOXMLHeader(input)) {//2007
wb = new XSSFWorkbook(OPCPackage.open(input));
}else{
System.out.println("不支持");
}
}
catch (Exception e)
{
e.printStackTrace();
}
return wb;
}[/code]
望哪位朋友指点下~
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- java 中 poi读取需刷新宏的excel单元格
- java
- eclipse
- 1个回答
- win7系统报错getOutputStream() has already been called for this response.但是xp系统没问题...
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 0个回答
- npoi画excel图形时如何设置图形透明度
- poi解析excel
- excel
- c#
- 1个回答
- java获取excle并自动生成word报表
- spring
- poi解析excel
- poi操作word
- java
- 4个回答
- java解析Excel根据行和列获取对应的单元格数据
- java
- excel
- 数据
- 3个回答
换一换