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

Ads
 

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

Ads