Creating CSV to EXCEL file in java

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@bijendrachauhan·
0.000 HBD
Creating CSV to EXCEL file in java
import java.io.FileOutputStream;
import java.io.FileReader;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import au.com.bytecode.opencsv.CSVReader;

public class CreateCSVToExcel {
	public void createCSVTOELs(String sourcePath,String destinationPath) throws Exception
    {
    	
    	
    	        Workbook wb = new HSSFWorkbook();
    	        CreationHelper helper = wb.getCreationHelper();
    	        Sheet sheet = wb.createSheet("new sheet");

    	        CSVReader reader = new CSVReader(new FileReader(sourcePath));
    	        String[] line;
    	        int r = 0;
    	        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]));
    	        }

    	        // Write the output to a file
    	        FileOutputStream fileOut = new FileOutputStream(destinationPath);
    	        wb.write(fileOut);
    	        fileOut.close();
    	    
    	}
    

}


<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@bijendrachauhan/creating-csv-to-excel-file-in-java">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍 , , ,