-
Excel formatting in VB
Need some help guys, how do I programmaticly format column 2 and 4 in an excel worksheet to be a number without a decimal place?
I am using the following objects..
Dim xlApp As New Excel.ApplicationClass()
Dim xlSheet As Excel.Worksheet
Dim xlBook As Excel.Workbook
Many thanks!
- Darren
-
An example that might help you:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim xlApp As New Excel.Application()
Dim xlWb As Excel.Workbook = xlApp.Workbooks.Add
Dim xlSt As Excel.Worksheet = xlWb.ActiveSheet
xlSt.Range("B:B,D:D").NumberFormat = "0"
xlApp.Visible = True
End Sub
Couldn't help the smiley in the code there, I think you understand waht should be there instead :)
/Leyan
-
Ok, I just tried that and got this error..
Server Error in '/freight' Application.
--------------------------------------------------------------------------------
Exception from HRESULT: 0x800A03EC.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC.
On this line.. xlSheet.Range("B:B,D").NumberFormat = "0"
Any thoughts?
-
Never mind, silly smiley faces ;/
-
That didnt seem to work (
-
Well it has to be about the smiley in the code I posted. It should be:
("B : B , D : D")
without the spaces. If I remove the last space this page translates the D and the colon to a smiley. :D
/Leyan
-