Saturday, September 21, 2013

How to set JXL Character Encoding

JXL (Java Excel API) is a open source Java API which allows Java developers to read Excel spreadsheets and to generate Excel spreadsheets dynamically. In addition, it contains a mechanism which allows java applications to read in a spreadsheet, modify some cells and write out the new spreadsheet.

You can learn how to use it by the following link.

At the default settings JXL is unable to read some special characters such like ®, ™, ©, etc.. which are used commonly.
This is the way how to overcome that issue.

Usually you can create the Workbook file as below.

Workbook workbook = Workbook.getWorkbook( new File(<path_to_excel_file>) );



At that case you can not read special characters like above mentioned. So this is the solution.

WorkbookSettings ws = new WorkbookSettings();
ws.setEncoding("CP1250");
Workbook workbook = Workbook.getWorkbook( new File(<path_to_excel_file>), ws );



Here CP1250 is a standard character encoding format. Like that you can specify what is the Character set you are going to use (ex: utf8, cp1250, etc...). So set the character set at the very beginning. Then you can read and write the characters which are defined under that character encoding system.

Cheers...!!

Tuesday, August 20, 2013

Convert XSD file to JAR by one command



What is XSD ....??

It is considered as the grammar of the XML... The XML Schema language is also referred to as XML Schema Definition (XSD). Simply XSD files are used to validate XML.


XSD files can be converted to a JAR file simply using the Apache XMLBeans

If you have already setup Apache XMLBeans then go to the folder which contains the xsd file and apply the below command which will convert xsd file to a jar file. (if not follow the Setup XMLBeans instructions)

>> scomp -out <jar_file_name.jar> <xsd_document_name.xsd>

example:
>> scomp -out getSupplierNames.jar getSupplierNames.xsd

Setup XMLBeans

First you have to setup Apache Ant and JDK 1.4 or later version.

JDK installation...
JDK can be downloaded from Java downloads. Install it and set the Environment Variables if they are not set correctly (Right click My Computer --> Properties --> Advanced --> Environment Variables --> System Variables)
    Variable: JAVA_HOME
    Value   : <folder where the JDK software is located>

If PATH variale exists append the value, else add the value.
    Variable: PATH
    Value   : %JAVA_HOME%\bin

Apache Ant installation...
Apache Ant can be downloaded from Ant Binary Distributions. Download the zip file and extract it.
Set below Environment Variables as described above.
    Variable: ANT_HOME
    Value   : <folder where you uncompressed Ant to>


If PATH variale exists append the value, else add the value.
    Variable: PATH
    Value   : %ANT_HOME%/bin

Apache XMLBeans installation...
 Apache XMLBeans can be downloaded from download mirrors. Download the zip file and extract it.
Set below Environment Variables as described earlier.
    Variable: XMLBEANS_HOME
    Value   : <folder where you uncompressed XMLBeans to>


If PATH variale exists append the value, else add the value.
    Variable: PATH
    Value   : %XMLBEANS_HOME%\bin

If CLASSPATH variale exists append the value, else add the value.
    Variable: CLASSPATH
    Value   : <path to xbean.jar>
              [usually this should be %XMLBEANS_HOME%\xbean.jar]

Now all the setup processes are completed and you can convert XSD files to JAR files using the scomp command as described at the top of the article....

CHEERS.......!!