Convert file to DOCX from command line?

Post Reply
emendelson
Posts: 1
Joined: Tue Oct 17, 2017 3:07 pm

Convert file to DOCX from command line?

Post by emendelson »

I saw in another post that there's a command-line method for converting documents to PDF format, but I haven't found a command-line method of opening a document and exporting it in DOCX format. Does that exist?

The PDF export post is here:

https://forum.softmaker.com/viewtopic.php?t=19096

It would be good to have an equivalent for DOC or DOCX. Is this possible?
miguel-c
SoftMaker Team
SoftMaker Team
Posts: 1233
Joined: Wed Jun 05, 2019 12:02 pm

Re: Convert file to DOCX from command line?

Post by miguel-c »

You can program this with BasicMaker.
Jossi
SoftMaker Volunteers
SoftMaker Volunteers
Posts: 1263
Joined: Fri Dec 05, 2003 10:47 pm
Location: Luebeck, Germany

Re: Convert file to DOCX from command line?

Post by Jossi »

A BasicMaker script to convert documents into other formats has been posted in the German forum:
https://forum.softmaker.de/viewtopic.ph ... 21#p118121
Jossi
SoftMaker Volunteers
SoftMaker Volunteers
Posts: 1263
Joined: Fri Dec 05, 2003 10:47 pm
Location: Luebeck, Germany

Re: Convert file to DOCX from command line?

Post by Jossi »

As the script I mentioned is in German, I've made a rough English translation:

Code: Select all

REM TextMaker Automatic File Conversion 2018
Set tm = CreateObject("TextMaker.Application")
tm.Application.Visible = True

DIM x, z AS Long

DIM Dateityp(22) AS String
	Dateityp(0)="TextMaker document"
	Dateityp(1)="TextMaker template"
	Dateityp(2)="Microsoft Word for Windows 97 & 2000"
	Dateityp(3)="OpenDocument, LibreOffice, OpenOffice.org, StarOffice"
	Dateityp(4)="Rich Text Format"
	Dateityp(5)="Pocket Word for Pocket PC"
	Dateityp(6)="Pocket Word for Handheld PC"
	Dateityp(7)="Text file, Code Page 1252 (Windows)"
	Dateityp(8)="Text file, Code Page 437 (DOS)"
	Dateityp(9)="Text file, Unicode"
	Dateityp(10)="Text file, UTF-8"
	Dateityp(11)="HTML"
	Dateityp(12)="Microsoft Word for Windows 6.0"
	Dateityp(13)="Text file for UNIX, Linux, FreeBSD"
	Dateityp(14)="Microsoft Word for Windows XP and 2003"
   	Dateityp(15)="TextMaker 2006 document"
   	Dateityp(16)="OpenXML (DOCX)"
   	Dateityp(17)="TextMaker 2008 document"
	Dateityp(18)="OpenXML template (DOTX)"
	Dateityp(19)="Microsoft Word for Windows XP and 2003 template"
	Dateityp(20)="TextMaker 2012 document"
	Dateityp(21)="TextMaker 2016 document"
	Dateityp(22)="TextMaker 2016 template"



Begin Dialog DIALOG_1 147,49, 200, 92, "Output format"
  Text 4,4,188,24, "Please choose output file type from list below."
  DropListBox 4,36,144,32, Dateityp(), .DropDown_1
  OKButton 160,60,24,20
End Dialog

DIM Dlg1 AS DIALOG_1

Set sl = CreateObject("Shell.Application")
Set ordner = sl.BrowseForFolder(0, "Please select folder with files to convert.", 0, 0)
        If not ordner is Nothing then
           quellordnername = ordner.self.Path
        Else
          MsgBox "No folder found!"
          End
        End If

x=Dialog(Dlg1)
z=Dlg1.DropDown_1
Select Case z
Case 0
	endg="tmdx"
Case 1
	endg="tmvx"
Case 2, 12, 14
	endg="doc"
Case 3
	endg="odt"
Case 4
	endg="rtf"
Case 5
	endg="psw"
Case 6
	endg="pwd"
Case 11
	endg="htm"
Case 7, 8, 9, 10, 13
	endg="txt"
Case 15, 17, 20, 21
	endg="tmd"
Case 16
   endg="docx"
Case 18
	endg="dotx"
Case 19
	endg="dot"
Case 22
	endg="tmv"
End Select
if z>10 then z=z+1
if z>18 then z=z+3
if z>23 then z=z+3

Set ordner = sl.BrowseForFolder(0, "Please select output folder.", 0, 0)
        If not ordner is Nothing then
           zielordnername = ordner.self.Path
        Else
          MsgBox "No folder found!"
          End
        End If

