Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Apr 02, 2025 10:34 am

I have a requirement to set the page margins of A4 size to 2.5cm on the left, 1.5cm on the right, and 2cm on the top and bottom. After setting the page margins, convert it to PDF or print it directly so that all four sides can fill the page according to the set page margins (non-proportional scaling, proportional scaling cannot satisfy the requirement that all four sides fill the page)

Code: Select all
 Workbook workbook = new Workbook();
 workbook.LoadFromFile(“111.xls”);
 Worksheet sheet = workbook.Worksheets[0];
 sheet.PageSetup.LeftMargin = 2.5*0.393700787;//Convert centimeters to inches
 sheet.PageSetup.RightMargin = 1.5*0.393700787;//Convert centimeters to inches
 sheet.PageSetup.TopMargin =2*0.393700787;//Convert centimeters to inches
 sheet.PageSetup.BottomMargin =2*0.393700787;//Convert centimeters to inches
sheet.PageSetup.IsFitToPage = true;
sheet.PageSetup.FitToPagesWide = 1;
sheet.PageSetup.FitToPagesTall = 1;
workbook.SaveToFile("222.pdf", FileFormat.PDF);
//workbook.PrintDocument.Print();

I am using .net, and the code above is what I tested, but it cannot meet my needs for now. Is there any other way to achieve full page margins on all four sides?

xiaoyu4649
 
Posts: 3
Joined: Sat Jan 18, 2025 12:02 pm

Thu Apr 03, 2025 9:32 am

Hello,

Thansk for your inquiry.
To help us investigate your issue further, could you please provide us with your test file and some screenshots showing what you are trying to achieve? You can attach them here or send them to this email [email protected]. Thanks in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 767
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.XLS