ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   OWC Formating Columns (https://www.excelbanter.com/excel-programming/284141-owc-formating-columns.html)

KLomax

OWC Formating Columns
 
The method below write a simple excel sheet to disk from
aspx code. It uses the "Office Web Components" object.
The problem is that I am writing "0012" to Cell(A2). If
you open the sheet written out, the formating has been
applied, but the leading zeros are truncated. For some
reason the values are being entered into the sheet before
the formatting is being applied.

Any ideas?

Public Sub Test()
Try
Dim sFile As String = moWebServer.MapPath(".")
& "\Files\MyExcel.xls"
Dim XLS As New OWC10.SpreadsheetClass()
Dim Sheet As OWC10.Worksheet = XLS.ActiveSheet

Sheet.Range(Sheet.Cells(1, 1), Sheet.Cells(1,
1)).EntireColumn.NumberFormat = "#,##0.00"
Sheet.Range(Sheet.Cells(1, 2), Sheet.Cells(1,
2)).EntireColumn.NumberFormat = "@"

Sheet.Cells(1, 1) = "99.95"
Sheet.Cells(1, 2) = "0012"

XLS.Export(sFile, ssExportActionNone, ssExportHTML)

Catch exp As Exception
Dim sErr As String = exp.Message
sErr = exp.ToString
End Try
End Sub



All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com