0

I try to load an excel file and show in xpsdocument viewer by following code

            XpsDocument xpsDocument = ef.ConvertToXpsDocument(SaveOptions.XpsDefault);

            documentViewer.Tag = xpsDocument;

            documentViewer.Document = xpsDocument.GetFixedDocumentSequence();

That works so far. The problem is that during the conversion the pagesize changes. It seems that a 8 by 11 inch pagesize is assumed and the document is streched. Excel document is designed for A4 papersize. That means the width grows and the last column moves to the next page.

How can I influence the paper size and border width for SaveOptions.XpsDefault??

user1230268
  • 221
  • 2
  • 14

1 Answers1

0

The A4 format is 8.267" x 11.692" so it seems that the assumption is right. Nevertheless, you can change the paper size like the following:

ExcelWorksheet ws = ef.Worksheets.ActiveWorksheet;
ws.PrintOptions.PaperType = PaperType.A4;

However, regarding the content being moved to next page, this will require investigating your Excel file's content.
But in case you're interested you can explicitly specify that the content's width (and/or height) should fit on a single page, like the following:

ws.PrintOptions.FitWorksheetWidthToPages = 1;

Last regarding the borders, you can specify the width by using LineStyle.

Mario Z
  • 4,328
  • 2
  • 24
  • 38
  • Thanks for your answer. But the excel File is completely ok and prints perfekt when sent to a printer. Only the conversion to xpsdoc causes the problem. I am in contact with gembox and got a bugfix that solves part of the problem. they told me the newest version is doing the job correctly. – user1230268 Nov 14 '16 at 20:10
  • 1
    with the newest version 4.1 the problem is resolved. It was just a bug in the 3.7 version – user1230268 Nov 15 '16 at 18:14