Cell style format not working with cells that have data

I'm using the following code. Only fields not filled in with data from the first line have the style from the second line.

'Adds data to the worksheet
Report.Cells.ImportDataTable(dt, False, "A5")

'Sets style for column 4
Report.Cells.Columns(4).Style.Number = 14

I cannot set the style with the xls template for other reasons so I just wanted to make column 4 display with the date cell format. Rows 0-4 , column 4 are empty but end up with the correct style (number 14). However, the cells (rows 5-x) in the column filled in by the ImportDataTable do not have the style. Any ideas why this is happening?

Thanks,

Sean

Please change your code to:

'Sets style for column 4

dim styleObj as Style = Report.Cells.Columns(4).Style

styleObj.Number = 14

Report.Cells.Columns(4).Style = styleObj

'Adds data to the worksheet
Report.Cells.ImportDataTable(dt, False, "A5")

I have a similar problem. If I set the style of a column, any data written to that column gets reformatted to General. The column itself does still have the formatting, (as tested by entering data into the next empty row), but the data written by Cell.setValue seems to override the column's current style.

Are you using Aspose.Cells for Java?

Hi,

If you want to apply the column' style to each cell in this column, you should set the column's style first. And we will afford Column.ApplyStyle() method to apply style to each cell in this column.

Hi,

Please try this fix for Java.You can set data first and use Column.applyStyle() method to set the column style and the style of the cells in the column.

Is there a way to set the Column Style first and then have cell.setValue not overwrite it? There are times when it would be easier to apply the styles first, such as when using dynamic columns.

Also, does applyStyle also set the set the style, or should I also call column.setStyle()?

Hi,

If you want set column style first and apply the style to all cells in this column, you should not set row style before setting the value of the cell.

ApplyStyle also sets the style of the column.

I'm not using java. I'm using ASP.NET. I tried the code you used in your first response, but I get

Property 'style' is 'Readonly'

Here is the exact code I'm trying:

Dim styleObj As Style = Report.Cells.Columns(4).Style

styleObj.Number = 14

Report.Cells.Columns(4).Style = styleObj

What I find realy odd is that the following code changes the style for the single cell (10,4), but not for the column (4).

Report.Cells.ImportDataTable(dt, False, DataCell)

Report.Cells(10, 4).Style.Number = 14

Report.Cells.Columns(4).Style.Number = 14

This code doesn't apply the style at all.

Report.Cells.ImportDataTable(dt, False, DataCell)

Report.Cells(10, 4).Style.Number = 14

Report.Cells.Columns(4).Style.Number = 14

Thanks for any help.

In latest version of Aspose.Cells for .NET, you can use following code:

Report.Cells.ImportDataTable(dt, False, DataCell)

Dim style as Style = Report.Cells.Columns(4).Style

style.Number = 4

Dim styleFlag as StyleFlag = new StyleFlag()

styleFlag.NumberFormat = True

Report.Cells.Columns(4).ApplyStyle(style, styleFlag)