<?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[undefined - 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:04 GMT</lastBuildDate><atom:link href="http://blog.jbaysolutions.com/author/gustavo-santos/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title><![CDATA[Vue.js quick start guide]]></title><description><![CDATA[<h1 id="vuejsv10xquickstartguide">Vue.js (v1.0.x) quick start guide</h1>

<p><em><strong>NOTE</strong>: We plan to update this guide to Vue 2.0 when the final release is out</em></p>

<p>Like most software companies which create web applications, we develop frontends with HTML and Javascript. <br>
Having mostly used jQuery on our applications, we felt there</p>]]></description><link>http://blog.jbaysolutions.com/2016/09/16/vue-js-quick-start-guide/</link><guid isPermaLink="false">9141f0f7-10e0-43a8-8c0b-e45fd1fa69c0</guid><category><![CDATA[javascript]]></category><category><![CDATA[vue]]></category><category><![CDATA[vue.js]]></category><category><![CDATA[frontend]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Fri, 16 Sep 2016 13:29:18 GMT</pubDate><media:content url="https://vuejs.org/images/logo.png" medium="image"/><content:encoded><![CDATA[<h1 id="vuejsv10xquickstartguide">Vue.js (v1.0.x) quick start guide</h1>

<img src="https://vuejs.org/images/logo.png" alt="Vue.js quick start guide"><p><em><strong>NOTE</strong>: We plan to update this guide to Vue 2.0 when the final release is out</em></p>

<p>Like most software companies which create web applications, we develop frontends with HTML and Javascript. <br>
Having mostly used jQuery on our applications, we felt there had to be an easier and less verbose way develop web frontends.   </p>

<p>The problem is...there literally hundreds of javascript libraries/frameworks out there, with new showing up every day!</p>

<p>After lots of searching and reading, we settled on <a href="http://vuejs.org/">Vue.js</a>. Although its relatively recent Vue.js seemed like a great choice. </p>

<p>Since the core library is only a view layer and doesn't force you to build a complete SPA (single page application), it means we could just start using it some components on our existing web applications.  </p>

<h2 id="documentation">Documentation</h2>

<p>Vue provides a very good <a href="https://vuejs.org/guide/index.html">official documentation</a>, which we recommend you start with.</p>

<h2 id="oursetup">Our Setup</h2>

<p>On our apps, the most basic setup always includes Vue, <a href="https://github.com/vuejs/vue-resource/">vue-resource</a> for http requests, and <a href="https://github.com/vuejs/vue-validator">vue-validator</a> for form validation </p>

<p>Since we are not using webpack or any other module bundler, we just import the js files using a script tag.</p>

<pre><code class="language-markup">    &lt;script src="javascripts/vue/vue.js"&gt;&lt;/script&gt;
    &lt;script src="javascripts/vue/vue-resource.js"&gt;&lt;/script&gt;
    &lt;script src="javascripts/vue/vue-validator.js"&gt;&lt;/script&gt;
</code></pre>

<h3 id="debuganddevtools">Debug and Devtools</h3>

<p>When on the developing environment, we enable these <a href="http://vuejs.org/api/#Global-Config">Vue global configs</a>:</p>

<pre><code class="language-javascript">     Vue.config.debug = true;
     Vue.config.devtools = true;
</code></pre>

<p>This will enable stack traces and allow using the <a href="https://github.com/vuejs/vue-devtools">vue-devtools</a> browser extension.  </p>

<h3 id="pageexample">Page example</h3>

<p>On each page, we create a div template, like explained in the Vue guide:</p>

<pre><code class="language-markup">    &lt;div id="app"&gt;
        {{ message }}
    &lt;/div&gt;
</code></pre>

<p>And on the js script loaded for that page:</p>

<pre><code class="language-javascript">    new Vue({
      el: '#app',
      data: {
        message: 'Hello Vue.js!'
      }
    })
</code></pre>

<p>It's highly recommended to give a different id to each template, it's pretty common for builds to concat and uglify multiple js files into one. <br>
If you have multiple templates with the same id, there will be conflicts when binding Vue instances to the templates.</p>

