<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:media="http://search.yahoo.com/mrss/"><channel><title><![CDATA[apache poi - JBay Solutions - The Dev Blog]]></title><description><![CDATA[JBay Solutions Development Blog on Java, Android, Play2 and others]]></description><link>http://blog.jbaysolutions.com/</link><generator>Ghost 0.7</generator><lastBuildDate>Wed, 16 Oct 2024 01:15:05 GMT</lastBuildDate><atom:link href="http://blog.jbaysolutions.com/tag/apache-poi/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Reading and converting XML files to Excel in Java]]></title><description><![CDATA[<p>Today we're going to show how to read a XML file and convert it's entries to lines on an excel file. </p>

<p>The XML file is located at <a href="https://github.com/jbaysolutions/xml-to-excel/blob/master/Publication1.xml?raw=true">https://github.com/jbaysolutions/xml-to-excel/blob/master/Publication1.xml?raw=true</a>.</p>

<p><strong>The XML file's main nodes are "Substances", each one has a few</strong></p>]]></description><link>http://blog.jbaysolutions.com/2015/10/16/reading-and-converting-xml-files-to-excel/</link><guid isPermaLink="false">f0159837-7141-49e2-9357-cf838f7e62c0</guid><category><![CDATA[java]]></category><category><![CDATA[apache poi]]></category><category><![CDATA[xml]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Fri, 16 Oct 2015 14:43:45 GMT</pubDate><content:encoded><![CDATA[<p>Today we're going to show how to read a XML file and convert it's entries to lines on an excel file. </p>

<p>The XML file is located at <a href="https://github.com/jbaysolutions/xml-to-excel/blob/master/Publication1.xml?raw=true">https://github.com/jbaysolutions/xml-to-excel/blob/master/Publication1.xml?raw=true</a>.</p>

<p><strong>The XML file's main nodes are "Substances", each one has a few properties "Name", "entry_force", "directive" and a list of "Product". We're going to create an excel row for each Product. Each row will also have the Product parent Substance details.</strong></p>

<p>Below is a sample of the XML structure:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Pesticides&gt;
&lt;Header&gt;
    &lt;Creation_Date&gt;09/07/2015 13:45&lt;/Creation_Date&gt;
&lt;/Header&gt;
&lt;Substances&gt;
    &lt;Name&gt;Garlic extract (++)&lt;/Name&gt;
    &lt;entry_force&gt;01/09/2008&lt;/entry_force&gt;
    &lt;directive&gt;Reg. (EC) No 839/2008&lt;/directive&gt;
    &lt;Product&gt;
        &lt;Product_name&gt;FRUITS, FRESH or FROZEN; TREE NUTS&lt;/Product_name&gt;
        &lt;Product_code&gt;0100000&lt;/Product_code&gt;
        &lt;MRL/&gt;
        &lt;ApplicationDate&gt;01/09/2008&lt;/ApplicationDate&gt;
    &lt;/Product&gt;
    &lt;Product&gt;
        &lt;Product_name&gt;Oranges (Bergamots, Bitter oranges/sour oranges, Blood oranges, Cara caras, Chinottos,
            Trifoliate oranges, Other hybrids of Citrus sinensis, not elsewhere mentioned,)
        &lt;/Product_name&gt;
        &lt;Product_code&gt;0110020&lt;/Product_code&gt;
        &lt;MRL/&gt;
        &lt;ApplicationDate&gt;01/09/2008&lt;/ApplicationDate&gt;
    &lt;/Product&gt;
    &lt;Product&gt;
        &lt;Product_name&gt;Lemons (Buddha's hands/Buddha's fingers, Citrons,)&lt;/Product_name&gt;
        &lt;Product_code&gt;0110030&lt;/Product_code&gt;
        &lt;MRL/&gt;
        &lt;ApplicationDate&gt;01/09/2008&lt;/ApplicationDate&gt;
    &lt;/Product&gt;
    &lt;Product&gt;
        &lt;Product_name&gt;Limes (Indian sweet limes/Palestine sweet limes, Kaffir limes, Sweet limes/mosambis, Tahiti
            limes,)
        &lt;/Product_name&gt;
        &lt;Product_code&gt;0110040&lt;/Product_code&gt;
        &lt;MRL/&gt;
        &lt;ApplicationDate&gt;01/09/2008&lt;/ApplicationDate&gt;
    &lt;/Product&gt;
&lt;/Substances&gt;
&lt;Substances&gt;
(...)
&lt;/Substances&gt;
</code></pre>

<p>As usual, we use  <a href="http://poi.apache.org/" title="Apache POI">Apache POI</a>, to create the excel file.</p>

