Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding problem in JExcel

I am loading an excel file in an GAE/Java application with JExcel like this:

The html form to upload the file islike this:

<form id="" action="/save" method="post" enctype="multipart/form-data" accept-charset="ISO-8859-1">
    <input name="file" type="file" value="load"/>
    <input type="submit"value="load excel"/>
</form>

and in the server I have:

ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
    FileItemStream item = iterator.next();
    InputStream stream = item.openStream();
    if (!item.isFormField()) {
        //if it's not a form field it's a file

        Workbook workbook = Workbook.getWorkbook(stream);
        ...
        String name = sheet.getCell(COL_NUMBER, row).getContents();
    }
}

The problem is that if I write in the cell something like 'city ó' when it reads in the server the variable name is ' city ?'. The encoding is not OK.

I've tried to change accept-charset="ISO-8859-1" (setting it to utf-8 or removing it) but with no success.

Can anyone tell me how could I solve this problem.

Thanks

like image 302
Javi Avatar asked Apr 18 '11 10:04

Javi


2 Answers

OK, I got it by doing this:

WorkbookSettings ws = new WorkbookSettings();
ws.setEncoding("Cp1252");
Workbook workbook = Workbook.getWorkbook(stream, ws);
like image 142
Javi Avatar answered Oct 21 '22 02:10

Javi


WorkbookSettings will look for system property jxl.encoding

If you don't have easy access to WorkbookSettings (i.e. coming from Drools- ExcelParser) you might find this preferable.

like image 23
Nick Robson Avatar answered Oct 21 '22 00:10

Nick Robson