Wenn Ihr mit den Funktion von
CopyText fromTemplate=“Template.rtf“ ToText=“Bericht“
CopyText fromText=“Bericht“ toFile=“&%[TMP]\Bericht.doc“
ein im MS-Word erstellten RTF-Dokument alle Variablen ersetzt und das fix fertige Dokument als *.doc speichert, so ist es eigentlich immer noch ein RTF-File.
Möchte man, dass es ein echtes MS-WORD Dokument wird, und dies gleich noch im neuen *.docx Format, so bedarf es einer Umwandlung.
Java Script
function ConvertWordToDocx(docInputFile, docxOutputFile) {
var fileSystemObject;
var wordApplication;
var wordDocument;
var wordDocuments;
var baseFolder;
var wdFormatDOCX = 16;
fileSystemObject = guixt.CreateObject("Scripting.FileSystemObject");
wordApplication = guixt.CreateObject("Word.Application");
wordDocuments = wordApplication.Documents;
docInputFile = fileSystemObject.GetAbsolutePathName(docInputFile);
baseFolder = fileSystemObject.GetParentFolderName(docInputFile);
if (!docxOutputFile)
{
docxOutputFile = fileSystemObject.GetBaseName(docInputFile) + ".docx";
}
if ((fileSystemObject.GetParentFolderName(docxOutputFile).length) == 0)
{
docxOutputFile = baseFolder + "\\" + docxOutputFile;
}
// Disable any potential macros of the word document.
wordApplication.WordBasic.DisableAutoMacros();
wordDocument = wordDocuments.Open(docInputFile);
// See http://msdn2.microsoft.com/en-us/library/bb221597.aspx
wordDocument.SaveAs(docxOutputFile, wdFormatDOCX);
var WdDoNotSaveChanges = 0;
wordDocument.Close(WdDoNotSaveChanges);
wordApplication.Quit(WdDoNotSaveChanges);
};
Der Aufruf im GuiXt Script erfolgt wie folgt:
calljs ConvertWordToDocx "&%[TMP]\Bericht.doc" "&%[TMP]\Bericht.docx"