<p>You can get the sample project used in this post at <a href="https://github.com/jbaysolutions/xml-to-excel">GitHub</a>.</p>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="downloadingthefile">Downloading the file</h2>

<p>We start by downloading the file from it's original URL location:</p>

<pre><code>File xmlFile = File.createTempFile("substances", "tmp");
String xmlFileUrl = "http://ec.europa.eu/food/plant/pesticides/eu-pesticides-database/public/?event=Execute.DownLoadXML&amp;id=1";
URL url = new URL(xmlFileUrl);
System.out.println("downloading file from " + xmlFileUrl + " ...");
FileUtils.copyURLToFile(url, xmlFile);
System.out.println("downloading finished, parsing...");
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="preparingtheexcelfile">Preparing the Excel file</h2>

<p>To create the Excel file where we're writing, we start by creating a new workbook, an empty sheet and writing the first line with the column headers:</p>

<pre><code>workbook = new XSSFWorkbook();

CellStyle style = workbook.createCellStyle();
Font boldFont = workbook.createFont();
boldFont.setBold(true);
style.setFont(boldFont);
style.setAlignment(CellStyle.ALIGN_CENTER);

Sheet sheet = workbook.createSheet();
rowNum = 0;
Row row = sheet.createRow(rowNum++);
Cell cell = row.createCell(SUBSTANCE_NAME_COLUMN);
cell.setCellValue("Substance name");
cell.setCellStyle(style);

cell = row.createCell(SUBSTANCE_ENTRY_FORCE_COLUMN);
cell.setCellValue("Substance entry_force");
cell.setCellStyle(style);

cell = row.createCell(SUBSTANCE_DIRECTIVE_COLUMN);
cell.setCellValue("Substance directive");
cell.setCellStyle(style);

cell = row.createCell(PRODUCT_NAME_COLUMN);
cell.setCellValue("Product name");
cell.setCellStyle(style);

cell = row.createCell(PRODUCT_CODE_COLUMN);
cell.setCellValue("Product code");
cell.setCellStyle(style);

cell = row.createCell(PRODUCT_MRL_COLUMN);
cell.setCellValue("MRL");
cell.setCellStyle(style);

cell = row.createCell(APPLICATION_DATE_COLUMN);
cell.setCellValue("Application Date");
cell.setCellStyle(style);
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="parsing">Parsing</h2>

<p>For this sample, the XML file is parsed using <a href="https://en.wikipedia.org/wiki/Document_Object_Model">DOM</a>.</p>

<p>We get the reference to the excel file sheet:</p>

<pre><code>Sheet sheet = workbook.getSheetAt(0);
</code></pre>

<p>We start by loading the XML document using DOM and getting the Substances node list:</p>

<pre><code>DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile);

NodeList nList = doc.getElementsByTagName("Substances");
</code></pre>

<p>Then we iterate through the Substances list and get the Substance properties:</p>

