Depends what XML schema you want to work with, but as a basic example using
JDOM and the usermodel:

                
                Document document = new Document();
                Element rootElement = new Element("Excel_Document")
                document.setRootElement(rootElement);           
                POIFSFileSystem fs = new POIFSFileSystem(new
FileInputStream("SOME FILENAME"));
                HSSFWorkbook wb = new HSSFWorkbook(fs);
                for (short i = 0; i < wb.getNumberOfSheets(); i++)
                {
                        Element sheetElement = new Element("worksheet");
                        rootElement.addContent(sheetElement);
                        HSSFSheet sheet = wb.getSheetAt(i);

                        for (int j = 0; j < sheet.getLastRowNum(); j++)
                        {
                                Element rowElement = new Element("row");
                                sheetElement.addContent(rowElement);
                                HSSFRow theRow = sheet.getRow(j);
                                        
                                for (short k = 0; k <
theRow.getLastCellNum(); k++)
                                {
                                        Element cellElement = new
Element("cell");
                                        rowElement.addContent(cellElement);
                                        HSSFCell theCell =
theRow.getCell(k);
                                        if (theCell != null)
                                        {
                                                switch
(theCell.getCellType())
                                                {
                                                        case
HSSFCell.CELL_TYPE_STRING :
        
cellElement.addContent(theCell.getStringCellValue());
                                                                break;
                                                        case
HSSFCell.CELL_TYPE_NUMERIC :
        
cellElement.addContent("" + theCell.getNumericCellValue());
                                                                break;
                                                        //handle other cell
types if you need to
                                                }
                                        } 
                                } 
                        } 
                }
                
                //output xml document 


-----Original Message-----
From: nitish kumar sinha [mailto:[EMAIL PROTECTED]
Sent: 12 December 2003 10:18
To: [EMAIL PROTECTED]
Subject: Converting Excel to Xml 


Hi 
I want to Convert Excel file to Xml file.Could u send me a sample code for
this.
nitish


This e-mail and any attachment is for authorised use by the intended recipient(s) 
only. It may contain proprietary material, confidential information and/or be subject 
to legal privilege. It should not be copied, disclosed to, retained or used by, any 
other party. If you are not an intended recipient then please promptly delete this 
e-mail and any attachment and all copies and inform the sender. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to