java jxl.jar为什么只写入了一个单元格,cell1明明都得到了啊。写入方法看如下代码,请高人指点
public void writer(){
try
{
Workbook booka= Workbook.getWorkbook(new File("F:网络账号记录表.xls"));
//获得第一个工作表对象
Sheet sheeta=booka.getSheet(0);
int a = sheeta.getColumns();
int b = sheeta.getRows();
WritableWorkbook book = Workbook.createWorkbook(new File("F:网络账号记录表副本.xls"));
WritableSheet sheet = book.createSheet("第一页", 0);
for(int c=0;c<b;c++){
for(int i=0;i<a;i++){
Cell cell1=sheeta.getCell(i,c);
String result=cell1.getContents();
Label label = new Label(i, c, result);
sheet.addCell(label);
book.write();
}
}
book.close();
booka.close();
} catch (Exception e) {
System.out.println(e);
}
}
------解决方案--------------------
把book.write();放到循环外面。
Java code
for(int c=0;c<b;c++){
for(int i=0;i<a;i++){
Cell cell1=sheeta.getCell(i,c);
String result=cell1.getContents();
Label label = new Label(i, c, result);
sheet.addCell(label);
}
}
[color=#FF0000]book.write();[/color]
book.close();
booka.close();