Using Excel Application in VB.NET - formatting excel cells
Posted on 2004-11-01
I am using VB.NET to write Latitude values into an Excel File ( A sample cell is "20:5:30"). This value comes from a local string variable in my VB.NET program . But Excel Identify this in the Time format. So , How to format the Excel thru my VB.NET program so that the excel file will identify the latitude value in string format and not in time format.
Problem 2 .
I use the line of code to close my excel work book - ObjExcel.Workbooks.Close() . After this line executes, a dialog box generated by Excel Appears asking "Do you want to save the changes you made ?" with buttons "Yes" , "No" , "Cancel".
If I click Cancel, the application crashes .In the first place , is there a way I can avoid this Excel dialog box coming up?
The simplified code is given below
'WriteFilepath is the path of excel file for Ex. "c:\myfiles\testsheet.xls"
Sub XLSfilewrite(ByVal WriteFilepath As String, ByVal LLorEN As String)
Dim ObjExcelWrite As New Excel.Application
Dim objWS As New Excel.Worksheet
ObjExcelWrite.Visible = False
objWS = ObjExcelWrite.Worksheets.Item(1)
''filling the excel cells with latitude : Problem here is -
'' Excel identify this value in time format, this should be identified by excel as string
objWS.Cells(1, 1).Value = "10:36:59"
ObjExcelWrite.Workbooks.Close() '' Problem here :A Save dialog box from excel appears
''prompting "Yes" "No" "Cancel" .While Clicking "Cancel"
'' The Application crashes
objWS = Nothing
ObjExcelWrite = Nothing