我正在尝试创建一个vb脚本来将csv文件转换为xls文件。 我使用的脚本是:
Option Explicit
dim dtmToday,dtmDayOfWeek,objFSO,objArgs,i,CARF_STR_MGR,WSHSHELL,oExec,objStartFolder,objFolder,colFiles,objFile,wb
dim myXL,xl
Dim CSVfolder
Dim XlsFolder
Dim fname
Dim WorkBooks
Const xlDelimited = 1
Const xlWorkbookNormal = -4143
Const xlTextQualifierDoubleQuote = 1
Const xlOpenXMLWorkbook = 56
SET WSHSHELL = WSCRIPT.CREATEOBJECT("WSCRIPT.SHELL")
Set objArgs=Wscript.Arguments 'create object
dtmToday=objArgs(0)
dtmToday=formatDate("%Y%m%d",dtmToday)
Wscript.echo dtmToday
objStartFolder="\\xxxxxxxx\xxxxx\xxxxx\xxxxx"
Set xl = CreateObject("Excel.Application")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles= objFolder.Files
For Each objFile in colFiles
if LCase(objFSO.GetExtensionName(objFile))="csv" AND instr(objFile.Name,dtmToday)<>0 Then
xl.Workbooks.OpenText objFile, , , xlDelimited _
, xlTextQualifierDoubleQuote, True, False, False, False, False, True, _
",", Array(Array(1,2), Array(2,2), Array(3,2), Array(4,2), Array(5,2) _
, Array(6,2), Array(7,2), Array(8,2), Array(9,2), Array(10,2), Array(11,2))
Set wb = xl.ActiveWorkbook
wb.SaveAs ="\\xxxxxxxx\xxxxx\xxxxx\xxxxx"& objFile.name &".xls", xlOpenXMLWorkbook, , , , False
wb.Close
xl.Quit
End if
Next
Set wb = nothing
Set xl = nothing
function formatDate(format, intTimeStamp)
......
end function
此代码的问题是我似乎无法将列的特定值修改为文本,因此我在csv文件的一列中有一个值为00000,我需要此值保持不变但是在xls文件中转换为0。 有什么方法可以解决这个问题吗?