如何在Java中生成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上的数据是否过于庞大。那么我们如何将它移到下一张纸上呢?
答案 0 :(得分:0)
如果首先完成了一定数量的行,则可以创建下一个csv文件。如果某些行已完成,则在第二个csv中,您可以编写下一个csv文件。
但在我的建议中,将数据写入数据库,那么一切都会非常简单。数据插入,检索,编辑等将非常简单