I am creating a spreadsheet via code in VB.Net (no designer).
I have the following code to set the column cell formats:
cells.Columns(2).Style.Custom = "#,##0;[Red](#,##0)"
cells.Columns(3).Style.Custom = "#,##0;[Red](#,##0)"
cells.Columns(4).Style.Custom = "#,##0;[Red](#,##0)"
Then I read some data and populate the spreadsheet:
Do While dr2.Read()
cells(x, 0).PutValue(Trim(dr2.Item("Customer")))
cells(x, 1).PutValue(Trim(dr2.Item("CustNo")))
If Not IsDBNull(dr2.Item("MSales")) Then
cells(x, 2).PutValue(CDec(Trim(dr2.Item("MSales"))))
End If
etc...
Loop
Then, based on the number of rows used I add some borders and a totals column:
range = sheets(0).Cells.CreateRange(3, 2, x - 1, 1)
range.SetOutlineBorder(BorderType.LeftBorder, CellBorderType.Medium, Color.Black)
cells(x + 1, 0).PutValue("TOTALS")
cells(x + 1, 2).Formula = "=SUM(C4:C" & x & ")"
Here is the problem, when I add the all the code after the loop, all of the cell.style.custom code doesn't work any longer.
Any ideas on how to perform this correctly?
Keep in mind, I am using the demo software.
Thanks
David