<h3 id="vcloak">v-cloak</h3>

<p>We highly recommend including the <a href="http://vuejs.org/api/#v-cloak">v-cloak</a> directive in every template. This way, uncompiled bindinds will not be diplayed while the page loads:</p>

<p>Just include this rule on your css:</p>

<pre><code class="language-css">    [v-cloak] {
      display: none;
    }
</code></pre>

<p>Using the same page as before:</p>

<pre><code class="language-markup">    &lt;div id="app" v-cloak&gt;
        {{ message }}
    &lt;/div&gt;
</code></pre>

<p>You can check the working sample <a href="https://jbaysolutions.github.io/vue-quick-start-samples/vue-sample-page.html">here</a> </p>

<h2 id="vueresource">vue-resource</h2>

<p><a href="https://github.com/vuejs/vue-resource">vue-resource</a> is a plugin for Vue that provides for making web requests and handle responses using a XMLHttpRequest or JSONP. </p>

<p>We use it extensively when using Vue, mostly for HTTP GET and POST requests. There are other methods and options available, for more details check the official vue-resource docs.</p>

<h3 id="get">GET</h3>

<p>This is a basic example of a GET request where we use the Github API to retrieve a list of JBay Solutions organization projects.</p>

<p>You can check the working sample <a href="https://jbaysolutions.github.io/vue-quick-start-samples/vue-resource-example.html#get">here</a> </p>

<pre><code class="language-javascript">     var url = "https://api.github.com/orgs/jbaysolutions/repos";

     // GET request
     this.$http.get(url).then(function (response) {
         this.loading = false;
         // success callback, response.data will contain the data in JSON format

         // get status
         response.status;
         // get status text
         response.statusText;

     }, function (response) {
         // error callback
     });
</code></pre>

<h3 id="post">POST</h3>

<p>This is a basic example of a POST request where we use the jsonplaceholder.typicode.com fake server to send some data.</p>

<p>You can check the working sample <a href="https://jbaysolutions.github.io/vue-quick-start-samples/vue-resource-example.html#post">here</a> </p>

<pre><code class="language-javascript">    var url = "http://jsonplaceholder.typicode.com/posts";

    var data = {
        title: "a title",
        body: "a body",
        userId: 1
    };

    // POST request
    this.$http.post(url, data).then(function (response) {
        // success callback

        // get status
        response.status;
        // get status text
        response.statusText;

    }, function (response) {
        // error callback
    });
</code></pre>

<p>You can also use POST to send forms or upload files using FormData. Details <a href="https://github.com/vuejs/vue-resource/blob/master/docs/recipes.md#forms">here</a></p>

<h2 id="vuevalidator">vue-validator</h2>

<p><a href="https://github.com/vuejs/vue-validator">vue-validator</a> is form validation component for Vue.js.
It comes with a few built in validators:</p>

<ul>
<li>required: whether the value has been specified</li>
<li>pattern: whether the pattern of the regular expression</li>
<li>minlength: whether the length of specified value is less than or equal minimum length</li>
<li>maxlength: whether the length of specified value is less more or equal maximum length</li>
<li>min: whether the specified numerical value is less than or equal minimum</li>
<li>max: whether the specified numerical value is more than or equal maximum</li>
</ul>

<p>Adicional validators can be declared globally or locally on each Vue instance. A global email validator is one we use on most apps:</p>

