我用jxl读取excel,获得workbook和sheet时出现异常,请求帮忙!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我用jxl读取excel,获得workbook和sheet时出现异常,请求帮忙!相关的知识,希望对你有一定的参考价值。
Warning: Cannot read name ranges for Cstatus - setting to empty
Warning: Cannot read name ranges for Division - setting to empty
Warning: Cannot read name ranges for Esqr - setting to empty
Warning: Cannot read name ranges for ESqr1 - setting to empty
Warning: Cannot read name ranges for Esqr2 - setting to empty
Warning: Cannot read name ranges for Fast - setting to empty
Warning: Cannot read name ranges for FASTROLE - setting to empty
Warning: Cannot read name ranges for FASTROLL - setting to empty
Warning: Cannot read name ranges for JobFunction - setting to empty
Warning: Cannot read name ranges for JVPortal - setting to empty
Warning: Cannot read name ranges for JVPortal2 - setting to empty
Warning: Cannot read name ranges for PersonType1 - setting to empty
Warning: Cannot read name ranges for Position - setting to empty
Warning: Cannot read name ranges for Print_Area - setting to empty
Warning: Cannot read name ranges for PRTS_Request - setting to empty
Warning: Cannot read name ranges for RoleCodes - setting to empty
Warning: Cannot read name ranges for RollCodes - setting to empty
Warning: Cannot read name ranges for STAT - setting to empty
common.AssertionFailed
at common.Assert.verify(Assert.java:37)
at jxl.read.biff.WorkbookParser.getName(WorkbookParser.java:1118)
at jxl.biff.formula.NameRange.read(NameRange.java:88)
at jxl.biff.formula.TokenFormulaParser.parseSubExpression(TokenFormulaParser.java:214)
at jxl.biff.formula.TokenFormulaParser.parse(TokenFormulaParser.java:111)
at jxl.biff.formula.FormulaParser.parse(FormulaParser.java:110)
at jxl.biff.DVParser.<init>(DVParser.java:431)
at jxl.biff.DataValiditySettingsRecord.initialize(DataValiditySettingsRecord.java:140)
at jxl.biff.DataValiditySettingsRecord.getFirstColumn(DataValiditySettingsRecord.java:234)
at jxl.read.biff.SheetReader.read(SheetReader.java:1016)
at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:686)
at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:252)
at aa.BooleanTest.readExcel(BooleanTest.java:52)
at aa.BooleanTest.main(BooleanTest.java:28)
Exception in thread "main" common.AssertionFailed
不行就把你的代码贴上···
// 创建可写入的Excel工作薄
OutputStream os = new FileOutputStream("D:\\数据汇总分析表.xls");
WritableWorkbook workbook1 = Workbook.createWorkbook(os);
WritableSheet sheet = workbook1.createSheet("数据汇总分析表", 0);追问
这个错误不是一开始就有的,之前只是报内存溢出错误,我一修改jvm的参数,它才出现这个错误,所以绝对不是代码问题!而且后面验证这个内存溢出问题不是因为数据量大的问题,而是因为excel中运用了格式什么的原因,因为我把除了头部分的数据外全部copy到另外一个excel表中就没有了错误!
参考技术A 如果不是代码错误,就是jxl包的版本不够,更新jxl包的版本后再试试若果仍然报错试试这个:
package jxl_excel;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class JxlExcel
/**
* @param args
* @throws IOException
* @throws BiffException
*/
public static void main(String[] args) throws BiffException, IOException
InputStream is = new FileInputStream("c:\\a.xls");//path是文件路径
Workbook wb = Workbook.getWorkbook(is);// 获得工作薄
Sheet st = wb.getSheet(0);
//获得总行数
int rowSize=st.getRows();
//获得总列数
int columnSize=st.getColumns();
if(rowSize!=0)
for(int i=1;i<rowSize;i++)
for (int j=0;j<columnSize;j++)
//st.getCell(j,i).getContents()括号内的参数j代表总列数,i代表总行数
System.out.println(st.getCell(j,i).getContents());
追问
这个错误不是一开始就有的,之前只是报内存溢出错误,我一修改jvm的参数,它才出现这个错误,所以绝对不是代码问题!
追答可能是jvm参数修改错误导致的吧
本回答被提问者和网友采纳Jxl创建Excel文件和解析Excel文件
import java.io.File; import jxl.Workbook; import jxl.write.Label; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; public class JxlExpExcel { /** * Jxl创建Excel文件 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //用数组定义一个表头 String[] title={"id","name","sex"}; //创建Excel文件 File file=new File("d:/jxl_test.xls"); try { file.createNewFile(); //创建工作薄 WritableWorkbook workbook=Workbook.createWorkbook(file); //创建sheet WritableSheet sheet=workbook.createSheet("sheet1", 0); Label lable=null; for (int i = 0; i < title.length; i++) { lable=new Label(i,0,title[i]); sheet.addCell(lable); } //追加数据 for (int i = 1; i < 100; i++) { lable=new Label(0,i,"a"+i); sheet.addCell(lable); lable=new Label(1,i,"user"+i); sheet.addCell(lable); lable=new Label(2,i,"男"); sheet.addCell(lable); } //写入数据 workbook.write(); //关闭流 workbook.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
import java.io.File; import jxl.Cell; import jxl.Sheet; import jxl.Workbook; public class JxlReadExcel { /** * 解析Excel文件 * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { //创建workbook Workbook workbook=Workbook.getWorkbook(new File("d:/jxl_test.xls")); //获取第一个工作表sheet Sheet sheet=workbook.getSheet(0); //获取数据 for (int i = 0; i < sheet.getRows(); i++) { for (int j = 0; j < sheet.getColumns(); j++) { Cell cell=sheet.getCell(j,i); System.out.print(cell.getContents()+" "); } System.out.println(); } //关闭流 workbook.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
以上是关于我用jxl读取excel,获得workbook和sheet时出现异常,请求帮忙!的主要内容,如果未能解决你的问题,请参考以下文章
java的jxl读取excel文件时报错Object record is not associated with a drawing record - ignoring