public static void main(String[] args) {
??ListPortAction.test();
?}
??? public static void test(){
??try{
???String targetfile = "c:/1.xls";
????? OutputStream os = new FileOutputStream(targetfile);
????? jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(os);
????? jxl.write.WritableSheet ws = wwb.createSheet("Test Sheet 1", 0);
????? for(int i=0;i<50;i++){
????? ?if(i!=0){
????? ??InputStream in = new FileInputStream(targetfile);
????? ??Workbook wb = Workbook.getWorkbook(in);
????? ??os = new FileOutputStream(targetfile);
????? ??wwb = Workbook.createWorkbook(os,wb);
????? ??ws = wwb.getSheet(0);
????? ??wb.close();????? ????
????? ??in.close();
????? ?}
????? ?for(int j=0;j<1000;j++){
????? ??Label l = new Label(0,j+i*1000,"測試");
????? ??ws.addCell(l);
????? ?}
????? ?try{
????? ?wwb.write();
????? ?wwb.close();
????? ?os.flush();
????? ?os.close();
????? ?}catch(Exception e){
?????? ?System.out.println("錯誤2:");
??????? e.printStackTrace();
????? ?}
????? }
???? }catch(Exception e){
???? ?System.out.println("錯誤:");
????? e.printStackTrace();
???? }
?}
以上是我寫的一個測試類,寫5W條記錄現在是沒有問題,先存硬盤,然后從硬盤獲取流,最后可以寫到response的outputStream中,不過感覺自己的代碼質量不是很好,歡迎高手多多指教??梢曰ハ嘟涣魉枷?。
posted on 2006-09-01 09:51
陳琪 閱讀(2087)
評論(1) 編輯 收藏