OWC Formating Columns

K

KLomax

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top