<pre><code class="language-javascript">    Vue.validator('email', function (val) {
        return /^(([^&lt;&gt;()[\]\\.,;:\s@\"]+(\.[^&lt;&gt;()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(val);
    });
</code></pre>

<p>Local validators can be declared inside the validators object on a Vue instance.</p>

<p>The sample below uses both cases, a global email validator and a locally declared validator to check if both passwords match. For more details about custom validatores check the docs <a href="http://vuejs.github.io/vue-validator/en/custom.html">here</a></p>

<p>You can check the working sample <a href="https://jbaysolutions.github.io/vue-quick-start-samples/vue-validator-example.html">here</a> </p>

<p>Since we mostly use Bootstrap for our apps layout, the sample below has is built with conditions to display errors using help blocks.</p>

<pre><code class="language-markup">    &lt;validator name="sampleValidator"&gt;
        &lt;form v-on:submit.prevent="saveUser" novalidate&gt;
            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.firstName.invalid &amp;&amp; $sampleValidator.firstName.touched}"&gt;
                &lt;label for="firstName" class="control-label"&gt;First Name *&lt;/label&gt;
                &lt;input class="form-control" type="text" name="firstName" placeholder="" v-model="user.firstName" v-validate:first-name="{ required: true, maxlength: 50 }"/&gt;
                &lt;span class="help-block" v-show="$sampleValidator.firstName.touched &amp;&amp; $sampleValidator.firstName.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.firstName.touched &amp;&amp; $sampleValidator.firstName.maxlength"&gt;The max size is 50.&lt;/span&gt;
            &lt;/div&gt;

            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.lastName.invalid &amp;&amp; $sampleValidator.lastName.touched}"&gt;
                &lt;label for="lastName" class="control-label"&gt;Last Name *&lt;/label&gt;
                &lt;input class="form-control" type="text" name="lastName" placeholder="" v-model="user.lastName" v-validate:last-name="{ required: true, maxlength: 100 }"/&gt;
                &lt;span class="help-block" v-show="$sampleValidator.lastName.touched &amp;&amp; $sampleValidator.lastName.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.lastName.touched &amp;&amp; $sampleValidator.lastName.maxlength"&gt;The max size is 100.&lt;/span&gt;
            &lt;/div&gt;

            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.country.invalid &amp;&amp; $sampleValidator.country.touched}"&gt;
                &lt;label for="country" class="control-label"&gt;Country Code&lt;/label&gt;
                &lt;input class="form-control" type="text" name="country" placeholder="" v-model="user.country" v-validate:country="{ maxlength: 3 }"/&gt;
                &lt;span class="help-block" v-show="$sampleValidator.country.touched &amp;&amp; $sampleValidator.country.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.country.touched &amp;&amp; $sampleValidator.country.maxlength"&gt;The max size is 3.&lt;/span&gt;
            &lt;/div&gt;

            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.mail.invalid &amp;&amp; $sampleValidator.mail.touched}"&gt;
                &lt;label for="email" class="control-label"&gt;Email *&lt;/label&gt;
                &lt;input class="form-control" type="email" name="email" v-model="user.email" v-validate:mail="{ required: true, email: true }"/&gt;
                &lt;span class="help-block" v-show="$sampleValidator.mail.touched &amp;&amp; $sampleValidator.mail.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.mail.touched &amp;&amp; $sampleValidator.mail.email &amp;&amp; !$sampleValidator.mail.required"&gt;The email address is not valid.&lt;/span&gt;
            &lt;/div&gt;

            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.password.invalid &amp;&amp; $sampleValidator.password.touched}"&gt;
                &lt;label for="password" class="control-label" &gt;Password *:&lt;/label&gt;
                &lt;input type="password" class="form-control" name="password" v-model="user.password" v-validate:password="{ required: true, minlength: 6, maxlength: 10 }"&gt;
                &lt;span class="help-block" v-show="$sampleValidator.password.touched &amp;&amp; $sampleValidator.password.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.password.touched &amp;&amp; $sampleValidator.password.minlength &amp;&amp; !$sampleValidator.password.required"&gt;Please enter at least 6 characters.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.password.touched &amp;&amp; $sampleValidator.password.maxlength"&gt;The max size is 255.&lt;/span&gt;
            &lt;/div&gt;

            &lt;div class="form-group" v-bind:class="{ 'has-error': $sampleValidator.confirmPassword.invalid &amp;&amp; $sampleValidator.confirmPassword.touched}"&gt;
                &lt;label for="confirmPassword" class="control-label" &gt;Confirm password *:&lt;/label&gt;
                &lt;input type="password" class="form-control" name="confirmPassword" v-model="confirmPassword" v-validate:confirm-password="{ required: true, passwordValidator: { rule: user.password }}"&gt;
                &lt;span class="help-block" v-show="$sampleValidator.confirmPassword.touched &amp;&amp; $sampleValidator.confirmPassword.required"&gt;This field is required.&lt;/span&gt;
                &lt;span class="help-block" v-show="$sampleValidator.confirmPassword.touched &amp;&amp; $sampleValidator.confirmPassword.passwordValidator &amp;&amp; !$sampleValidator.confirmPassword.required"&gt;The passwords don't match.&lt;/span&gt;
            &lt;/div&gt;

            &lt;button class="btn btn-primary" type="submit"&gt;Add&lt;/button&gt;
        &lt;/form&gt;
    &lt;/validator&gt;
