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

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

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

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:
sir, how to convert excel file to csv file using java? please send me sample code.
sir, how to read empty cell in excel file using poi and how to add this empty cell to arraay list and the following is my code
Advertisements
how to convert .xml file to csv file
how to convert war file into .exe file using java code
convert excel file data into different locales while converting exclile file to csv file
how to send email please give me details with code in jsp,servlet
how to create an excel file using java
how to use Excel Templet to write excel file using java.
How to save form data to a csv file using jquery or ajax
how to parse a csv file using standard libraries?
i want java code for this xml file...please show me..
how to use Excel Template to write excel file using java
How to Retrieve Data from the database and write into excel file using Java
How to convert excel file int xml format in java
How to read a rows which have a values in a excel file using apache poi - JSP-Servlet
how to convert doc file into html using java swing
excel file using JDBC java.?
how to save html form data into .csv file using only jsp.
How to link a excel file with a application software using java swing
How to link a excel file with a application software using java swing
How to link an excel file with the application software using java swing
How to delete excel file records using Store Procedure?
How to browse excel file and stored the contents into the database using jsp/servlet?
How to export data from html file to excel sheet by using java
How to export data from html file to excel sheet by using java
upload a file into database and progrm should support excel and text and csv file formats
Excel file wriring using java
Java code to convert pdf file to word file
Upload CSV File into Columns of sql table using servlets and jsp
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
Javah -  Header File Generator

Ads