B4J Question .XLS? and .DOC? print to .PDF, Microsoft OLE

peacemaker

Expert
Licensed User
Longtime User
Hi, All

Is it possible now from B4J Java based app to use Microsoft Office automation ?
I need to automate the printing files to .PDF, now FreeOffice software helps to save any file to .PDF, but all is manually, with pre-formatting to A4 paper format.
Long-long ago i used MS VisualBasic 5.0 for a console app (with command line) that used:
B4X:
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\WINDOWS\system32\stdole2.tlb#OLE Automation
to open a file in Excel or Word and send to a printer.

Now the task is wider - select A4-paper, margins, choose a printer (PDF-printer) or export to PDF - when Adobe software is installed - such OLE integraton to MS Office is OK.
Any suggestion ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Seems, jPOI does not help to print at all ?
No. It has nothing to do with printing.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But how to send to printer .XLS sheet, or file ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Actually, SOLVED, and without app, just by VBscrpt:
B4X:
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.DisplayAlerts = False
inputFile = WScript.Arguments(0)
objExcel.Workbooks.Open inputFile

objExcel.ActiveSheet.PageSetup.PaperSize = 9    'A4
objExcel.ActiveSheet.PageSetup.Orientation = 1    'portrait
objExcel.ActiveSheet.PageSetup.Zoom = False
objExcel.ActiveSheet.PageSetup.FitToPagesWide = 1
objExcel.ActiveSheet.PageSetup.FitToPagesTall = 10
objExcel.ActiveSheet.PageSetup.LeftMargin = objExcel.CentimetersToPoints(2)
objExcel.ActiveSheet.PageSetup.RightMargin = objExcel.CentimetersToPoints(1)
objExcel.ActiveSheet.PageSetup.TopMargin = objExcel.CentimetersToPoints(1)
objExcel.ActiveSheet.PageSetup.BottomMargin = objExcel.CentimetersToPoints(1)
objExcel.ActiveSheet.PageSetup.CenterHorizontally = True

objExcel.ActiveSheet.PrintOut 1, 1000, 1, false, "Adobe PDF", false, false, , true

objExcel.Quit

Drag & drop .XLS file to this script helps to save .PDF file.
 
Upvote 0
Top