5 Replies Latest reply: Sep 18, 2012 9:03 PM by EJP RSS

    JAVA code to Convert Excel file To XML file

    916888
      Hi,


      I am new to java ,Any one please share me the code to convert Excel file in to xml file.


      Thanks in advance.
        • 1. Re: JAVA code to Convert Excel file To XML file
          rp0428
          >
          I am new to java ,Any one please share me the code to convert Excel file in to xml file.
          >
          Take a look at the Apache POI project.
          http://poi.apache.org/
          • 2. Re: JAVA code to Convert Excel file To XML file
            916888
            Thanks for the reply.

            Appreciate your help, Any one please share the code
            • 3. Re: JAVA code to Convert Excel file To XML file
              DrClap
              Share the code?

              If you thought about the problem for a minute or two, you would realize that there is an infinite number of possible formats for the Excel data, and an infinite number of possible formats for the XML data. So asking for "the code" to convert any of the first infinite number of formats to one of the second infinite number of formats is a little bit unrealistic. Wouldn't you agree?
              • 4. Re: JAVA code to Convert Excel file To XML file
                962213
                Here is a sample code for reading an Excel file. It uses JExcel API:

                package com.quicklyjava;

                import jxl.*;
                import jxl.read.biff.BiffException;

                import java.io.File;
                import java.io.IOException;

                public class JavaExcelRead {

                /**
                * @param args
                */
                public static void main(String[] args) {

                try {

                //Create a workbook object from the file at specified location.
                //Change the path of the file as per the location on your computer.
                Workbook wrk1 = Workbook.getWorkbook(new File("C:/test.xls"));

                //Obtain the reference to the first sheet in the workbook
                Sheet sheet1 = wrk1.getSheet(0);

                //Obtain reference to the Cell using getCell(int col, int row) method of sheet
                Cell colArow1 = sheet1.getCell(0, 0);
                Cell colBrow1 = sheet1.getCell(1, 0);
                Cell colArow2 = sheet1.getCell(0, 1);

                //Read the contents of the Cell using getContents() method, which will return
                //it as a String
                String str_colArow1 = colArow1.getContents();
                String str_colBrow1 = colBrow1.getContents();
                String str_colArow2 = colArow2.getContents();

                //Display the cell contents
                System.out.println("Contents of cell Col A Row 1: \""+str_colArow1 + "\"");
                System.out.println("Contents of cell Col B Row 1: \""+str_colBrow1 + "\"");
                System.out.println("Contents of cell Col A Row 2: \""+str_colArow2 + "\"");


                } catch (BiffException e) {
                e.printStackTrace();
                } catch (IOException e) {
                e.printStackTrace();
                }


                }

                }




                You can further process this to convert the data extracted into XML. Hope this helps!
                • 5. Re: JAVA code to Convert Excel file To XML file
                  EJP
                  Entire thread is off topic for these forums. Locking.