乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>java</em>导出excel jxls需要用那些包

<em>java</em>导出excel jxls需要用那些包

作者:乔山办公网日期:

返回目录:excel表格制作


Workbook workbook = Workbook.getWorkbook(new File(filePath));
e79fa5e98193e4b893e5b19e361 Sheet sheet = workbook.getSheet(0);
int col = sheet.getColumns();
int row = sheet.getRows();
String result[][] = new String[row][col];
Cell cell;
// i列 j行
System.out.println("col:"+col+" row: "+row);

for (int i = 0; i < row; i++) {
if(i!=0){
SubjectEntity sub=new SubjectEntity();
for (int j = 0; j < col; j++) {
cell = sheet.getCell(j, i);
result[i][j] = cell.getContents();
if(j==0){
sub.setQuestion(result[i][j]);
}else if(j==1){
sub.setSort(result[i][j]);
}else if(j==2){
sub.setMark(Float.valueOf(result[i][j]));
}else if(j==3){
sub.setRatio(Integer.valueOf(result[i][j]));
}else{
OptionEntity opt=new OptionEntity();
if(!cell.toString().contains("EmptyCell")){ //若是空的单元格会包括EmptyCell
Colour c=cell.getCellFormat().getBackgroundColour();
if(c.equals(Colour.RED)) //红色的为正确答案
opt.setIfright(1);
else
opt.setIfright(0);
opt.setOptionText(result[i][j]);
opt.setSubject(sub);
sub.getOptions().add(opt);
}
}
}
sub.setKemu(kemu);
dao.save(sub);
list.add(sub);

}
}

POI 3.6
Commons BeanUtils
Commons Collections
Commons JEXL
Commons Logging
Commons Digester 可以去 jxls的官网去看看介绍。里面有详细的包下载的链接。
你是要问什么啊?我们是js中生成的表格,用poi导出。用的是ssi框架,原理是现在js中遍历表头,再用java把表头生成,之后再把生成的数据再导出

发现你问题的所在了,你把过多的可重用的东西卸写在了循环内
HSSFCellStyle cellStyle = wb.createCellStyle();
HSSFDataFormat format = wb.createDataFormat();
cellStyle.setDataFormat(format.getFormat("@"));
// HSSFRow row = sheet.createRow(i+2);//这句不可重用
HSSFCell policyNoCell = row.createCell((short) 0);
policyNoCell.setCellStyle(cellStyle);
policyNoCell.setCellValue(new HSSFRichTextString(rs.getString(3)));//这句不可重用
你这个完全可以卸载循环外啊,creat这么多,肯定占内存
就算你有多个style,你也可以只需要creat一次,然后反复调用就好了

切记,以后再代码e79fa5e98193e4b893e5b19e334设计中,一定要考虑最大可能的重用,而不是每次需要去创造(new()、crate什么的),这是一种思维,祝你好运

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网