双引号中的值不能导出到excel

时间:2014-01-30 02:12:41

标签: java excel

在我用java编写的excel功能导出中,双引号中的值在下载的excel中消失了。这个有什么工作吗?

1 个答案:

答案 0 :(得分:1)

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();
        }
}