如何在不同excel之间实现工作表的复制?
感谢xwjsyyx的热心帮忙...
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("", 251, 64, -1, -1)
GUISetIcon("D:\008.ico")
$ButtonOk = GUICtrlCreateButton("确定(&O)", 143, 16, 83, 25, 0)
$Buttonchose = GUICtrlCreateButton("选择数据 ", 26, 16, 83, 25, 0)
GUISetState(@SW_SHOW)
GUICtrlSetState($Buttonchose,$GUI_FOCUS)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
FileDelete (@TempDir & "\filename.txt")
Exit
Case $Buttonchose
If FileExists(@TempDir & "\filename.txt") Then FileDelete(@TempDir & "\filename.txt")
$message = "按ctrl或shift选择文件."
$var = FileOpenDialog($message, @DesktopCommonDir & "\", "Excel文件 (*.csv)", 1 + 4)
If @error Then
MsgBox(16, "警告", "没有选中文件")
Else
$v = StringReplace($var, "|", @CRLF) ;
FileWrite(@TempDir & "\filename.txt", $v)
EndIf
Case $ButtonOk
If Not FileExists (@TempDir&"\filename.txt") Then
MsgBox (16,"警告","请先选择数据")
Else
GUICtrlSetState ($Buttonchose ,$GUI_DISABLE)
GUICtrlSetState ($ButtonOk ,$GUI_DISABLE)
$path = FileReadLine(@TempDir&"\filename.txt",1) ;读取路径
$oExcel=ObjCreate("Excel.Application")
$oExcel.Visible = 1
$NEW=$oExcel.WorkBooks.Add
$i = 2
While $i < 200
$file = FileReadLine(@TempDir&"\filename.txt",$i) ;读取文件名
If @error = -1 Then
$MSG = MsgBox (64,"","完成")
If $MSG = 1 Then
GUICtrlSetState ($Buttonchose ,$GUI_ENABLE)
GUICtrlSetState ($ButtonOk ,$GUI_ENABLE)
ExitLoop
EndIf
EndIf
$fpath = $path&"\"&$file ;文件路径
$OPEN=$oexcel.workbooks.open ($fpath)
$name = $oExcel.Activesheet.Cells(2, 10).Value
$oExcel.ActiveSheet.Name = $name
$OPEN.sheets(1).copy (Default,$NEW.sheets($i))
$OPEN.close (0)
$i = $i + 1
WEnd
EndIf
EndSwitch
WEnd
[ 本帖最后由 jydgod 于 2008-5-12 19:39 编辑 ] |