JExcelApi currency format by cell formula - file error

I am writing a spreadsheet with JExcelApi .

I have two cells that I want to apply currency formatting to. From reading the API, I discovered jxl.write.NumberFormat, which seems to do what I want. In my application, I wrote:

NumberFormat currency = new NumberFormat(NumberFormat.CURRENCY_DOLLAR);
WritableCellFormat currencyFormat = new WritableCellFormat(currency);

cells.add(new Formula(col, row, myFormula, currencyFormat));

      

col and row are the column and row to write. myFormula is the formula to be written. There is one AVERAGE () and one SUM (), each of which is written to a different cell. Cells are an ArrayList that is written to the spreadsheet like this:

for (WritableCell cell : cells) {
    ws.addCell(cell);
}

      

(There is a try / catch block, but it is currently inactive.)

EDIT: ws is a WritableSheet obtained with WritableWorkbook.getSheet (row name). Everything else added to ws is written without issue :)

The file is written successfully, but when I open it, I get the message "File error. Some number formats may be lost." The boxes formatted above were not formatted in the Excel file.

I am using Microsoft Excel 2003 SP3 and JExcelApi 2.6.10.

Can anyone help me please? Thanks in advance:)

+2


source to share


3 answers


you can find help here: http://www.docjar.com/html/api/jxl/demo/Write.java.html - use



WritableCellFormat cfi3 = new WritableCellFormat
                (NumberFormats.ACCOUNTING_FLOAT);

      

+3


source


NumberFormat currencyFormat = new NumberFormat(NumberFormat.CURRENCY_DOLLAR + " ###,###.00", NumberFormat.COMPLEX_FORMAT); 
WritableCellFormat lCurrencyFormat = new WritableCellFormat(currencyFormat);
Number currency = new Number(j, cnt, Double.parseDouble(lStr), lCurrencyFormat);
lSheet.addCell(currency);

      



This will definitely solve your goal!

+1


source


It seems that your currency format is not written. You can try to create a formula cell first and then format it in currency format. Hope this helps you.

0


source







All Articles