You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2010/08/03 18:29:57 UTC
DO NOT REPLY [Bug 49694] New: autoSizeColumn does not respect dates
in HSSF
https://issues.apache.org/bugzilla/show_bug.cgi?id=49694
Summary: autoSizeColumn does not respect dates in HSSF
Product: POI
Version: 3.6
Platform: PC
Status: NEW
Severity: minor
Priority: P2
Component: HSSF
AssignedTo: dev@poi.apache.org
ReportedBy: cmm@stl-software.de
The method sheet.autoSizeColumn for HSSF does not respect formats for dates. It
rather tries to format the date as a numeric, fails and falls back to a very
simple to-string-transformation:
try {
NumberFormat fmt;
if ("General".equals(format))
sval = "" + value;
else
{
// --> fails, because the format is no Decimal Format
fmt = new DecimalFormat(format);
sval = fmt.format(value);
}
} catch (Exception e) {
sval = "" + value;
}
Hence, the width for date cells is not calculated corretly.
Sample Code ist here:
//-----------------------------------
Workbook workBook = new HSSFWorkbook();
Sheet sheet = workBook.createSheet("First Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue(new GregorianCalendar(2010, 7, 3));
DataFormat dataFormat = workBook.getCreationHelper().createDataFormat();
CellStyle cellStyle = workBook.createCellStyle();
cellStyle.setDataFormat(dataFormat.getFormat("dd.mm.yyyy"));
cell.setCellStyle(cellStyle);
row = sheet.createRow(1);
cell = row.createCell(0);
cell.setCellValue("small");
sheet.autoSizeColumn(0);
workBook.write(outputStream);
//-----------------------------------
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
DO NOT REPLY [Bug 49694] autoSizeColumn does not respect dates in
HSSF
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49694
Nick Burch <ni...@alfresco.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
OS/Version| |All
--- Comment #1 from Nick Burch <ni...@alfresco.com> 2010-08-03 13:13:07 EDT ---
HSSFDataFormatter now looks to be up to the job of correctly formatting the
cells for an excel-like display
I've updated HSSFSheet to use this, in r981969.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org