I am working with a worksheet that has data which extends past the bounds of the page size. I have the need to detect the last column, and the first column contained within the bounds of the printed page.
On the sheet I am working with:
My page layout size is set to 8.5 x 11
My orientation is set to portrait.
My margins are set to normal.
Zoom is 100%
I did not, and do not want to set FitPagesToWide
Is there a way for me to detect which column at any given point in time is the last one to be within the bounds of the sheet dimensions?
For example:
If I were to print my sheet out using excel. I get columns A-G on one piece of paper and any content in H-J on another sheet.
Using the example above I would want to call a function like:
worksheet.uboundColumnForPage(pageNumber)
worksheet.lboundColumnForPage(pageNumber)
So execution of the following code:
string lastColumnOnPage1 = mySheet.uboundColumnForPage(1);
string firstColumnOnPage2 = mySheet.lboundColumnForPage(2);
string lastColumnOnPage2 = mySheet.uboundColumnForPage(2);
would produce following:
lastColumnOnPage1 = “G”;
firstColumnOnPage2 = “H”;
lastColumnOnPage2 = “J”;
Thank you for your timely response and possible solution suggestions.
Steven
Hi,
Thank you for considering Aspose.
Well you can get the last column by checking each column width. Please see the following sample code in this regard,
Sample Code:
private int uboundColumnForPage(Cells cells, int page, double pageWidthInch)
{
int lastColumn;
double count = 0;
for (int i = 0; i < 256; i++)
{
count += cells.GetColumnWidthInch(i);
if (Math.Abs(count - pageWidthInch) < double.Epsilon)
{
page--;
count = 0;
if (page == 0)
{
return lastColumn;
}
}
else if (count > pageWidthInch)
{
page--;
if (page == 0)
{
return lastColumn - 1;
}
count = cells.GetColumnWidthInch(i);
}
}
return 256;
}
Thank You & Best Regards,