请问下 为什么 jxl 怎么能只能插入一行数据

drizztguai 2010-04-10 11:49:27
我想把ACCESS里的数据导入到excel里面

但是插入后只有一行显示在excel里面。


try
{
c = DriverManager.getConnection( "jdbc:odbc:students", "","" );
sq1 = c.createStatement();
rs = sq1.executeQuery("select * from stu" );
int index=0;
WritableWorkbook book;
try {
book = Workbook.createWorkbook(new File("e:/atoecel.xls"));
WritableSheet sheet = book.createSheet("Sheet_1", 0);

while (rs.next())
{
s1 = rs.getString(1);
s2 = rs.getString(2);
s3 = rs.getString(3);
s4 = rs.getString(4);
Label label1 = new Label (0,index,s1);
sheet.addCell(label1);
Label label2 = new Label (1,index,s2);
sheet.addCell(label2);
Label label3 = new Label (2,index,s3);
sheet.addCell(label3);
Label label4 = new Label (3,index,s4);
sheet.addCell(label4);
book.write();
index++;
}
c.close();
book.close();
}
catch (Exception e)
{
}
}
catch (Exception ex)
{

}


请大家指教,谢谢
...全文
167 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zuoguodang 2010-04-10
  • 打赏
  • 举报
回复
楼上说的对,你这等于write了一次,就是最后一次。把write()放到循环外面
awusoft 2010-04-10
  • 打赏
  • 举报
回复
book.write();
放到循环外

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