We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Loaded Excel document Worksheet PageSetup PaperSize is incorrect

We’re finding Excel documents with worksheets that when viewed in Microsoft Excel the Page Layout -> Size is set as A4. However when loading these documents using Aspose Cells the…

workbook.Worksheets[i].PageSetup.PaperSize

…is PaperLetter, when it should be PaperA4. When saved to PDF using Aspose Cells…

workbook.Save(tmpPDFStream, Aspose.Cells.SaveFormat.Pdf)

…the resulting PDF page sizes are Letter and not A4. When saving using Microsoft Excel the page sizes in the PDF generated are A4… not Letter consequently they look different.

@support-1,
Please share your sample file, output file and code snippet with us for our testing. We will reproduce the problem and provide our feedback after analysis.

To create the following Excel document, I simply created a new document and added a couple of worksheets. When I inspect the page size in Excel it says A4…

PageTypeTest.zip (6.8 KB)

It fails the following test as the papersize in Aspose is PaperLetter not PaperA4…

    [TestMethod]
    public void TestAsposeCells()
    {
        using(FileStream fs = new FileStream(@"E:\Temp\Test.xlsx", FileMode.Open, FileAccess.ReadWrite))
        {
            Workbook workbook = new Workbook(fs);
            Assert.AreEqual(workbook.Worksheets[1].PageSetup.PaperSize, PaperSizeType.PaperA4);
            Assert.AreEqual(workbook.Worksheets[0].PageSetup.PaperSize, PaperSizeType.PaperA4);
        }
    }

I have actually noted that after selecting an orientation or a paper size in Excel, the paper size when loaded into Aspose is correct. E.g. in the following document on the 2nd sheet I set the orientation to landscape then back to portrait then saved, it passes the first test above but not the 2nd

PageTypeTestFixed.zip (7.8 KB)

When I look at the page sizes in Excel both sheets are A4 however when loaded with Aspose sheet 1 is A4 and sheet 0 is Letter

@support-1,
We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-47259 - Worksheet PageSetup PaperSize is incorrect

@support-1,

We evaluated your issue further and found it is not an issue with Aspose.Cells APIs.
Please note, the papersize is automatically assigned and it’s from the default printer of your machine.
Please set the default paper size with the following code as we cannot directly access the default printer for permission.
e.g
Sample code:

.......
Workbook workbook = new Workbook(fs);
workbook.Settings.PaperSize = PaperSizeType.PaperA4;

It seems very odd that Excel and Aspose are unable to have the same logic to determine the default paper size. When I look at the devices and printers on my machine there is no default printer set. When I attempt to set one it gives me the message “Setting this printer as default means Windows will stop managing your default printer.”

In any case hard coding the PaperSize to A4 isn’t an option for us. We would rather the user specify the paper size in Excel than hard code the paper size to A4.

I would suggest Aspose should have a paper size as unknown when no paper size has been set in the excel document, that would at least allow us to do…

if (workbook.Worksheets[1].PageSetup.PaperSize == PaperSizeType.Unknown)
workbook.Worksheets[1].PageSetup.PaperSize = PaperSizeType.PaperA4;

Thereby allowing users of our system to choose a PaperSize for the document if they want to.

@support-1,
Thank you for your comments. We are analyzing this information and will write back soon to share our feedback.

@support-1,

Please use PageSetup.IsAutomaticPaperSize property to check whether the paper size is automatic for your needs.