Saturday 15 May 2010

jsf - How to override PrimeFaces p:dataExporter wrongly exporting numbers as text in Excel? -


primetime tag exports numeric data by default, which results in a green The color of the triangle in the upper left corner of the cell if you click excel export under the table of cars, then it can be seen as well.

To ensure that I can not export my numerical columns as text, how can I override this? I tried to use the postprocessor attribute indicating my method, which sets the Excel format for all data cells using the POI API, but it Does not take effect (nothing changed):

  Public Zero Format xx (Object Doc) {HSSFWorkbook book = (HSSFWorkbook) Doctor; HSSFSheet sheet = book.getSheetAt (0); HSSFRow header = sheet.getRow (0); Int colCount = header.getPhysicalNumberOfCells (); Int rowCount = sheet.getPhysicalNumberOfRows (); HSSFCellStyle numStyle = book.createCellStyle (); NumStyle.setDataFormat ((short) 1); {HSSFRow line = sheet.getRow (rowInd) for (infinite row = 1; rowind  

I also tried

  cell.setCellType (HSSFCell.CELL_TYPE_NUMERIC);  

but he gives me

  java.lang.IllegalStateException: can not obtain a numeric value from a text cell  

This means that all data is exported indiscriminately as text and you can not change it later.

"post-text" itemprop = "text">

In your post processor, you have not set the cell value anywhere in the whole you set the type, but not the value. Setting type is not enough You have to convert the value to a number and set it again


No comments:

Post a Comment