</code></pre>

<p>When the form is submited, we only save the user if the form is valid:</p>

<pre><code class="language-javascript">    saveUser: function () {
        this.$validate(true);
        if (this.$sampleValidator.valid) {
            // save the user
        }
    },
</code></pre>

<!--## File upload?-->

<h2 id="ourcustomcomponents">Our custom components</h2>

<p>Below are the components we most commonly use on our apps: </p>

<h3 id="datepicker">Datepicker</h3>

<p>This datepicker component is a wrapper for <a href="https://eternicode.github.io/bootstrap-datepicker/">bootstrap-datepicker</a>. <br>
The lib js and css files need to be included in your html.</p>

<pre><code class="language-markup">    &lt;script src="js/bootstrap-datepicker.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" media="screen" href="css/bootstrap-datepicker3.css")"&gt;
</code></pre>

<p>Below is the full component source: </p>

<pre><code class="language-javascript">    var datepickerComponent = Vue.extend({
        template: '&lt;div class="input-group date" v-el:inputgroup&gt;' +
        '   &lt;input type="text" class="form-control" v-model="value"&gt;' +
        '   &lt;span class="input-group-addon"&gt;&lt;i class="glyphicon glyphicon-calendar"&gt;&lt;/i&gt;&lt;/span&gt;' +
        '&lt;/div&gt;',
        props: {
            value: ''
        },
        data: function () {
            return {};
        },
        watch: {
            value: function () {
                this.datepicker.datepicker("update", this.value);
            },
        },
        ready: function () {
            this.datepicker = $(this.$els.inputgroup).datepicker({
                format: 'yyyy-mm-dd',
                autoclose: true
            });
        }
    });

    Vue.component('datepicker', datepickerComponent);
</code></pre>

<p>And to use it:</p>

<pre><code class="language-markup">    &lt;datepicker :value.sync="myDate"/&gt;
</code></pre>

<h3 id="bootstrapselect">bootstrap-select</h3>

<p>This select component is a wrapper for <a href="https://silviomoreto.github.io/bootstrap-select/">bootstrap-select</a></p>

<p>The lib js and css files need to be included in your html.</p>

<pre><code class="language-markup">    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/js/bootstrap-select.min.js"&gt;&lt;/script&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.11.2/css/bootstrap-select.min.css"&gt;
</code></pre>

<p>Below is the full component source:</p>

<pre><code class="language-javascript">    var bSelectComponent = Vue.extend({
        //v-el:select
        template: '&lt;select v-el:select&gt;' +
        '   &lt;option v-for="item in items" value="{{item.value}}"&gt;{{item.text}}&lt;/option&gt;' +
        '&lt;/select&gt;',
        props: {
            value: "",
            items: [],
        },
        data: function () {
            return {};
        },
        watch: {
            items: function () {
                var select = $(this.$els.select);
                select.selectpicker("refresh");
                select.selectpicker("val", this.value);
            },
            value: function () {
                var select = $(this.$els.select);
                if (this.value !== select.selectpicker("val")) {
                    select.selectpicker("val", this.value);
                }
            }
        },
        ready: function () {
            var select = $(this.$els.select);
            select.selectpicker();
            select.selectpicker("val", this.value);
            var self = this;
            select.on("changed.bs.select", function () {
                self.value = select.selectpicker("val");
            });
        }
    });
    Vue.component('b-select', bSelectComponent);
