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...!!

No comments:

Post a Comment