Hello,
i am using VB script to convert the csv file into xls ( ofc 97 -2003) version. when i conver the file and open with excel i am getting error for the below data.
Example : Source CSV DATA: "423E2847" , Target (xls) its converted into scientfic form: 4.2e+13 like this.
i have text qualifier as double quotes and using text data type in VB still i am unable to get this corrected. for long numbers its showing correctly issue occurig only the text contains "E" letter in it. i want the source data to be displayed in excel as it is i.e 423E2847
Note: i want this to be in script . i coped the script i am using below.
Script:
'======================================
' Convert CSV to XLS
'
' arg1: source - CSV path\file
' arg2: target - Excel path\file
'======================================
srccsvfile = Wscript.Arguments(0)
tgtxlsfile = Wscript.Arguments(1)
'Create Spreadsheet
'Look for an existing Excel instance.
On Error Resume Next ' Turn on the error handling flag
Set objExcel = GetObject(,"Excel.Application")
'If not found, create a new instance.
If Err.Number = 429 Then '> 0
Set objExcel = CreateObject("Excel.Application")
End If
objExcel.Visible = false
objExcel.displayalerts=false
'Defining all columns as string
strDataTypes= "Array("
strDataTypes= strDataTypes & "Array(1,2)" ' Column 1 as Text format
strDataTypes= strDataTypes & "Array(2,2)"
strDataTypes= strDataTypes & "Array(3,2)"
strDataTypes= strDataTypes & "Array(4,2)"
strDataTypes= strDataTypes & ")"
objExcel.Workbooks.OpenText srccsvfile,,,1 _
, 1, True, False, False, True,False,False, _
, Eval(strDataTypes)
set wb=objExcel.ActiveWorkbook
'Adjust width of columns
'This code could be used to AutoFit a select number of columns
For intColumns = 1 To 17
objExcel.Columns(intColumns).AutoFit()
Next
'Make Headings Bold
objExcel.Rows(1).Font.Bold = TRUE
'Freeze header row
With objExcel.ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
objExcel.ActiveWindow.FreezePanes = True
'Add Data Filters to Heading Row
objExcel.Rows(1).AutoFilter
'set header row gray
objExcel.Rows(1).Interior.ColorIndex = 15
'Save Spreadsheet, 56 = Excel 2003-2007
wb.SaveAs tgtxlsfile, 56, , , , False
wb.Close
'Release Lock on Spreadsheet
objExcel.Quit()
i am using VB script to convert the csv file into xls ( ofc 97 -2003) version. when i conver the file and open with excel i am getting error for the below data.
Example : Source CSV DATA: "423E2847" , Target (xls) its converted into scientfic form: 4.2e+13 like this.
i have text qualifier as double quotes and using text data type in VB still i am unable to get this corrected. for long numbers its showing correctly issue occurig only the text contains "E" letter in it. i want the source data to be displayed in excel as it is i.e 423E2847
Note: i want this to be in script . i coped the script i am using below.
Script:
'======================================
' Convert CSV to XLS
'
' arg1: source - CSV path\file
' arg2: target - Excel path\file
'======================================
srccsvfile = Wscript.Arguments(0)
tgtxlsfile = Wscript.Arguments(1)
'Create Spreadsheet
'Look for an existing Excel instance.
On Error Resume Next ' Turn on the error handling flag
Set objExcel = GetObject(,"Excel.Application")
'If not found, create a new instance.
If Err.Number = 429 Then '> 0
Set objExcel = CreateObject("Excel.Application")
End If
objExcel.Visible = false
objExcel.displayalerts=false
'Defining all columns as string
strDataTypes= "Array("
strDataTypes= strDataTypes & "Array(1,2)" ' Column 1 as Text format
strDataTypes= strDataTypes & "Array(2,2)"
strDataTypes= strDataTypes & "Array(3,2)"
strDataTypes= strDataTypes & "Array(4,2)"
strDataTypes= strDataTypes & ")"
objExcel.Workbooks.OpenText srccsvfile,,,1 _
, 1, True, False, False, True,False,False, _
, Eval(strDataTypes)
set wb=objExcel.ActiveWorkbook
'Adjust width of columns
'This code could be used to AutoFit a select number of columns
For intColumns = 1 To 17
objExcel.Columns(intColumns).AutoFit()
Next
'Make Headings Bold
objExcel.Rows(1).Font.Bold = TRUE
'Freeze header row
With objExcel.ActiveWindow
.SplitColumn = 0
.SplitRow = 1
End With
objExcel.ActiveWindow.FreezePanes = True
'Add Data Filters to Heading Row
objExcel.Rows(1).AutoFilter
'set header row gray
objExcel.Rows(1).Interior.ColorIndex = 15
'Save Spreadsheet, 56 = Excel 2003-2007
wb.SaveAs tgtxlsfile, 56, , , , False
wb.Close
'Release Lock on Spreadsheet
objExcel.Quit()