本帖最后由 edisonx 于 2012-11-11 18:48 编辑
各位先進好,
小弟想練 Excel 自動化,手邊的是 excel 2010,
無奈的是打開 help file 任何一個範例,
副檔名從 .xls 改成 .xlsx 都會失敗 ( xls 是正常沒錯),
最後錯誤訊息都指向 Excel.au3 裡,如下
...../Excel.au3 (191) : ==> The requested action with this object has failed.:
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)
If $sPassword = "" And $sWritePassword = "" Then .WorkBooks.Open($sFilePath, Default, $fReadOnly)^ ERROR
請教 AU 是否對於 office 是否不支援 2007 以後?
附上 source code
#include <Excel.au3>
#include <File.au3>
Local $sFilePath = @TempDir & "\Temp.xlsx"
If Not _FileCreate($sFilePath) Then ;Create an .XLS file to attach to
MsgBox(4096, "Error", " Error Creating File - " & @error)
EndIf
_ExcelBookOpen($sFilePath)
If @error Then sLog("_ExcelBookOpen")
Local $oExcel = _ExcelBookAttach($sFilePath) ;with Default Settings ($s_mode = "FilePath" ==> Full path to the open workbook)
If @error Then sLog("_ExcelBookAttach")
_ExcelWriteCell($oExcel, "If you can read this, then Success!", 1, 1) ;Write to the Cell
If @error Then sLog("_ExcelWriteCell")
MsgBox(0, "Exiting", "Press OK to Save File and Exit")
_ExcelBookClose($oExcel, 1, 0) ;This method will save then Close the file, without any of the normal prompts, regardless of changes
If @error Then sLog("_ExcelBookClose")
Func sLog($str)
ConsoleWrite( StringFormat("%s : %d\n", $str, @error) )
EndFunc
還沒機會跑出 @error 就出現 excel.au3 物件需求失敗。
最後想請教,目前 AU 掛 excel 作法是編成執行檔做外掛,
是否有方式像 C# 做成 plug-in ? ( menu 多個選項,excel 開啟後不再額外開 exe )
謝謝各位不吝指導,感激不盡。 |