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.

Fri Jan 17, 2014 12:00 pm

hi

i'm trying to set my printing area to fit all rows and columns that contain values, but ws.PageSetup.PrintArea only takes ranges in a string format aka "A1:E8". i don't want to write a helper method that converts ws.Range[1,1,ws.LastRow, ws.LastColumn] to a string range. is there a more convenient way to do this? i simply want to set the printing area to included all data on the sheet.

waldomirmarkgraf
 
Posts: 15
Joined: Mon Dec 06, 2010 12:14 pm

Mon Jan 20, 2014 3:41 am

Hello,

Thanks for your inquiry.
Please refer to the following method.
Code: Select all
string s = ws.Range[1,1,ws.LastRow, ws.LastColumn].RangeAddressLocal;
sheet.PageSetup.PrintArea = s;

If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Jan 24, 2014 9:15 am

Hello,

Have you tested the method? Does it fulfill your need? Could you please give us some feedback if convenience?

If there are any questions, welcome to get it back to us.

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Mon Jan 27, 2014 10:12 am

the code seems to work only that it doesn't do anything. the printing area stays the same. one cell before the last in the columns. even when setting the area manually, PrintArea doesn't seem to be doing anything.

waldomirmarkgraf
 
Posts: 15
Joined: Mon Dec 06, 2010 12:14 pm

Tue Jan 28, 2014 7:38 am

Hello,

Thanks for your feedback.
Sorry that we don't quite understand what you mean. I have tested the method with Spire.xls7.3, it works fine and it also set the PrintArea, please see the screenshot. The test file is in the attachment. Could you please provide us the following information if the issue persists?
1.Project can reproduce the issue
All code about this problem, a simple project which can reproduce this problem will be better.
2. Test Document or Test data

Code: Select all
 
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\EditSheetSample.xls");
Worksheet sheet = workbook.Worksheets[0];
string s = sheet.Range[1, 1, sheet.LastRow, sheet.LastColumn].RangeAddressLocal;
sheet.PageSetup.PrintArea = s;
workbook.SaveToFile(@"..\..\result.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(@"..\..\result.xls");

Sincerely,
Gary
E-iceblue support team
Attachments
EditSheetSample.zip
(3.96 KiB) Downloaded 335 times
AfterSetPrintArea.PNG
AfterSetPrintArea.PNG (26.9 KiB) Viewed 3601 times
BeforeSetPrintArea.PNG
BeforeSetPrintArea.PNG (26.37 KiB) Viewed 3601 times
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.XLS