|
发表于 2017-3-28 09:35:40
|
显示全部楼层
假设将文件保存到c:\mytest.xlsx中去
$filename = "c:\lhq.csv"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = True
$oExcel.DisplayAlerts = True
$oWorkbook_o = $oExcel.Workbooks.Add
$oWorkbook_o.activesheet.Columns.Select
$oWorkbook_o.activesheet.Selection.NumberFormatLocal = "@"
Local $aArray=[1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
With $oWorkbook_o.ActiveSheet.QueryTables.Add("TEXT;" & $filename , $oWorkbook_o.activesheet.Range("A1"))
.Name = "lhq"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = 1; xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 936
.TextFileStartRow = 1
.TextFileParseType = 1;xlDelimited
.TextFileTextQualifier = 1 ;xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes =$aArray; Array(1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh(False)
EndWith
$oWorkbook_o.saveas("c:\mytest.xls",51)
$oWorkbook_o.close
$oExcel.quit |
|