2014-01-08 30 views
0

如何在使用Java生成CSV時將數據寫入下一頁?如何在生成CSV時將數據寫入下一張表格?

    response.setContentType("text/csv"); 
     response.setCharacterEncoding("UTF-8"); 
     response.setHeader("Content-disposition", 
       "inline; filename=\"mGovData.csv\""); 


     OutputStream outputStream = response.getOutputStream(); 

     byte[] bom = new byte[] { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF }; 
     outputStream.write(bom); // adds BOM 

     Writer out = new BufferedWriter(new OutputStreamWriter(
       outputStream, "UTF-8")); 

     if (otmstatus != null 
       || (StringUtils.isNotBlank(otmfrmDate) && StringUtils 
         .isNotBlank(otmtoDate)) 
       || (otmdaystate != null && from != null && to != null)) { 

      // Write the content 
      if (otmfrmDate != null && otmtoDate != null) { 
       from = new SimpleDateFormat("dd-MM-yyyy").parse(otmfrmDate); 
       // to = new SimpleDateFormat("dd-MM-yyyy").parse(otmtoDate); 
       DateFormat d = new SimpleDateFormat("dd-MM-yyyy"); 
       to = d.parse(otmtoDate); 
       to.setHours(23); 
       to.setMinutes(59); 
       to.setSeconds(59); 
      } 

      otmConfigDtos = otmManager.getOtmDetailsForReport(otmstatus, 
        from, to, sp_Id, otmdaystate, otmphoneNo, msgText); 

      String csvTitles = getText("lbl.report.generate.pdf.text.otm") 
        + "," + "\n" 
        + getText("lbl.report.generate.pdf.text.documentdate") 
        + new Date().toString() + "," + "\n" 
        + getText("lbl.report.generate.pdf.text.reportdate") 
        + " " 
        + getText("lbl.report.generate.pdf.text.dateform") 
        + " " + DateFormatUtils.format(from, "dd/MM/yyyy") 
        + " " + getText("lbl.report.generate.pdf.text.dateto") 
        + " " + DateFormatUtils.format(to, "dd/MM/yyyy") + "\n"; 

      out.write(csvTitles); 

out.flush(); 
     out.close(); 
     outputStream.close(); 
} 

我想知道寫在CSV上的數據是否過於龐大。那麼我們如何將它移動到下一張表格?

+1

csv沒有'表'的概念。傳單工作。 – Jayan

+0

謝謝jayan ..但它只在網頁上以excel格式下載.. Excel有10萬行左右的限制嗎? – Vicky

+0

當然,Excel可以加載CSV數據,而Excel確實有'表'的概念,但是CSV不能。它比Excel使用的格式簡單得多。 –

回答

0

如果在第一行中完成了一定數量的行,則可以創建下一個csv文件。在第二個csv中,如果某些行已完成,那麼您可以編寫下一個csv文件。

但在我的建議是,將數據寫入數據庫,然後一切都會非常簡單。數據插入,檢索,編輯等將非常簡單

+0

但我只從動態檢索的DB記錄生成csv。所以我不知道有多少記錄動態地從數據庫中取出。如果它超過最大值,那麼我如何創建下一個csv,如你所說? – Vicky

+0

@Vicky - 請告訴我你用這個生成的csv有什麼用? –

+0

政府報告分析 – Vicky

相關問題