Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 137
  • Last Modified:

VB.Net Exporting Excel Woorkbook to PDF

I had this question after viewing How do I save an Excel spreadsheet to PDF using VB.net.

When i use the code from the solution of this above question it does what it should do with exception of the scaling of some of the pages in this doc. The first 3 or so are fine but the last 3 are maybe only 50% in size. not sure what i am missing here. Below is the simple version of code i am using to do this

Dim savePathPDF As String = "C:\Users\Documents\LSR.pdf"
        Dim saveAsFormat As Excel.XlFixedFormatType = Excel.XlFixedFormatType.xlTypePDF

        oBook.ExportAsFixedFormat(saveAsFormat, savePathPDF, Excel.XlFixedFormatQuality.xlQualityStandard, True, True, 1, , False, )

        oExcel.ActiveWorkbook.Close(SaveChanges:=False)
        oExcel.Quit()

Open in new window

0
AlexPonnath
Asked:
AlexPonnath
  • 4
  • 3
1 Solution
 
irudykCommented:
The sizing of the contents in each worksheet is set in its page setup. Sounds to me like those last 3 worksheets have the scaling limit in their respective page setup set to something other than 100% (i.e. 50%)

So, if you want all worksheets scaled at 100%, you'd have to loop through each worksheet in the workbook, set the scaling to 100% and the continue with saving the workbook as a PDF.
0
 
AlexPonnathAuthor Commented:
Any idea how to do that ? never had to deal with scaling. Or is there a way to set it in the actual workbook ?
0
 
AlexPonnathAuthor Commented:
I tried the below code but with no success, i enclosed the file in question which causes that problem

With oBook.Worksheets(4).PageSetup
            .Zoom = False
            .FitToPagesWide = 1
            .FitToPagesTall = 1
 End With

Also i just tried to save doc from Excel App itself and it does scale all pages fine
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
irudykCommented:
Hi,

I don't see the file attachment, but looking at your code, I'd suggest the following to loop through each worksheet in the workbook and set the scaling to 100%:

Dim oWorksheet As Excel.Worksheet
For Each oWorksheet In oBook.Worksheets
    oWorksheet.PageSetup.Zoom = 100
Next

Open in new window

0
 
AlexPonnathAuthor Commented:
Sorry, here is a copy of file in question.  I tried your code but that creates now an output which is to big for page which means a single page might use up 3 or 4 pages because there are some cells which no longer fit on page.
LSR.xls
0
 
irudykCommented:
I see.  Change the 2nd True statement to False

oBook.ExportAsFixedFormat(saveAsFormat, savePathPDF, Excel.XlFixedFormatQuality.xlQualityStandard, True, False, 1, , False)
0
 
AlexPonnathAuthor Commented:
That did the trick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now