Comments on: Export or Save As PDF A Specific Range in LibreOffice Calc Sheets using Macro https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/ Linux and Dev Portal Fri, 29 Sep 2023 14:18:11 +0000 hourly 1 By: shaziya javed https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-4142 Fri, 29 Sep 2023 14:18:11 +0000 http://www.debugpoint.com/?p=1441#comment-4142 Hello Arindam,
I executed the above code. The PDF file created is not opening, it is showing of 0KB. Moreover it is not taking the sheet that i wanted. I had put the sheet number in place of sheet(0). but it is not taking that particular sheet name in PDF. Also cell number something else.

]]>
By: Sarwono https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-3441 Mon, 29 May 2023 02:49:47 +0000 http://www.debugpoint.com/?p=1441#comment-3441 In reply to Arindam.

thanks a lot for reply. i have tried, but still got error. do you please to make libreoffice calc macro codes, to print, export pdf, send to email or send to whatsapp? for example like this… because i have googling, but not found yet. or make student report. thanks

]]>
By: Arindam https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2664 Sat, 31 Dec 2022 17:43:43 +0000 http://www.debugpoint.com/?p=1441#comment-2664 In reply to sarwono.

Looks like your fileName is not being created correctly; probably have invalid character in file name.

Can you add the following statement in the line 63 and share a screenshot of the output.

msgbox fileName

]]>
By: sarwono https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2659 Sat, 31 Dec 2022 01:15:30 +0000 http://www.debugpoint.com/?p=1441#comment-2659 Hi arindam, thank your post, very useful for me. i just want to export PDF repeatly using your code on libreoffice calc, so i add For statement before “Filename…. and next statement before End sub, but i got error. how to fix it? I just want to exportPDF in many files in single click. thank for your kindness

]]>
By: Zoila Armstrong https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2455 Sat, 29 Oct 2022 20:01:20 +0000 http://www.debugpoint.com/?p=1441#comment-2455 

]]>
By: Arindam https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2335 Wed, 14 Sep 2022 17:20:44 +0000 http://www.debugpoint.com/?p=1441#comment-2335 In reply to Hernan.

This line is incorrect.

oCellRange = oSheet.getCellRangeByName(“$A$1:$CJ$63”)

You need to remove the dollar sign. Replace the above line with below and then try to run.

oCellRange = oSheet.getCellRangeByName(“A1:CJ63”)
]]>
By: Hernan https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2334 Wed, 14 Sep 2022 16:38:15 +0000 http://www.debugpoint.com/?p=1441#comment-2334 In reply to Arindam.

No with worksheet calc contents

This my macro,

Rem Attribute VBA_ModuleType=VBAModule
Rem Option VBASupport 1

Sub GUARDAR_DATOS()

‘ GUARDAR_DATOS Macro

    dim document as object
  dim dispatcher as object
  dim fileName
  fileName = ThisComponent.Sheets(0).Name & _
   “_Litoman1_” & ThisComponent.Sheets(0).getCellRangebyName(“B5”).String & _
   “_” & Replace(Date,”/”,”-“) & “.pdf”
  document = ThisComponent.CurrentController.Frame
  dispatcher = createUnoService(“com.sun.star.frame.DispatchHelper”)
  
  oSheet = ThisComponent.CurrentController.getActiveSheet()
  oCellRange = oSheet.getCellRangeByName(“$A$1:$CJ$63”)
  
  dim aFilterData(0) as new com.sun.star.beans.PropertyValue
  aFilterData(0).Name = “Selection”
  aFilterData(0).Value = oCellRange
 
  ‘ change the path below as per your needs
  path =”C:\Users\hcarrillo\Documents\” & fileName
  Open path For Append As #1
  Close #1
 
  dim args1(1) as new com.sun.star.beans.PropertyValue
  args1(0).Name = “URL”
  args1(0).Value = “C:\Users\hcarrillo\Documents\” & fileName ‘ change the path below as per your needs
  
  args1(1).Name = “FilterData”
  args1(1).Value = aFilterData()
 
  dispatcher.executeDispatch(document, “.uno:ExportDirectToPDF”, “”, 0, args1())
End Sub

And report

Error general de Entrada Salida

]]>
By: Hernan https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2333 Wed, 14 Sep 2022 16:28:54 +0000 http://www.debugpoint.com/?p=1441#comment-2333 In reply to Hernan.

Hi Arindam,

No sr, I want to create a PDF file with a contents range cells of sheet, but only create file empty, this macro must be running in windows machines.

Thanks

]]>
By: Arindam https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2329 Wed, 14 Sep 2022 04:07:46 +0000 http://www.debugpoint.com/?p=1441#comment-2329 In reply to Hernan.

