如何在java中使用apache poi在excel中显示绝对路径

时间:2014-07-29 10:13:30

标签: java apache-poi

我的csv文件包含文件夹的绝对路径 d:\比较\ 5.0.60, d:\比较\ 5.0.60, 当我尝试使用excel中的apache poi输出将这些数据导出到excel时,就像这样D:compare5.0.60

以下是将数据从csv导出到excel的代码

public void cvstoexcel()
{
     Workbook wb = new HSSFWorkbook();
        CreationHelper helper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet("Compare");

        CSVReader reader;
        String[] line;
        int r = 0;
        setWorkbookDefaultFontToBold(wb);
        try {
            reader = new CSVReader(new FileReader("D:\myfile.csv"));
            while ((line = reader.readNext()) != null) {
                Row row = sheet.createRow((short) r++);
                for (int i = 0; i < line.length; i++)


                        row.createCell(i).setCellValue(helper.createRichTextString(line[i]));

            }
        }

         catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        // Write the output to a file
        FileOutputStream fileOut;
        try {
            parentFolder = yourFile.getParent();
            fileOut = new FileOutputStream(parentFolder+File.separator+"DCompare.xls");
               wb.write(fileOut);
                fileOut.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

}

但我需要输出就像cvs文件D:\ compare \ 5.0.60请帮忙

0 个答案:

没有答案