This project is read-only.

How do I set the DataFormat for an entire column?

Nov 12, 2012 at 6:41 PM
Edited Nov 12, 2012 at 6:42 PM

I'm having trouble setting the DataFormat on a column in a report.  I was hoping to use SetDefaultColumnStyle, but it doesn't appear to be working:

ICellStyle datetimeFormatStyle = workbook.CreateCellStyle();
datetimeFormatStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("m/d/yy h:mm");
sheet.SetDefaultColumnStyle(0, datetimeFormatStyle);

Unfortunately the dates are still appearing in the standard m/d/yy format.  The date date does have time stamps on it.  What am I doing wrong?  Or is it not possible to do this for an entire column?

Nov 22, 2012 at 10:08 PM

I'm not sure what's going on with SetDefaultColumnStyle. But I suggest you create a shared cell style with the dataformat and assign it to each existing cell in the column. I'm thinking maybe SetDefaultColumnStyle is only for creating new cell while you are in Excel UI.