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

[AU3基础] 批量处理doc文档是遇到无法处理的文档即出错退出

[复制链接]
发表于 2011-3-19 14:24:07 | 显示全部楼层 |阅读模式
本帖最后由 papapa314 于 2011-3-19 14:27 编辑

批量处理doc文档的时候碰到这样的问题:当doc文档的编码有问题或者为文件属性为只读的时候,程序马上出错退出。请问各位,如何判断这类无法处理的doc文档,然后自动跳过这些文档,保证程序不会出错?
以下是部分源码,我用设置文件属性的方法,遇到某些doc文档还是程序还是直接退出。出错原因是word UDF的一个函数
        $o_doc = $o_object.Documents.Open ($s_FilePath, $f_ConfirmConversions, $f_ReadOnly, $f_AddToRecentFiles, _
                        $s_PasswordDocument, "", $f_Revert, $s_WritePasswordDocument, "", $i_Format)
        If Not IsObj($o_doc) Then
                __WordErrorNotify("Error", "_WordDocOpen", "", "Document Object Creation Failed")
                Return SetError($_WordStatus_GeneralError, 0, 0)
        EndIf

谢谢您的关注!!!



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include<file.au3>
#include<array.au3>
#include <Word.au3>
#Include <GuiListView.au3>



$Form1_1 = GUICreate("word改内容测试", 587, 572);这个要放在使用时间限制的前面。
$listview1=GUICtrlCreateListView("路径",50,50,400,400)
$buton1=GUICtrlCreateButton("添加",450,450,50,50)
$buton2=GUICtrlCreateButton("开始",520,520,50,50)
GUISetState()


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $buton1
                        open()
                Case $buton2
                        start()
        EndSwitch
WEnd

        



Func open()

$file=FileOpenDialog("","","(*.doc)",4)
;MsgBox(0,0,$file)
$filearray=StringSplit($file,"|")
;_ArrayDisplay($filearray)
Dim $path[$filearray[0]-1]
For $i=0 To $filearray[0]-2
        $path[$i]=$filearray[1]&"\"&$filearray[$i+2]
Next;...........................................多选文件时得到每个文件的完整路径

;_ArrayDisplay($path)
For $i=0 To $filearray[0]-2
;MsgBox(0,0,$path[$i])

GUICtrlCreateListViewItem($path[$i],$listview1)

Next

EndFunc




Func start()
        
For $i=0 To _GUICtrlListView_GetItemCount($listview1)-1

        $oWordApp = _WordCreate(_GUICtrlListView_GetItemText($listview1,$i),1,0)
        $oWordDoc = _WordDocGetCollection($oWordApp, 0)
        If Not @error Then
        $oWordDoc.Range.insertBefore("大家好");在文档开头加入一段话
        EndIf


        _WordDocClose($oWordDoc,-1)

        _WordQuit ($oWordApp, -1)


        
Next
EndFunc

发表于 2011-3-20 12:29:28 | 显示全部楼层
if $oWordDoc.ReadOnly=false then $oWordDoc.Range.insertBefore("大家好")
判断只读可以加上这个判断
不知 楼主所说的编码有问题是什么情况。
发表于 2011-3-20 12:37:37 | 显示全部楼层
最好修改和保存放在一起处理,一起判断执行。
 楼主| 发表于 2011-3-21 16:13:40 | 显示全部楼层
回复 2# kevinch


    谢谢热心回复。编码问题就是当文档里有乱码的话软件就自动退出,还有一些word文档,也不知道有什么问题,手动打开是正常的,但就是无法处理,一处理到这个文档软件就自动退出。不知道如何判断这类无法处理的文档?
发表于 2011-3-21 18:52:00 | 显示全部楼层
回复  kevinch


    谢谢热心回复。编码问题就是当文档里有乱码的话软件就自动退出,还有一些word文档 ...
papapa314 发表于 2011-3-21 16:13

还真没遇到过你说的那样的文件,乱码应该不影响打开的情况,除非打开时有询问编码的情况,没遇到,还真没概念。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 10:46 , Processed in 0.080635 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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