Jump to content

Dos to Word Application


milky
 Share

Recommended Posts

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:)

Link to comment
Share on other sites

  • 5 years later...

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
 Share

×
×
  • Create New...