Recently Browsing 0 members
No registered users viewing this page.
i wrote this function as alternative to using the Com Object or Commandline version of this project, discussed also earlyer on this forum.
Project site - http://ebstudio.info/home/xdoc2txt.html
Advantage of this implementation is that you do not need to register Com dll, using regsvr32.
But you still need the project Dll (xd2txlib.dll).
; #FUNCTION# ==================================================================================================================== ; Name ..........: _ExtractText ; Description ...: Extracts text from advanced documment formats (Doc, Docx, ODT, XLS, ...) ; Syntax ........: _ExtractText($sFilename[, $bProperties = False[, $hDll = 0]]) ; Parameters ....: $sFilename - a string value. ; $bProperties - [optional] a boolean value. Default is False. If True, documment properties will be returned instead of the text. ; $hDll - [optional] a handle value. Default is 0. Optional handle to previously opened xd2txlib.dll. By default the xd2txlib.dll (Expected in @scriptdir) will be opened and closed during the function call. ; Return value .: String, containing the text or documment properties or empty string and Error as follows: ;1 - The file does not exists. ;2 - Error during opening xd2txlib.dll. ;3 - No text returned. ; Author ........: Fenzik ; Modified ......: ; Remarks .......: Project site - http://ebstudio.info/home/xdoc2txt.html ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ExtractText($sFilename, $bProperties = False, $hDll = 0) If Not FileExists($sFilename) Then Return SetError(1, "", "") Local $bLoaded = False If $hDll = 0 Then $hDll = DllOpen(@scriptdir&"\xd2txlib.dll") If $hDll = -1 Then Return SetError(2, "", "") $bLoaded = True Endif $aResult = DllCall($hDll, "int:cdecl", "ExtractText", "WSTR", $sFilename, "BOOL", $bProperties, "WSTR*", "") If $aResult = 0 Then Return SetError(3, "", "") If $bLoaded = True Then DllClose($hDll) Return $aResult EndFunc
I have a Word document containing a 9-column table where row 1 is the column headers. My goal is to read the table into a 2d array, remove some rows, update some fields, and add a few rows to the end. The resulting array will likely be a different length. Next, I want to write the data back into the table. If it's easier, I can write the data to a new document from a template containing the same table header with a blank 2nd row.
Here's my early attempt:
Local $oWord = _Word_Create() Local $oDoc = _Word_DocOpen($oWord, $sFile) Local $aData = _Word_DocTableRead($oDoc, 1) $aData = "Something else" Local $oRange = _Word_DocRangeSet($oDoc, 0) $oRange = _Word_DocRangeSet($oDoc, $oRange, $wdCell, 9) _Word_DocTableWrite($oRange,$aData) This, unfortunately, writes the entire array into the first cell of row 2. What am I doing wrong?
Our Microsoft Office Templates shared folder was changed from a DFS share to an Isilon share. example:
Old Server: \\Domain.com\Office\Templates
New Server: \\Templates.domain.com\Office\Templates
The team making the changes overlooked that several hundred thousand documents, had been attached to the old template documents. So when you open a document which has been attached, it will take a couple of minutes to open, while it tries to locate the old server path. I've been asked to come in and fix it, so after several hours found that the data is being held in document.zip\word\_rels\settings.xml.rels, I now need to replace the old server path with the new server path. I didn't want to use dom as that would take too long and found a tool wtc https://github.com/NeosIT/wtc which works perfectly, takes about 8 minutes to scan a single directory with 4000 documents and fix them. The problem is the documents are all held on sharepoint and they want to retain the file timestamp, which is easy enough, but they also don't want to keep the "Modified By" apparently they don't like seeing all the documents appearing as "Modified by: Subz" Anyone know of way to retain the "Modified By" info,
Good evening everyone
I am working with Word UDF ( thanks @water! ), and, especially, with the function _Word_DocFindReplace().
The replace does work everywhere in the document, but, it does not work in Headers or Footers.
Am I missing something or am I forced to use the code below?
I have already looked in the Help file ( about _Word_DocFindReplace() ), but there are no mentions about replace text in Headers/Footers.
Sub FindAndReplaceFirstStoryOfEachType() Dim rngStory As Range For Each rngStory In ActiveDocument.StoryRanges With rngStory.Find .Text = "find text" .Replacement.Text = "I'm found .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With Next rngStory End Sub Thanks everyone in advance
im working on a Script that should change a high amount of Word Templates at once.
Target is to open each Templatefile (.dotx) in a specific folder and do the following steps:
Add a page break at the end of the document (works) Add a text on the created Page (works) Change the headerstyle to blank for the new page and the following (missing) Add a heading between two specific headings (missing) Can please someone help me to add the 2 functions to the script?
#include <word.au3> #include <File.au3> #include <array.au3> ; wdGoToDirection Const $wdGoToNext = 2 ; wdGoToItem Const $wdGoToPage = 1 ; Created a logfile for tracking/error reporting on my local desktop, though anywhere would work. Needs to be changed or it will error. Global $LogFile = FileOpen("c:\logfiles\test.log", 1) ; This is the network path, change it or this will error as it is. ListFiles ("D:\Templates\") Global $loopend=$aFileList ; Creates an instance of Word for the program to use. Logs any errors associated. Global $oWord = _Word_Create(False, False) If @error <> 0 Then Exit _FileWriteLog($LogFile, "Error creating a new Word application object. @error = " & @error & ", @extended = " & @extended & @crlf) If @extended = 1 Then _FileWriteLog ($LogFile, "MS Word was not running when _Word_Create was called." & @CRLF) Else _FileWriteLog ($LogFile, "MS Word was already running when _Word_Create was called." & @CRLF) EndIf ; Logs and begins loop _FileWriteLog ($LogFile, "Beginning Loop." & @CRLF) For $looper = 1 to $loopend Step +1 _FileWriteLog ($LogFile, "Modifying file: " & $aFileList[$looper], " ") OpenAndModify ("D:\Templates\" & $aFileList[$looper]) Next ; Closes instance of Word _Word_Quit ($oWord) _FileWriteLog ($LogFile, "Program Completed.") ; Begins Function section ; Two functions, Listfiles and OpenAndModify Func ListFiles($FolderPath) ; Function puts all files in the network folder into an array. Logs any errors. _FileWriteLog ($LogFile, "Getting File Information for: " & $FolderPath & @crlf) Global $aFileList = _FileListToArray($FolderPath, "*") If @error = 1 Then _FileWriteLog($LogFile, "Path was invalid." & @crlf) EndIf If @error = 4 Then _FileWriteLog ($LogFile, "No file(s) were found." & @crlf) EndIf EndFunc Func OpenAndModify ($sDocument) ; Function opens file and changes the Page Setup ; Opens the Document Local $oDoc = _Word_DocOpen ($oWord, $sDocument, Default, Default, Default) If @error <> 0 Then _FileWriteLog ($LogFile, "Error opening " & $sDocument & " @error = " & @error & ", @extended = " & @extended & @crlf) & Exit ; Changes Tray Settings ;$oDoc.PageSetup.FirstPageTray = 0 ;$oDoc.PageSetup.OtherPagesTray = 0 ; Add a link to the end of the document and set parameters ; ScreenTip and TextToDisplay Local $oRange = _Word_DocRangeSet($oDoc, -2); Go to end of document $oRange.InsertBreak($wdPageBreak) ;MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocRangeSet Example", "Inserted a break.") $oRange.Text = "«Text»" ; Add a space at the end of the document $oRange = _Word_DocRangeSet($oDoc, -2) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", _ "Error adding a link to the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocLinkAdd Example", "Baustein wurde an das Ende des Dokuments eingefügt.") ; Saves the document _Word_DocSave($oDoc) _FileWriteLog ($LogFile, "Modification of" & $sDocument & " complete." & @CRLF) EndFunc