</code></pre>

<p>And to use it:</p>

<pre><code class="language-markup">    &lt;b-select :value.sync="myValue" :items="itemList"/&gt;
</code></pre>

<p>Where itemList is an array of objects:</p>

<pre><code class="language-javascript">[
    {
        "text": "Item 1",
        "value": "1"
    },
    {
        "text": "Item 2",
        "value": "2"
    },
    {
        "text": "Item 3",
        "value": "3"
    },

]
</code></pre>

<p>To enable any of the js component options, like live search, you can use it like this:      </p>

<pre><code class="language-markup">    &lt;b-select :value.sync="myValue" :items="itemList" data-live-search="true"/&gt;
</code></pre>

<h3 id="vuegridlayout">vue-grid-layout</h3>

<p>A draggable and resizable grid layout, for Vue.js.</p>

<p>We developed this component to be used primarily in our SaaS app <a href="https://www.draxed.com/?utm_source=blog&amp;utm_medium=web&amp;utm_campaign=vue-grid-layout">Draxed</a>.</p>

<p>Read all about it <a href="https://github.com/jbaysolutions/vue-grid-layout">HERE</a>.</p>

<h3 id="vuebootstraptable">vue-bootstrap-table</h3>

<p>A sortable and searchable table, as a Vue component, using bootstrap styling.</p>

<p>We developed this component to be used primarily in our SaaS app <a href="https://www.draxed.com/?utm_source=blog&amp;utm_medium=web&amp;utm_campaign=vue-bootstrap-table">Draxed</a>.</p>

<p>Read all about it <a href="https://github.com/jbaysolutions/vue-bootstrap-table">HERE</a>.</p>]]></content:encoded></item><item><title><![CDATA[SQL queries to get table and columns names for MySQL, PosgreSQL and SQL Server]]></title><description><![CDATA[<p>Something that now and then are always needed, the SQL queries to get the list of table names from a database, or the column names for a table. <br>
Below are the queries for MySQL, PostgreSQL and Microsoft SQL server. </p>

<h3 id="mysql">MySQL</h3>

<p>To get the table list:</p>

<pre><code>show tables;
</code></pre>

<p>To get the</p>]]></description><link>http://blog.jbaysolutions.com/2015/12/01/sql-table-and-columns-from-mysql-postgresql-sqlserver/</link><guid isPermaLink="false">8f422c92-5eba-4227-8ebe-a3591f977eaf</guid><category><![CDATA[sql]]></category><category><![CDATA[mysql]]></category><category><![CDATA[postgresql]]></category><category><![CDATA[sql server]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Tue, 01 Dec 2015 20:09:10 GMT</pubDate><content:encoded><![CDATA[<p>Something that now and then are always needed, the SQL queries to get the list of table names from a database, or the column names for a table. <br>
Below are the queries for MySQL, PostgreSQL and Microsoft SQL server. </p>

<h3 id="mysql">MySQL</h3>

<p>To get the table list:</p>

<pre><code>show tables;
</code></pre>

<p>To get the column list for a table:</p>

<pre><code>show columns from &lt;tableName&gt;;
</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><hr></p>

<h3 id="postgresql">PostgreSQL</h3>

<p>To get the table list:</p>

<pre><code>SELECT table_name FROM information_schema.tables WHERE table_catalog ='&lt;dbName&gt;' and table_schema = 'public';
</code></pre>

<p>To get the column list for a table:</p>

<pre><code>SELECT column_name FROM information_schema.columns where table_catalog = '&lt;dbName&gt;' and table_name = '&lt;tableName&gt;';
</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><hr></p>

<h3 id="sqlserver">SQL Server</h3>

<p>To get the table list:</p>

<pre><code>SELECT TABLE_NAME FROM &lt;dbName&gt;.INFORMATION_SCHEMA.Tables;
</code></pre>

<p>To get the column list for a table:</p>

