Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Export Excel Workbook to .PDF
Message
From
14/01/2018 14:17:33
 
 
To
14/01/2018 03:12:31
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
01657177
Message ID:
01657194
Views:
62
>>
>>
>>            string xlsfilename = ConfigurationManager.AppSettings["XLSFilesPath"] + "ps20180113.xls";
>>            string pdffilename = ConfigurationManager.AppSettings["PDFFilesPath"] + "testps20180113.pdf";
>>
>>            Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
>>            Microsoft.Office.Interop.Excel.Workbook wbv = excel.Workbooks.Open(xlsfilename);
>>            Microsoft.Office.Interop.Excel.Worksheet wx = excel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet;
>>            if (File.Exists(pdffilename))
>>            {
>>                File.Delete(pdffilename);
>>            }
>>
>>            wbv.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, pdffilename);
>>
>>       
>>            wbv.Close(true, Type.Missing, Type.Missing);
>>            excel.Quit();
>>
>>
>>The above C# code creates a .pdf from an Excel Worksheet
>>I can't find the equivalent code to do it with VFP
>
>Assuming you can use automation, you don't need no friggin interop - the ugly kludge of a word was meant to bridge the gap between dot-nyet stuff (i.e. c#) and other stuff (i.e. office, which is still not rewritten in dot net, after 17 years)
>So something like
>
oEx=createobject("excel.application")
>oWb=oEx.Workbooks.Open(xlsfilename)
>oSh=oEx.ActiveSheet
>if File(pdffilename)
>              erase (pdffilename)
>endif
>oSh.ExportAsFixedFormat(oEx.XlFixedFormatType.xlTypePDF, pdffilename)
>OWb.Close(0)
>oEx.quit()
>As for the special locations... I assume you have your own locations, or can find how to extract them from Excel or wherever they are defined.

That did it, Dragan

I couldn't find the constant definitions, so I guessed and found- 0 = pdf, 1 = xps.

Here's and interesting tidbit.
I used to create the pdf for this report by using xfrx with a report that I printed with an .frx.
To meet user requirements I had to make a lot of changes that made me looking at creating a spreasheet for the report and then exporting to a pdf.
The coding time for a speadsheet is a lot longer than using an .frx but the total runtime is lower now.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Reply
Map
View

Click here to load this message in the networking platform