views:

28

answers:

1

I'm using the JExcel API to create an XLS file. I can't figure out how to populate a new cell without any specific cell formatting. I would like the formatting to be automatically applied, as it does in Excel when you type a value in a cell and it auto-detects what it thinks you're trying to enter.

I wrote something similar to this:

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

WritableWorkbook w = Workbook.createWorkbook(new File(xlsPath));
WritableSheet sheet = w.createSheet("Sheet1", 0);
sheet.addCell(new Label(colNum, rowNum, "99"));

Because I used a 'Label', the value entered in the cell is '99 -- notice the apostrophe in the value, forcing it to be evaluated as a text value. Other potential classes to use are Blank, Boolean, DateTime, Formula, Label, and Number. The problem is that I don't know what type the cell value will be when I'm setting it.

How can I enter my values in the field without knowing the data type, and without the JExcel API prefixing my values with apostrophes?

A: 

Those apostrophes only show up when I open the new workbook using OpenOffice. If I open it using Excel, then the apostrophes don't automatically get added. So in this case, using the Label class seems to be working OK. I'll call this an OpenOffice oddity.

Mike M. Lin