Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CSV to EXCEL conversion
#1
Hi all

I am running csv to excel conversion code in QTP9.5 , the execution and results are fune except that some of the "date" field data in CSV is converted to "numbers" in excel.

Any comments or help is appreciated.

Many thanks in advance

below is the code I am using

'Function Name : CSV to excel
'Fucntion Description: 'VBScript to convert CSV file to Excel - number format issue
'Test data used : test data
'Date : 21/04/09
'Written by :
'*******************************************************************
Code:
Function csvtoexcel Dim fldr, f, file,strOrigFile, strFile, fso, strDirectory Dim objExcel strOrigFile = "C:\QTPV6\results\actual\200906019043a.csv"
'******************************************************
'CONVERTS THE FILE TO AN EXCEL FILE
'******************************************************
Code:
strFile = replace(strOrigFile,".csv",".xls") Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.Open strOrigFile objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.SaveAs strFile, -4143 objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.Close objExcel.DisplayAlerts = False objExcel.Application.Quit

'******************************************************
'FORMAT THE EXCEL FILE AND SAVE IT
'******************************************************

Code:
objExcel.Workbooks.Open strFile objExcel.columns("A:A").numberformat="0" objExcel.columns("C:C").numberformat="0" objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.SaveAs strFile, -4143 objExcel.DisplayAlerts = False objExcel.ActiveWorkbook.Close objExcel.DisplayAlerts = False objExcel.Application.Quit Set objExcel = Nothing End Function
Reply
#2
Hi,
Thanks for the posting here,
i tried with your cide but i oserved that i am able to render the date field instead of number (This might be the setting in Excel --Format Cells-->Number-->Date-->Select the appropriate format)
If possible could you attach the .cv files also
Reply
#3
@neerukonda9 - always wrap your code to make your post more readable. refer Mycode section in help.

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem With conversion function wajid 3 2,535 10-01-2018, 01:16 PM
Last Post: wajid
  How to update CSV File and need to Save same CSV File kotaramamohana 1 4,030 10-24-2015, 08:40 AM
Last Post: tigerliew
  Pdf to Excel or any other Format Conversion branjitk 1 2,931 06-14-2012, 08:14 AM
Last Post: basanth27
  Working with .csv Files pjeigenn 0 2,042 08-02-2010, 07:15 PM
Last Post: pjeigenn

Forum Jump:


Users browsing this thread: 1 Guest(s)