<pre><code>for (int i = 0; i &lt; nList.getLength(); i++) {
    System.out.println("Processing element " + (i+1) + "/" + nList.getLength());
    Node node = nList.item(i);
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String substanceName = element.getElementsByTagName("Name").item(0).getTextContent();
        String entryForce = element.getElementsByTagName("entry_force").item(0).getTextContent();
        String directive = element.getElementsByTagName("directive").item(0).getTextContent();

        NodeList prods = element.getElementsByTagName("Product");
</code></pre>

<p>When we get to the Product element, we get it as a NodeList and iterate it to get it's details:</p>

<pre><code>for (int j = 0; j &lt; prods.getLength(); j++) {
    Node prod = prods.item(j);
    if (prod.getNodeType() == Node.ELEMENT_NODE) {
        Element product = (Element) prod;
        String prodName = product.getElementsByTagName("Product_name").item(0).getTextContent();
        String prodCode = product.getElementsByTagName("Product_code").item(0).getTextContent();
        String lmr = product.getElementsByTagName("MRL").item(0).getTextContent();
        String applicationDate = product.getElementsByTagName("ApplicationDate").item(0).getTextContent();
</code></pre>

<p>Now that we have all the details we want to write on the excel file, we create a row with all the details:</p>

<pre><code>Row row = sheet.createRow(rowNum++);
Cell cell = row.createCell(SUBSTANCE_NAME_COLUMN);
cell.setCellValue(substanceName);

cell = row.createCell(SUBSTANCE_ENTRY_FORCE_COLUMN);
cell.setCellValue(entryForce);

cell = row.createCell(SUBSTANCE_DIRECTIVE_COLUMN);
cell.setCellValue(directive);

cell = row.createCell(PRODUCT_NAME_COLUMN);
cell.setCellValue(prodName);

cell = row.createCell(PRODUCT_CODE_COLUMN);
cell.setCellValue(prodCode);

cell = row.createCell(PRODUCT_MRL_COLUMN);
cell.setCellValue(lmr);

cell = row.createCell(APPLICATION_DATE_COLUMN);
cell.setCellValue(applicationDate);
</code></pre>

<p>When all the elements are written, we write the excel to the filesystem:</p>

<pre><code>FileOutputStream fileOut = new FileOutputStream("C:/Temp/Excel-Out.xlsx");
workbook.write(fileOut);
workbook.close();
fileOut.close();
</code></pre>

<p>Finally, we delete the downloaded XML file:</p>

<pre><code>if (xmlFile.exists()) {
    System.out.println("delete file-&gt; " + xmlFile.getAbsolutePath());
    if (!xmlFile.delete()) {
        System.out.println("file '" + xmlFile.getAbsolutePath() + "' was not deleted!");
    }
}
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="conclusion">Conclusion</h2>

<p>The sample project used in this post at <a href="https://github.com/jbaysolutions/excel-xml-reader">GitHub</a> has a main class <a href="https://github.com/jbaysolutions/xml-to-excel/blob/master/src/main/java/com/jbaysolutions/xmlreader/XmlToExcelConverter.java">XmlToExcelConverter</a> to download, parse the file and create the excel file.</p>

<p>Feel free to copy and adapt the code to read other XML files! <br>
Hope it helped anyone having the same issues as us!</p>

<h2 id="references">References</h2>

<p><a href="https://en.wikipedia.org/wiki/Document_Object_Model">DOM</a></p>

<p><a href="https://docs.oracle.com/javase/tutorial/jaxp/dom/">DOM Tutorial</a></p>

<p><a href="http://poi.apache.org/" title="Apache POI">Apache POI</a></p>]]></content:encoded></item><item><title><![CDATA[Reading and parsing Excel Spreadsheet XML files with Java]]></title><description><![CDATA[<p>On one of our projects, we were asked to implement a process that updates a database with values from an Excel file on a daily basis. The file is located at <a href="https://github.com/jbaysolutions/excel-xml-reader/raw/master/ActiveSubstance.xls">https://github.com/jbaysolutions/excel-xml-reader/raw/master/ActiveSubstance.xls</a>. The problem with this file is its format. It's an</p>]]></description><link>http://blog.jbaysolutions.com/2015/03/04/parsing-excel-spreadsheet-xml/</link><guid isPermaLink="false">2c3dd67a-5ff8-48b5-8ccb-24c0f2c8bf39</guid><category><![CDATA[java]]></category><category><![CDATA[apache poi]]></category><category><![CDATA[excel]]></category><category><![CDATA[excel spreadsheet xml]]></category><category><![CDATA[excel 2003]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Wed, 04 Mar 2015 17:29:31 GMT</pubDate><content:encoded><![CDATA[<p>On one of our projects, we were asked to implement a process that updates a database with values from an Excel file on a daily basis. The file is located at <a href="https://github.com/jbaysolutions/excel-xml-reader/raw/master/ActiveSubstance.xls">https://github.com/jbaysolutions/excel-xml-reader/raw/master/ActiveSubstance.xls</a>. The problem with this file is its format. It's an <a href="http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example">Excel spreadsheet XML</a>.</p>

<p>Usually we parse excel files using <a href="http://poi.apache.org/" title="Apache POI">Apache POI</a>, but it has no support for Excel spreadsheet XML. The solution was to create our own parser.</p>

<p>For this specific case, we will cover the process of obtaining the substance name (column A), ADI value (column P) and ARfD value (column S).</p>

<p>You can get the sample project used in this post at <a href="https://github.com/jbaysolutions/excel-xml-reader">GitHub</a>.</p>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="downloadingthefile">Downloading the file</h2>

<p>This class was to be used by a timer that runs once a day. Starts by downloading the file:</p>

<pre><code>File file = File.createTempFile("substances", "tmp");

String excelFileUrl = "http://ec.europa.eu/sanco_pesticides/public/?event=activesubstance.exportList";
URL url = new URL(excelFileUrl);
System.out.println("downloading file from " + excelFileUrl + " ...");
FileUtils.copyURLToFile(url, file);
System.out.println("downloading finished, parsing...");
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="parsing">Parsing</h2>

<p>Since the file format is XML, it can be parsed using <a href="http://en.wikipedia.org/wiki/Simple_API_for_XML">SAX</a>.</p>

<p>Since this file has only one sheet, we are keeping the parser simple, so we will only need to find the sheet rows and cells. We declare a class to represent the row:</p>

<pre><code>class XmlRow {
    ArrayList&lt;String&gt; cellList = new ArrayList&lt;&gt;();

    @Override
    public String toString() {
        return cellList.toString();
    }
}
</code></pre>

<p>And a SAX handler to load the rows and cell ("Data" in the XML) contents:</p>

<pre><code>class SAXHandler extends DefaultHandler {

    List&lt;XmlRow&gt; xmlRowList = new ArrayList&lt;&gt;();
    XmlRow xmlRow = null;
    String content = null;

    @Override
    //Triggered when the start of tag is found.
    public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {
        switch (qName) {
            //Create a new Row object when the start tag is found
            case "Row":
                xmlRow = new XmlRow();
                break;
        }
    }

    @Override
    public void endElement(String uri, String localName,
                           String qName) throws SAXException {
        switch (qName) {
            case "Row":
                xmlRowList.add(xmlRow);
                break;
            case "Data":
                xmlRow.cellList.add(content);
                break;
        }
    }

    @Override
    public void characters(char[] ch, int start, int length)
            throws SAXException {
        content = String.copyValueOf(ch, start, length).trim();
    }
}
</code></pre>

<p>Once the file is downloaded, it's loaded to a string to be supplied to the SAX Parser:</p>

<pre><code>String fileContent = IOUtils.toString(new FileInputStream(file));

SAXParserFactory parserFactor = SAXParserFactory.newInstance();
SAXParser parser = parserFactor.newSAXParser();
SAXHandler handler = new SAXHandler();

ByteArrayInputStream bis = new ByteArrayInputStream(fileContent.getBytes());

parser.parse(bis, handler);
</code></pre>

<p>When we try and run this the first time, and exception occurs:</p>

<pre><code>Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 14; The processing instruction target matching "[xX][mM][lL]" is not allowed.
</code></pre>

<p>This happens because some blank space or other visible content exists before the <?xml ?> declaration. For this file, we have to remove the first 2 lines, so it can be parsed:</p>

<pre><code>
<b>removeLineFromFile(file.getAbsolutePath(), 1, 2);</b>

String fileContent = IOUtils.toString(new FileInputStream(file));

SAXParserFactory parserFactor = SAXParserFactory.newInstance();
SAXParser parser = parserFactor.newSAXParser();
SAXHandler handler = new SAXHandler();

ByteArrayInputStream bis = new ByteArrayInputStream(fileContent.getBytes());

parser.parse(bis, handler);
</code></pre>

<p><strong>The removeLineFromFile() method can be found on the sample project source.</strong></p>

<p>When we try to parse it again, another exception is thrown:</p>

<pre><code>Exception in thread "main" org.xml.sax.SAXParseException; lineNumber: 1313; columnNumber: 70; The entity "nbsp" was referenced, but not declared.
</code></pre>

<p>This happens because the entity <code>&amp;nbsp;</code> isn't one of XML's predefined entities. To fix it, we have to prepend this to the file before parsing it:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
&lt;!DOCTYPE some_name [ 
    &lt;!ENTITY nbsp "&amp;#160;"&gt; 
    &lt;!ENTITY acute "&amp;#180;"&gt;
]&gt;
</code></pre>

<p>The <code>&amp;acute;</code> entity was also found on the file, so we added it as well.</p>

<p>There was also the text "JECFA&amp;ECCO" somewhere in a cell which would cause the parser to throw another exception.</p>

<p>The code now looks like this:</p>

<pre><code>removeLineFromFile(file.getAbsolutePath(), 1, 2);

String fileContent = IOUtils.toString(new FileInputStream(file));
fileContent = fileContent.replaceAll("&amp;ECCO", "&amp;#38;ECCO");
fileContent = "&lt;?xml version=\"1.0\"?&gt;\n" +
        "&lt;!DOCTYPE some_name [ \n" +
        "&lt;!ENTITY nbsp \"&amp;#160;\"&gt; \n" +
        "&lt;!ENTITY acute \"&amp;#180;\"&gt; \n" +
        "]&gt;" + fileContent;


SAXParserFactory parserFactor = SAXParserFactory.newInstance();
SAXParser parser = parserFactor.newSAXParser();
SAXHandler handler = new SAXHandler();

ByteArrayInputStream bis = new ByteArrayInputStream(fileContent.getBytes());

parser.parse(bis, handler);
</code></pre>

<p>We now have a row list, where each row has a cell list. We are going to use this to get our values:</p>

<pre><code>//Parsing the substances list obtained from XML
int count = 0;
for (XmlRow subsRow : handler.xmlRowList) {
    if (subsRow.cellList.size() &gt; 19) {
        String substance = subsRow.cellList.get(0);
        if (substance.equals("Substance")) {
            continue;
        }

        count++;
        String adi = subsRow.cellList.get(15); // column P
        String arfd = subsRow.cellList.get(18); // column S

        System.out.println("Substance name='" + substance + "', ADI='" + adi + "', ARfD='" + arfd + "'");
    }
}
</code></pre>

<p>In this example we only care for the substance rows, so we ignore any row that has less than 19 cells. On our project class we use these values to update a DB table, but for simplicity here we are only printing them.</p>

<p>If our goal was to create a regular Excel file, we could change the code to:</p>

<pre><code>Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();

//Converts all rows to POI rows 
int rowCount = 0;
for (XmlRow subsRow : handler.xmlRowList) {
    Row row = sheet.createRow(rowCount);
    int cellCount = 0;
    for (String cellValue : subsRow.cellList) {
        Cell cell = row.createCell(cellCount);
        cell.setCellValue(cellValue);
        cellCount++;
    }
    rowCount++;
}

String fileOutPath = "/tmp/fileOut.xls";
FileOutputStream fout = new FileOutputStream(fileOutPath);
workbook.write(fout);
workbook.close();
fout.close();
</code></pre>

<p>As you can see, it can be easily modified depending on the purpose!</p>

<p>Finally, we delete the downloaded file:</p>

<pre><code>if (file.exists()) {
    System.out.println("delete file-&gt; " + file.getAbsolutePath());
    if (!file.delete()) {
        System.out.println("file '" + file.getAbsolutePath() + "' was not deleted!");
    }
}
//System.out.println(result);
System.out.println("getAndParseFile finished, processed " + count + " substances!");
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>

<h2 id="conclusion">Conclusion</h2>

<p>For the purpose of reading data from an Excel spreadsheet XML file, it's relatively simple to do it.</p>

<p>The sample project used in this post at <a href="https://github.com/jbaysolutions/excel-xml-reader">GitHub</a> has two main classes. <a href="https://github.com/jbaysolutions/excel-xml-reader/blob/master/src/main/java/com/jbaysolutions/excelparser/ExcelXmlReader.java">ExcelXmlReader</a> to download, parse the file and print the values to the console and the <a href="https://github.com/jbaysolutions/excel-xml-reader/blob/master/src/main/java/com/jbaysolutions/excelparser/ExcelXmlConverter.java">ExcelXmlConverter</a> class, to download, parse the file and converts it to OOXML file format.</p>

<p>The code can be modified to read multiple sheets or even the styles if necessary. It just wasn't needed for our use case. </p>

<p>Hope it helped anyone having the same issues as us!</p>

<h2 id="references">References</h2>

<p><a href="http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example">Excel spreadsheet XML</a></p>

<p><a href="http://en.wikipedia.org/wiki/Simple_API_for_XML">SAX</a></p>

<p><a href="http://poi.apache.org/" title="Apache POI">Apache POI</a></p>]]></content:encoded></item><item><title><![CDATA[Apache POI, translating Excel column number to letter]]></title><description><![CDATA[<p>Recently I had to write some code to generate excel files using Apache POI. One of the files was fairly complex and used formulas in a few cells.</p>

<p>I found myself spending a few hours searching for a way to translate the indexed column numbers that POI uses to the</p>]]></description><link>http://blog.jbaysolutions.com/2012/06/08/apache-poi-translating-excel-column-number-to-letter-5/</link><guid isPermaLink="false">8ff78aea-0a24-46cd-b68b-91e61266a0fe</guid><category><![CDATA[java]]></category><category><![CDATA[apache poi]]></category><category><![CDATA[excel]]></category><category><![CDATA[poi]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Fri, 08 Jun 2012 16:08:19 GMT</pubDate><content:encoded><![CDATA[<p>Recently I had to write some code to generate excel files using Apache POI. One of the files was fairly complex and used formulas in a few cells.</p>

<p>I found myself spending a few hours searching for a way to translate the indexed column numbers that POI uses to the column letters I needed in those formulas.</p>

<p>It turns out the solution is quite simple, you just have to use org.apache.poi.hssf.util.CellReference:</p>

<pre><code>String columnLetter = CellReference.convertNumToColString(columnNumber);
</code></pre>

<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>  
<!-- Horizontal For Posts - Text Only -->  
<ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1311169549359552" data-ad-slot="3316155422"></ins>
<script>  
(adsbygoogle = window.adsbygoogle || []).push({});
</script>  

<p><br></p>]]></content:encoded></item></channel></rss>