Set fs = CreateObject("Scripting.FileSystemObject")
Set dr = fs.GetFolder(quellordnername)
For each dateiname in dr.files
	tm.Documents.Open dateiname, Empty, Empty, Empty, 0
dname=tm.ActiveDocument.Name
l=len(dname)
test=Right(dname, 5)
test=Mid(test, 1, 1)
If test="." Then l=l-4 Else l=l-3
dname=Mid(dname, 1, l)
neuername=zielordnername+"\"+dname+endg
  	tm.ActiveDocument.SaveAs neuername, z
   tm.ActiveDocument.Close smoDoNotSaveChanges
next
tm.Application.Quit
Set tm = Nothing
End
And here the script für PlanMaker:

Code: Select all

REM PlanMaker Automatic File Conversion 2018
Set pm = CreateObject("PlanMaker.Application")
pm.Application.Visible = True

DIM x, y, z AS Long

DIM Dateityp(22) AS String
	Dateityp(0)="PlanMaker document"
   Dateityp(1)="PlanMaker template"
   Dateityp(2)="Excel 97/2000/XP"
   Dateityp(3)="Excel 5.0/7.0"
   Dateityp(4)="Excel template"
   Dateityp(5)="Sylk"
   Dateityp(6)="Rich Text Format"
   Dateityp(7)="HTML"
   Dateityp(8)="dBASE file, DOS character set"
   Dateityp(9)="dBASE file, Windows character set"
   Dateityp(10)="Text file with Windows character set (DIF)"
   Dateityp(11)="Text file with Windows character set (ANSI)"
   Dateityp(12)="Text file with DOS character set"
   Dateityp(13)="Text file with ANSI character set for UNIX, Linux and FreeBSD"
   Dateityp(14)="Text file with Unicode character set"
   Dateityp(15)="dBASE file with Unicode character set"
   Dateityp(16)="Text file with UTF-8 character set"
   Dateityp(17)="Excel document (XLSX)"
   Dateityp(18)="Excel template (XLTX)"
   Dateityp(19)="PlanMaker 2008 document"
   Dateityp(20)="PlanMaker 2020 document"
   Dateityp(21)="PlanMaker 2012 document"
   Dateityp(22)="PlanMaker 2012 template"

Begin Dialog DIALOG_1 147,49, 200, 92, "Output format"
  Text 4,4,188,24, "Please choose output file type from list below."
  DropListBox 4,36,144,32, Dateityp(), .DropDown_1
  OKButton 160,60,24,20
End Dialog

DIM Dlg1 AS DIALOG_1

Set sl = CreateObject("Shell.Application")
Set ordner = sl.BrowseForFolder(0, "Please select folder with files to convert.", 0, 0)
        If not ordner is Nothing then
           quellordnername = ordner.self.Path
        Else
          MsgBox "No folder found!"
          End
        End If

x=Dialog(Dlg1)
z=Dlg1.DropDown_1
Select Case z
Case 0
	endg="pmdx"
	y=0
Case 1
	endg="pmvx"
	y=1
Case 2, 3
	endg="xls"
	y=z
Case 4
	endg="xlt"
	y=4
Case 5
	endg="slk"
	y=6
Case 6
	endg="rtf"
	y=7
Case 7
	endg="htm"
	y=8
Case 8, 9
	endg="dbf"
	y=z+1
Case 10
	endg="dif"
	y=11
Case 11, 12, 13, 14
   endg="txt"
	y=z+1
Case 15
	endg="dbf"
	y=18
Case 16
   endg="txt"
	y=21
Case 17
   endg="xlsx"
	y=23
Case 18
	endg="xltx"
	y=24
Case 19, 20, 21
	endg="pmd"
	y=z+7
Case 22
	endg="pmv"
	y=29
End Select

Set ordner = sl.BrowseForFolder(0, "Please select output folder.", 0, 0)
        If not ordner is Nothing then
           zielordnername = ordner.self.Path
        Else
          MsgBox "No folder found!"
          End
        End If

Set fs = CreateObject("Scripting.FileSystemObject")
Set dr = fs.GetFolder(quellordnername)
For each dateiname in dr.files
	pm.Workbooks.Open dateiname, False, Empty
dname=pm.ActiveWorkbook.Name
l=len(dname)
test=Right(dname, 5)
test=Mid(test, 1, 1)
If test="." Then l=l-4 Else l=l-3
dname=mid(dname, 1, l)
neuername=zielordnername+"\"+dname+endg
  	pm.ActiveWorkbook.SaveAs neuername, y, Empty, Empty
   pm.ActiveWorkbook.Close smoDoNotSaveChanges
next
pm.Application.Quit
Set pm = Nothing
End
Post Reply

Return to “BasicMaker 2018 for Windows”