You want to create a PDF with 0 bytes using macro?

]]>
By: Hernan https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-2328 Tue, 13 Sep 2022 22:38:20 +0000 http://www.debugpoint.com/?p=1441#comment-2328 Hi Arindam

Need a little help

I use this macro in Win10 but not write into file only create it with 0 bytes

Thanks,

]]>
By: Jacky https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-417 Fri, 28 Apr 2017 09:47:00 +0000 http://www.debugpoint.com/?p=1441#comment-417 Hi Arindam

First of all, the macro is very helpful, thanks!

Two quick questions

1) what is the propose of

path =”file:///home/arindam/” & fileName
Open path For Append As #1
Close #1

I can run the macro without the above statements

2) can we export the sheet content and append it to a PDF file (not overwrite it)
As I need a macro to export a sheet to a PDF, updated the sheet content and then export the updated sheet again to the same PDF as page 2.

Thanks.

Jacky

]]>
By: Arindam Giri https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-376 Thu, 03 Nov 2016 02:23:00 +0000 http://www.debugpoint.com/?p=1441#comment-376 In reply to Mono Roy.

The pdf would be generated with exactly what size of columns/rows you have in Calc. If you want to change the column width you can use below code. Place it somewhere before the pdf generation.

Sub col_chg()
oDoc = ThisComponent
oSheet = ThisComponent.getCurrentController.getActiveSheet
oColumn = oSheet.getColumns.getByIndex( 1 ) ‘ col B
oColumn.Width = 2.5 * 2540
End Sub

]]>
By: Mono Roy https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-373 Mon, 31 Oct 2016 05:25:00 +0000 http://www.debugpoint.com/?p=1441#comment-373 Hi Arindam –

Thanks much for this macro. Very helpful.

Now is there a way to set the margins for the PDF and also the cell width for each column I am printing.

I am printing 5 columns and I would like it take up all of the page at .5″ margins. I have specific sizes I have calculated for my coumns by placing them in a Writer doc by DDE so i know exactly how I want it to look.

I guess the other option is to just place it in a Writer doc and accordingly align margins as I am doing now.

Please let me know if you get a chance.

Thank you again.

This was very helpful.

Mono

]]>
By: Arindam Giri https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-265 Tue, 05 Apr 2016 17:21:00 +0000 http://www.debugpoint.com/?p=1441#comment-265 In reply to Punit Patpatia.

Great!

]]>
By: Punit Patpatia https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-264 Tue, 05 Apr 2016 06:53:00 +0000 http://www.debugpoint.com/?p=1441#comment-264 In reply to Punit Patpatia.

Never Mind, I found the error.

oObj2.IsLandscape = True
oObj2.Width = 29700
oObj2.Height = 21000

]]>
By: Punit Patpatia https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-263 Tue, 05 Apr 2016 06:09:00 +0000 http://www.debugpoint.com/?p=1441#comment-263 Thanks you very much for this wonderful post!
Just a quick question, How can I change the layout of PDF page to “Landscape” from “Portrait”?

]]>
By: Arindam Giri https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-248 Sun, 13 Mar 2016 01:14:00 +0000 http://www.debugpoint.com/?p=1441#comment-248 In reply to Marek Pluhař.

Try all of these to see if it works.
a) Make sure you have write permission to the folder where you are creating the file. The easiest way to do is to go to the path via explorer and create an empty text file and save.

b) Change below two lines in code where the path URI is present for the file as below. “test” is the sample folder name I have used.

path =”c:test” & fileName

args1(0).Value = “file:///c:/test/” & fileName

Try and let me know.

]]>
By: Marek Pluhař https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-247 Sat, 12 Mar 2016 16:52:00 +0000 http://www.debugpoint.com/?p=1441#comment-247 In reply to Arindam Giri.

Thank you for your answer, but program says: “Fault input/output”.

]]>
By: Arindam Giri https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-246 Sat, 12 Mar 2016 05:04:00 +0000 http://www.debugpoint.com/?p=1441#comment-246 In reply to Marek Pluhař.

This macro is specifically designed for LibreOffice Calc spreadsheet.

]]>
By: Arindam Giri https://www.debugpoint.com/export-or-save-as-pdf-a-specific-range-in-libreoffice-calc-sheets-using-macro/#comment-245 Sat, 12 Mar 2016 03:54:00 +0000 http://www.debugpoint.com/?p=1441#comment-245 In reply to Marek Pluhař.

I guess you are running LibreOffice under Windows. So try using the basic path system as below and see if it works:

path =”c:anyfolder” & fileName

]]>