Exporting Spreadsheet files as .odt

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sourav16
Posts: 5
Joined: Sat Dec 10, 2022 2:33 pm

Exporting Spreadsheet files as .odt

Post by sourav16 »

Dear Team,

I am trying to export the Openoffice Calc to .odt (i.e. OpenOffice Writer Format). I am using the following macro which I have used the following macro, which I have used to export the document to pdf, but the same is not working. Can anyone help me this matter

Following is the macro

Code: Select all

Sub Export_ODT
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 args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$A$1:$F$118"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
  Dim Cel As Object
  Dim Werkblad As Object
  Dim Werkmap As Object
  
  Werkmap=ThisComponent
  Werkblad=Werkmap.Sheets.getByName("SEL")
  Cel=Werkblad.getCellByposition(0,7) 'A8


args2(0).Name = "URL"
args2(0).Value = "file:///d:/SEL Calculator/"& Cel.getString()&".odt"
args2(1).Name = "FilterName"
args2(1).Value = "calc_odt_Export"
args2(2).Name = "FilterData"
args2(2).Value = Array(Array("UseLosslessCompression",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Quality",0,90,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ReduceImageResolution",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("MaxImageResolution",0,300,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTaggedPDF",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("SelectPdfVersion",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportNotes",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarks",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenBookmarkLevels",0,-1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("UseTransitionEffects",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsSkipEmptyPages",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("IsAddStream",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FormsType",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportFormFields",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerToolbar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerMenubar",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("HideViewerWindowControls",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ResizeWindowToInitialPage",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("CenterWindow",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("OpenInFullScreenMode",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DisplayPDFDocumentTitle",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialView",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Magnification",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Zoom",0,100,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PageLayout",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("FirstPageOnLeft",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("InitialPage",0,1,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Printing",0,2,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Changes",0,4,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableCopyingOfContent",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EnableTextAccessForAccessibilityTools",0,true,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportLinksRelativeFsys",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PDFViewSelection",0,0,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ConvertOOoTargetToPDFTarget",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("ExportBookmarksToPDFDestination",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("_OkButtonString",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("EncryptFile",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("DocumentOpenPassword",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("RestrictPermissions",0,false,com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("PermissionPassword",0,"",com.sun.star.beans.PropertyState.DIRECT_VALUE),Array("Selection",0,,com.sun.star.beans.PropertyState.DIRECT_VALUE))

dispatcher.executeDispatch(document, ".uno:ExportToPDF", "", 0, args2())


end sub  
Can anyone help me with the code.
OpenOffice 4.1.10 on Windows 10
JeJe
Volunteer
Posts: 2786
Joined: Wed Mar 09, 2016 2:40 pm

Re: Exporting Spreadsheet files as .odt

Post by JeJe »

xhtml and pdf are the only option in the export dialog. What you're doing is exporting to pdf with an .odt extension. If you change the exported file extension to .pdf it will open as a pdf as that's what it is.

If you copy from calc and do a pastespecial in a writer document then you can save as an odt. If that doesn't do what you want you could try copying the cell contents into a Writer texttable.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
sourav16
Posts: 5
Joined: Sat Dec 10, 2022 2:33 pm

Re: Exporting Spreadsheet files as .odt

Post by sourav16 »

Thank You Jeje for your reply. But is there anyway to directly export it to .odt format?
OpenOffice 4.1.10 on Windows 10
JeJe
Volunteer
Posts: 2786
Joined: Wed Mar 09, 2016 2:40 pm

Re: Exporting Spreadsheet files as .odt

Post by JeJe »

Quickly looking online there seem to be sites that offer to do it.

If you said what result you want or why maybe someone will be able to help you more - a spreadsheet is like a table not a passage of text.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Exporting Spreadsheet files as .odt

Post by John_Ha »

sourav16 wrote: Sat Dec 10, 2022 6:37 pm Thank You Jeje for your reply. But is there anyway to directly export it to .odt format?
No ...

... but you might be able to do it the other way round by pulling it in instead of pushing it out. Open a .odt file and import the spreadsheet either with copy/paste or as a DDE.

That being said, exporting to a PDF will maintain the visual look of the sheet and copying from the PDF to a .odt will maintain that look.

I'm pretty certain LO Writer permits you to import a PDF file - it may be just a single sheet.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply