Online Hibernate Training just in Rs. 1000

One week online training in Hibernate ORM framework. Learn Hibernate Framework and enhance your skills. Best Online Hibernate training at 90% discount. Join Now!! Offer is valid Only for limited Period!!! Online Training Big Data and Hadoop Training Java Training  
 

sir, how to convert excel file to csv file using java? please send me sample code.

Ads

 
 

Share on Google+Share on Google+

hariprasad
sir, how to convert excel file to csv file using java? please send me sample code.
2 Answer(s)      6 years and 5 months ago
Posted in : Development process

please send me sample code for converting excel file into csv file uisng java.

Ads
View Answers

March 8, 2011 at 5:38 PM


import java.io.*;
import jxl.*;
import java.util.*;

class  ConvertExcelToCSV
{
  public static void main(String[] args) 
  {
    try
    {
      String filename = "C:/data.xls";
      WorkbookSettings ws = new WorkbookSettings();
      ws.setLocale(new Locale("en", "EN"));
      Workbook w = Workbook.getWorkbook(new File(filename),ws);

      File f = new File("c:/new.csv");
      OutputStream os = (OutputStream)new FileOutputStream(f);
      String encoding = "UTF8";
      OutputStreamWriter osw = new OutputStreamWriter(os, encoding);
      BufferedWriter bw = new BufferedWriter(osw);


      for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++)
      {
        Sheet s = w.getSheet(sheet);

        bw.write(s.getName());
        bw.newLine();

        Cell[] row = null;

        for (int i = 0 ; i < s.getRows() ; i++)
        {
          row = s.getRow(i);

          if (row.length > 0)
          {
            bw.write(row[0].getContents());
            for (int j = 1; j < row.length; j++)
            {
              bw.write(',');
              bw.write(row[j].getContents());
            }
          }
          bw.newLine();
        }
      }
      bw.flush();
      bw.close();
    }
    catch (Exception e)
    {
      System.err.println(e);
    }

  }
}


March 8, 2011 at 5:41 PM


For the above code, you need JExcel Api,

Download it


Ads









Related Tutorials/Questions & Answers:
Advertisements