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









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
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
how to convert .xml file to csv file
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 send email please give me details with code in jsp,servlet
how to parse a csv file using standard libraries?
how to create an excel file using java
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
i want java code for this xml file...please show me..
How to convert excel file int xml format in java
How to Retrieve Data from the database and write into excel file using Java
how to save html form data into .csv file using only jsp.
excel file using JDBC java.?
How to read a rows which have a values in a excel file using apache poi - JSP-Servlet
convert .txt file in .csv format - Java Beginners
How to delete excel file records using Store Procedure?
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
upload a file into database and progrm should support excel and text and csv file formats
how to convert doc file into html using java swing
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
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
please convert for me this code to GUI - Swing AWT
downloading excel file using Java and springs
Javah -  Header File Generator
please convert for me this code to GUI - Swing AWT
Excel file wriring using java
How to write into CSV file in Java
Java code to convert pdf file to word file
PHP code for csv file upload into mysql
how to read data from excel file through browse and insert into oracle database using jsp or oracle???
please send me javascript validation code - Java Beginners
Linking excel file with a application tool using swing
how to convert a jar file into .exe file
please let me get code how to insert a data to mysql using setter and getter method by using java
please let me get code how to insert a data to mysql using setter and getter method by using java
To read & write a excel file using the core java
How to Read Excel file Using Java
How do I import a CSV file in R?
Please guide me sir - EJB
please send me the banking data base in swings
csv file download
How to upload a large excel file - JSP-Servlet

Ads