找回密码
 加入
搜索
查看: 2524|回复: 4

[AU3基础] [已解决]excel UDFs 不能在用在 2010 ?

[复制链接]
发表于 2012-11-10 02:17:03 | 显示全部楼层 |阅读模式
本帖最后由 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 )


謝謝各位不吝指導,感激不盡。
发表于 2012-11-10 13:04:38 | 显示全部楼层
不是不支持,是只支持后缀名xls,2013测试了所有函数

评分

参与人数 1金钱 +20 收起 理由
edisonx + 20 感謝提點,一點意思,不成敬意。

查看全部评分

 楼主| 发表于 2012-11-10 13:46:39 | 显示全部楼层
回复 2# netegg


謝謝您的回答,確認一下,所以只支援寫入 xls,不支援其他 extend filename ?

感謝。
发表于 2012-11-10 15:44:16 | 显示全部楼层
用vba原型来修改,就可以都支持啦
 楼主| 发表于 2012-11-11 18:51:41 | 显示全部楼层
回复 4# kevinch


是可以沒錯,只是挑用 au 其中一個原因便是 office 自動化不用重刻原始碼。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-29 19:28 , Processed in 0.178078 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表