You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "a.rubalcaba" <a....@yahoo.com> on 2010/01/22 19:54:59 UTC

XSSFExportToXML help trying to export xlsx to xml

Hi,

I am currently trying to convert a Excel xlsx file into xml.

I've gone though and done some custom mapping according to this example.  
http://openxmldeveloper.org/articles/2268.aspx 

Yet when I run it through my code I get  

Exception in thread "main" java.lang.NullPointerException
	at
org.apache.poi.xssf.extractor.XSSFExportToXml.indexOfElementInComplexType(XSSFExportToXml.java:431)
	at
org.apache.poi.xssf.extractor.XSSFExportToXml.compare(XSSFExportToXml.java:412)
	at
org.apache.poi.xssf.extractor.XSSFExportToXml.compare(XSSFExportToXml.java:78)
	at java.util.Arrays.mergeSort(Arrays.java:1284)
	at java.util.Arrays.sort(Arrays.java:1223)
	at java.util.Collections.sort(Collections.java:159)
	at
org.apache.poi.xssf.extractor.XSSFExportToXml.exportToXML(XSSFExportToXml.java:158)
	at
org.apache.poi.xssf.extractor.XSSFExportToXml.exportToXML(XSSFExportToXml.java:102)
	at com.poi.sample.XSFFExportSample.main(XSFFExportSample.java:30)


I was however able to run the CustomXMLMapping sample that I got off SVN.
I'm wondering if I'm not mapping things correctly in the Excel spreadsheet
but when I verify if the spreadsheet can be exported to XML it gives me no
problems. I'm also able to click Save As XML and have no issue.

I uploaded the project as a zip file in case anyone wants to look at it.

Here is the code I'm using

public static void main(String[] args) {
		try {
			InputStream inp = new FileInputStream("Book1.xlsx");
			XSSFWorkbook wb = new XSSFWorkbook(inp);
			for(XSSFMap map : wb.getCustomXMLMappings())
			{
				XSSFExportToXml exporter = new XSSFExportToXml(map);
				OutputStream writer = new FileOutputStream("outxml.xml"); 
				exporter.exportToXML(writer, false);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (TransformerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

Here is the schema I'm using for testing

<complexType name="GolfClubType">
    <complexContent>

      <extension base="tns:GolfManufacturerType">
        <sequence>
          <element name="ClubKind" type="tns:ClubKindType"></element>
          <element name="Loft" type="string"></element>
          <element name="Shaft" type="tns:ShaftType"></element>
        </sequence>
      </extension>
    </complexContent>
  </complexType>

  <simpleType name="ClubKindType">
    <restriction base="string">
      <enumeration value="Driver"></enumeration>
      <enumeration value="Wood"></enumeration>
      <enumeration value="Iron"></enumeration>
      <enumeration value="Wedge"></enumeration>
      <enumeration value="Putter"></enumeration>
    </restriction>
  </simpleType>

  <simpleType name="ShaftType">
    <restriction base="string">
      <enumeration value="Regular"></enumeration>
      <enumeration value="Stiff"></enumeration>
    </restriction>
  </simpleType>

If anyone wants I can upload the spreadsheet as well.


Any ideas on how to better convert xlsx file to XML? 




-- 
View this message in context: http://old.nabble.com/XSSFExportToXML-help-trying-to-export-xlsx-to-xml-tp27278396p27278396.html
Sent from the POI - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org