用move试试,我也是在论坛上学到的,呵呵,不解释! 几万行的数据一般在几秒内完成
给个栗籽 声明一下:我这个是学习别人的,非原创,但现在没找到作者,因此没法感谢原创,请原作者看到或者认识原创的人不要骂我,相互学习哦!
$path=@ScriptDir&"\汇总.xlsx"
$pathA=@ScriptDir&"\A.xls"
$pathB=@ScriptDir&"\B.xls"
$oExcel = ObjCreate("Excel.Application")
$oExcel.Visible = True
$oExcel.DisplayAlerts = False
; ############# Add New xlsx file #####################################
$oWorkbook_o=$oExcel.Workbooks.Add
$oWorkbook_o.SaveAs($path,51);51表示xlsx文件
$oWorkbook_o.Close
$oWorkbook = $oExcel.Workbooks.Open($path)
$oWorkBook1 = $oExcel.WorkBooks.Open($pathA)
$oWorkBook2 = $oExcel.WorkBooks.Open($pathB)
$oWorkBook1.WorkSheets(1).move($oWorkbook.Worksheets(1))
$oWorkBook2.WorkSheets(1).move($oWorkbook.Worksheets(2))
$oWorkbook.Sheets(1).Name = "AAAA"
$oWorkbook.Sheets(2).Name = "BBBB"
;~ $oWorkbook.Sheets(3).Name = "汇总"
$oWorkbook.Sheets("Sheet2").delete
$oWorkbook.Sheets("Sheet3").delete
$oWorkbook.Save
$oExcel.Quit
|