0

I am converting csv file to excel using CsvMapReader. But for few files am getting exception as below:

Exception in thread "main" org.supercsv.exception.SuperCsvException: the nameMapping array and the sourceList should be the same size (nameMapping length = 0, sourceList size = 11) context=null

Tried many alternatives but not able to resolve.

Please help to resolve this, pasting a part of my code:

String fName = filename;
String outputFile = "";
Workbook wb = new HSSFWorkbook();
FileOutputStream fileOut;

if(!new File(filename).exists()){    
    System.out.println("File Not Found");

} else{
    try {
        ICsvMapReader csvMapReader = new CsvMapReader(new FileReader(
                fName), CsvPreference.EXCEL_PREFERENCE);


        final String[] headers = csvMapReader.getHeader(true);

        Map csvRow;
        outputFile = fName.substring(0, fName.length() - 4);
        fileOut = new FileOutputStream(outputFile + ".xls");
        Sheet sheet = wb.createSheet("products");

        int rowNo = 0;
        createExcelHeader(sheet, rowNo, fName);    //Seperate function      

        **while ((csvRow = csvMapReader.read()) != null) {** //getting exception at this point
            rowNo++;
            Row excelRow = sheet.createRow(rowNo);
            createExcelRow(csvRow, excelRow, fName); //Seperate function
        }

        csvMapReader.close();
        wb.write(fileOut);
        fileOut.close();

        System.out.println("*");

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Bentaye
  • 9,403
  • 5
  • 32
  • 45
Gayathri
  • 41
  • 1
  • 8
  • Possible duplicate of [Messed up CSV leads to Exception](https://stackoverflow.com/questions/13585914/messed-up-csv-leads-to-exception) – Capricorn May 13 '18 at 19:39
  • No tried those solutions in my case its not solving my issue Please help with any other resolutions – Gayathri May 15 '18 at 16:41

0 Answers0