Sign in to follow this  
Followers 0
milky

Dos to Word Application

1 post in this topic

Hello,

I wrote a small AutoIt App which takes DOS formatted textfiles and forwards them to MS Word. I searched a lot for a programm which does this, but I didn't find one.

The reason for it is an old DOS program, which is used a lot, even today. The user wanted to print the output of that programm with some other font-size, font-style and so on... We used WinPrint, but this is a printing only app, so no formatting can be done afterwards... :(

The solution was, to print with the DOS prgramm to an file, e.g. C:\12345\output.txt ... then read this file, convert it to unicode, put this into word with some pre-defined font / page size and so on ... and then the user can re-format or print it now.

Here is the main function of the Dos2Word programm I wrote:

Func Convert2Word()
    ; keine datei da...
    If Not FileExists($sFilePath) Then Return

    ; noch in Beaarbeitung...
    If _WinAPI_FileInUse($sFilePath) Then Return

    ; nun aber...
    Local $sFilePathTemp = $sFilePath & "_" & _WinAPI_CreateGUID() & ".txt"
    FileMove($sFilePath, $sFilePathTemp, $FC_OVERWRITE)

    ; open word and create new document
    Local $oWord = _Word_Create()
    If @error Then ErrorExit("Fehler bei _Word_Create()")
    Local $oDoc = _Word_DocAdd($oWord)
    If @error Then ErrorExit("Fehler bei _Word_DocAdd()")

    ; seite definieren
    With $oDoc.PageSetup
        .PageHeight = $sPageHeight
        .PageWidth = $sPageWidth
        .TopMargin = $sTopMargin
        .BottomMargin = $sBottomMargin
        .LeftMargin = $sLeftMargin
        .RightMargin = $sRightMargin
    EndWith

    ; schrift und absatz
    With $oDoc.Range
        .Font.Name = $sFontName
        .Font.Size = $sFontSize
    EndWith
    With $oDoc.Range.ParagraphFormat
        .SpaceBefore = 0
        .SpaceAfter = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = 0
    EndWith

    Local $hFile = FileOpen($sFilePathTemp, BitOR($FO_READ, $FO_BINARY))
    Local $iError
    Local $iLine = 1
    Do
        Local $sLine = FileReadLine($hFile, $iLine)
        $iError = @error
        $iLine += 1

        ; ignore special escape line of cm.exe
        If StringLeft($sLine, 2) = Chr(27) & Chr(64) Then $sLine = StringTrimLeft($sLine, 2)

        $oDoc.Range.insertAfter(_WinAPI_MultiByteToWideChar($sLine, $sCodePage, 0, True) & @CRLF)
    Until $iError <> 0

    ; und am ende löschen, sofern gewünscht
    FileClose($hFile)
    If $sFilesDelete <> "0" Then FileDelete($sFilePathTemp)
EndFunc   ;==>Convert2Word

The Homepage of the program is here: https://mcmilk.de/projects/Dos2Word/

The full source code and precompild signed binaries for 32bit and 64bit systems are also there, the License is GPLv2 ;)

With best regards, Milky
Maybe someone finds it useful too o:)

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Neonovaz
      By Neonovaz
      Hello
       
      Is there anyway to store word documents in Autoit GUI? For example I have a instruction sheet that I want to bundle up with the exe.

      So a user simply clicks the icon and the stored document will launch  (Something like how you can add objects like excel sheets in word documents )

      (I Know we can launch word files from script directory)

       
    • fopetesl
      By fopetesl
      I need to be able to issue a command line which has a folder in parentheses as
       
      attrib +s +h "absolute folder to hide"  I've read through many posts here but nothing quite hacks how to use a variable as the folder in parentheses.
      I've tried
       
      Local $dosattrib = "attrib +s +h " & ""$hidFolder"" ; $hidFolder built up from decrypted encrypted C:\Hidden Folder which I do not want visible when compiled version is reverse engineered  which errors with excess parentheses but in single "" it doesn't work.
      There seems to be a relatively complicated method to make it work but surely there's a simple way?
       
       
    • Jury
      By Jury
      I've failed to find an example of _Word_DocFindReplace which searches for formatted text (I'm looking for stand alone paragraph marks that are formatted other than normal i.e. Bold Italic, Underlined). 
      The reason being that when converting a Word document to html one of the main problems in the results is that a stand alone paragraph mark is converted to an html space that retains the formatting ...>&nbsp;<... thus showing up as a underline _  in a browser when it should be blank.  I've played around with the script and got it to at least un-bold  the first paragraph mark regardless if it was bold or not but I'd like to clear all formatting from any stand alone paragraph marks in the whole document.  Below is what I've done so far (not much more than in the help file I'm afraid) .  Way down at the bottom of the _Word_DocFindReplace  help  text is this parameter but without any examples to be found :
      $bFormat   [optional] True to have the find operation locate formatting in addition to or instead of the find text (default = False) #include <MsgBoxConstants.au3> #include <Word.au3> $processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\' Global $oWord = _Word_Create() Global $sTestfile = $processing & "Testing.docx" ConsoleWrite($sTestfile & @CRLF) Global $oDoc = _Word_DocOpen($oWord, $sTestfile) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "ERROR", "Error opening file = '" & $sTestfile & "'" & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound = _Word_DocFind($oDoc, "^p", Default, Default) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error locating paragraph control character in the document." & @CRLF & "@error = " & @error & ", @extended = " & @extended) $oRangeFound.Bold = False If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", _ "Error inserting text after the paragraph control character in the document." & @CRLF & "@error = " & @error & _ ", @extended = " & @extended) MsgBox($MB_SYSTEMMODAL, "Word UDF: _Word_DocFind Example", "Paragraph control character successfully replaced." & @CRLF & _ "Text inserted in paragraph 2.")  
    • TheDcoder
      By TheDcoder
      Hello Everyone , Are you tired of searching the forum for getting both the exit code & the stdout output? Then you are in the right place!

      With this UDF you can get the both output & exit code of the command or the console app! Or you can get the exit code of another process without having to use RunWait...
      Features:
      1. Simple & Lightweight (15 KB)
      2. Detailed comments & description
      3. Flexible functions with many optional parameters
      A BIG THANKS TO PsaltyDS for the functions! 2 of the (main) functions in the UDF are his work
       
      List of functions:
      Downloads:
      Grab the latest (in development) code from GitHub
       
      Hope it may help you, TD
       
      P.S Icon made by Freepik from www.flaticon.com, Modified by TheDcoder
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me