Programmatically convert * .odt file to MS Word * .doc file using the OpenOffice.org base macro

I am trying to create reStructuredText in the tool chain of a Word Word document, so I can only save rst sources in version control.

I still

Have rst2odt.py to convert the reStructuredText format to the OpenOffice.org Writer format.

Next, I want to use the very latest OpenOffice.org (currently 3.1), which does a pretty decent job of creating a Word 97/2000 / XP document, so I wrote a macro:

sub ConvertToWord(file as string)
  rem ----------------------------------------------------------------------
  rem define variables
  dim document   as object
  dim dispatcher as object
  rem ----------------------------------------------------------------------
  rem get access to the document
  document   = ThisComponent.CurrentController.Frame
  dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

  rem ----------------------------------------------------------------------
  dim odf(1) as new com.sun.star.beans.PropertyValue
  odf(0).Name = "URL"
  odf(0).Value = "file://" + file + ".odt"
  odf(1).Name = "FilterName"
  odf(1).Value = "MS Word 97"
  dispatcher.executeDispatch(document, ".uno:Open", "", 0, odf())

  rem ----------------------------------------------------------------------
  dim doc(1) as new com.sun.star.beans.PropertyValue
  doc(0).Name = "URL"
  doc(0).Value = "file://" + file + ".doc"
  doc(1).Name = "FilterName"
  doc(1).Value = "MS Word 97"

  dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, doc())
end sub

But when I execute it:

soffice "macro:///Standard.Module1.ConvertToWord(/path/to/odt_file_wo_ext)"

I get: "BASIC runtime error. Property or method not found." message In the line:

document   = ThisComponent.CurrentController.Frame

, , . , - document , , .

?

P.S. JODConverter , .

+3
1

JODConverter ( ), , , / OpenOffice/LibreOffice DOC, // . .

0

Source: https://habr.com/ru/post/1716203/


All Articles