<pre><code>SELECT COLUMN_NAME FROM &lt;dbName&gt;.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '&lt;tableName&gt;';
</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>

<hr>]]></content:encoded></item><item><title><![CDATA[Adding Image to PDF file using Java and IText]]></title><description><![CDATA[<p>To add an image to an already existing PDF file is a relatively simple task, using <a href="http://itextpdf.com/" title="iText">iText</a>.</p>

<p>On this example, we will add a smile image to the bottom of the PDF first page.</p>

<p>We start by loading the PDF we want to modify, and getting the reference for the</p>]]></description><link>http://blog.jbaysolutions.com/2015/10/27/adding-image-to-pdf-java-itext/</link><guid isPermaLink="false">b440d4a5-a073-4323-9f91-3dee253fe90e</guid><category><![CDATA[java]]></category><category><![CDATA[itext]]></category><category><![CDATA[pdf]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Tue, 27 Oct 2015 15:49:00 GMT</pubDate><content:encoded><![CDATA[<p>To add an image to an already existing PDF file is a relatively simple task, using <a href="http://itextpdf.com/" title="iText">iText</a>.</p>

<p>On this example, we will add a smile image to the bottom of the PDF first page.</p>

<p>We start by loading the PDF we want to modify, and getting the reference for the first page:</p>

<pre><code class="language-java">    PdfReader reader = new PdfReader(srcPdf);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(destPdf));
    PdfContentByte content = stamper.getOverContent(1);
</code></pre>

<p>srcPdf is a String with the full path to the existing PDF file, while destPdf is the full path where the modified PDF file will be created.  </p>

<p>Then, we load the image (imagePath is the full path for the imagem file):</p>

<pre><code>Image image = Image.getInstance(imagePath);

// scale the image to 50px height
image.scaleAbsoluteHeight(50);
image.scaleAbsoluteWidth((image.getWidth() * 50) / image.getHeight());
</code></pre>

<p>Since the image dimensions are large, it's scaled to 50 pixels height before we add it to the PDF.</p>

<p>We then set the page coordinates where we want it. <strong>Be aware that the 0 value for the Y axis is the bottom of the page, not the top:</strong></p>

<pre><code>image.setAbsolutePosition(70, 140);
</code></pre>

<p>All we need to do now is add it to the page reference and close the stamper:</p>

<pre><code>content.addImage(image);

stamper.close();
</code></pre>

<p>That's it! </p>

<p>The sample project with all the code, example PDF and image is available at github, <a href="https://github.com/jbaysolutions/add-image-to-pdf">here</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>]]></content:encoded></item><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><item><title><![CDATA[Enabling remote JMX on Glassfish 2.1.1]]></title><description><![CDATA[<p>The default glassfish app. server installation comes with local JMX connections enabled by default.</p>

<p>To enable JMX connections from remote hosts all that's needed is to add <strong>-Djava.rmi.server.hostname=&lt;hostname&gt;</strong> in the JVM Options of the instance of GlassFish, where <strong>&lt;hostname&gt;</strong> is the external</p>]]></description><link>http://blog.jbaysolutions.com/2011/12/05/enabling-remote-jmx-on-glassfish-2-1-1/</link><guid isPermaLink="false">8435b73a-cd40-4b48-84c9-29a203747c70</guid><category><![CDATA[java]]></category><category><![CDATA[glassfish]]></category><category><![CDATA[jmx]]></category><dc:creator><![CDATA[Gustavo Santos]]></dc:creator><pubDate>Mon, 05 Dec 2011 13:03:09 GMT</pubDate><content:encoded><![CDATA[<p>The default glassfish app. server installation comes with local JMX connections enabled by default.</p>

<p>To enable JMX connections from remote hosts all that's needed is to add <strong>-Djava.rmi.server.hostname=&lt;hostname&gt;</strong> in the JVM Options of the instance of GlassFish, where <strong>&lt;hostname&gt;</strong> is the external hostname of the server where glassfish is running.</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>]]></content:encoded></item></channel></rss>