0

したがって、csv を xls/xlsx に変更しましたが、セルごとに 1 文字を取得しています。csv の区切り文字としてパイプ (|) を使用しました。csv からの 1 行は次のとおりです。

しかし、Excelでは 4 になっています。0 | SDFA

コードは次のとおりです。

    try {
        String csvFileAddress = "manage_user_info.csv"; //csv file address
        String xlsxFileAddress = "manage_user_info.xls"; //xls file address
        HSSFWorkbook workBook = new HSSFWorkbook();
        HSSFSheet sheet = workBook.createSheet("sheet1");
        String currentLine=null;
        int RowNum=0;
        BufferedReader br = new BufferedReader(new FileReader(csvFileAddress));
        while ((currentLine = br.readLine()) != null) {
            String str[] = currentLine.split("|");
            RowNum++;
            HSSFRow currentRow=sheet.createRow(RowNum);
            for(int i=0;i<str.length;i++){
                currentRow.createCell(i).setCellValue(str[i]);
            }
        }

        FileOutputStream fileOutputStream =  new FileOutputStream(xlsxFileAddress);
        workBook.write(fileOutputStream);
        fileOutputStream.close();
        System.out.println("Done");
    } catch (Exception ex) {
        System.out.println(ex.getMessage()+"Exception in try");
    }
4

1 に答える 1