gpt4 book ai didi

java - 双引号中的值在导出到 Excel 时不起作用

转载 作者:行者123 更新时间:2023-12-01 13:32:59 27 4
gpt4 key购买 nike

在我用 java 编写的导出到 Excel 功能中,双引号中的值在下载的 Excel 中消失了。有没有解决这个问题的方法?

最佳答案

How you are trying to export the data into excel? please post?

Simple example with Apache POI-
{
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Test Export");
Map<String, Object[]> data = new HashMap<String, Object[]>();
//cell value in double quotes
data.put("2", new Object[] {"1", "\"abc\""});
data.put("3", new Object[] {"2", "\"xyz\""});
Set<String> keyset = data.keySet();
int rownum = 0;
for (String key : keyset) {
Row row = sheet.createRow(rownum++);
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr) {
Cell cell = row.createCell(cellnum++);
cell.setCellValue((String)obj);
}
}
try {
FileOutputStream out =new FileOutputStream(new File("/home/rahul/Desktop/testExport.xls"));
workbook.write(out);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

关于java - 双引号中的值在导出到 Excel 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21446582/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com