Reading Excel, XML MAP element name using Apache POI
<p>I have a business requirement in which I have been provided with excel document that has xml mapping in place (basically using excel menu option Developer-> Source and then selecting an xml file and mapping XML elements to the excel cells). For eg: Value in cell A2 is mapped to xml element "document_title", B2 is mapped to "document_number".</p>

<p>The requirement is to read the excel document programmatically and search for a list of XML elements and find the mapped cells and the contents of the cell. For eg: Search xml element "document_title" and find the cell to which this element is mapped to (in the example mentioned above, this is A2) and read the content of the cell.</p>

<p>I have tried using OPCP package and XSSFReader classes of apache POI and try to parse it using DOMParser but unable to achieve this. </p>

<p>Following is a trimmed version of source code, can someone please help me in the right direction.</p>

<pre><code>public static void main( String[] args ) throws IOException
{
    System.out.println( "reading excel" );

    try {
        OPCPackage pkg = OPCPackage.open("D:\\test.xlsx");
        XSSFReader r = new XSSFReader( pkg ); 
        SharedStringsTable sst = r.getSharedStringsTable();

        InputStream inp = r.getSheet("rId1"); 

        InputSource inpSource = new InputSource(inp);

        DOMParser parser = new DOMParser(); 
        parser.parse(inpSource); 

        Document doc = parser.getDocument(); 
        inp.close();  // dont know yet, how to read each element, and hence trying to write this to a file

        OutputStream writer = new FileOutputStream("D:\\outtrId11.xml"); 
        TransformerFactory transfac = TransformerFactory.newInstance(); 
        Transformer trans = transfac.newTransformer(); 
                                trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); 
        trans.setOutputProperty(OutputKeys.INDENT, "yes"); 
        trans.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); 

        //create string from xml tree 

        StreamResult result = new StreamResult(writer); 
        DOMSource source = new DOMSource(doc); 
        trans.transform(source, result);            

    } catch (InvalidFormatException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (OpenXML4JException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SAXException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TransformerConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (TransformerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
</code></pre>

<p>Please let me know in case of any queries/suggestions. Any help will be really appreciated</p>