[code="java"]
private void readWriter(){
WritableWorkbook wwb=null;
WritableSheet wws=null;
FileOutputStream out =null;
ByteArrayOutputStream targetFile=null;
File is = new File("f:\ExcelTest\try.xls");
try {
out = new FileOutputStream("f:\ExcelTest\try1.xls");
Workbook wb = Workbook.getWorkbook(is);
targetFile = new ByteArrayOutputStream();
wwb = Workbook.createWorkbook(targetFile, wb);
wws = wwb.createSheet("Sheet名称",0);
Label label= new Label(2,0,"单元格内容");
wws.addCell(label);
targetFile.writeTo(out);
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
wwb.close();
out.close();
targetFile.close();
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
[/code]
为什么我输出excel文件的时候,excel里面什么都,我到底哪里写错了呢
targetFile.writeTo(out);
这个是什么啊!
用wws.write();;
Ok?
你是用的poi?
不是, jxl
我记得需要调用write()方法 才往文件里写。
[code="java"]wwb = Workbook.createWorkbook(file);// 创建可写工作薄
WritableSheet ws = wwb.createSheet("业务量酬金明细", 0);
WritableFont font = new WritableFont(WritableFont.ARIAL, 14);
WritableCellFormat writableCellFormat = new WritableCellFormat(
font);
writableCellFormat.setAlignment(Alignment.CENTRE);
writableCellFormat.setShrinkToFit(true);
writableCellFormat.setWrap(true);
ws.mergeCells(0, 0, head.length - 1, 2);
ws.addCell(new Label(0, 0, mipOrg.getOrgName() + " " + addTime
+ "业务量酬金明细报表", writableCellFormat));
for (int i = 0; i < head.length; i++) {
ws.setColumnView(i, 20);
Label label = new Label(i, 3, head[i], writableCellFormat);
ws.addCell(label);
}
for (int i = 4; i < list.size() + 4; i++) {
Stipend stipendDetail = (Stipend) list.get(i - 4);
Label label = new Label(0, i, stipendDetail.getOrgCode(),
writableCellFormat);
ws.addCell(label);
label = new Label(1, i, stipendDetail.getQuotaName(),
writableCellFormat);
ws.addCell(label);
label = new Label(2, i, stipendDetail.getQuotaValue()
.toString(), writableCellFormat);
ws.addCell(label);
label = new Label(3, i, stipendDetail.getBusinessCount()
.toString(), writableCellFormat);
ws.addCell(label);
label = new Label(4, i, stipendDetail.getAddTime(),
writableCellFormat);
ws.addCell(label);
}
wwb.write();[/code]