如何在使用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上的數據是否過於龐大。那麼我們如何將它移動到下一張表格?
csv沒有'表'的概念。傳單工作。 – Jayan
謝謝jayan ..但它只在網頁上以excel格式下載.. Excel有10萬行左右的限制嗎? – Vicky
當然,Excel可以加載CSV數據,而Excel確實有'表'的概念,但是CSV不能。它比Excel使用的格式簡單得多。 –