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

Free Support Forum - aspose.com

Too many pages printed

I am using Aspose.Cells to combine 6 spreadsheet into 1 spreadsheet with 6 tabs. If I try to print the resulting file immediately after opening it (without changing tabs first), the entire spreadsheet with all 6 tabs and 247 pages is printed even though the current tab only has 1 page.

If I switch tabs before printing, then it works normally (printing only the current tab).

I want it to behave like the Excel default (printing only the current tab when the file is first opened) - how can I fix this? I tried setting ActiveSheetIndex = 0 and I also tried setting the print area; neither of these seemed to help. I am using Aspose Cells

Here is my code showing how I combine the files and what I already tried - thank you in advance!

protected static void CombineReports(string folder, int projectProgramID, DateTime reportEndDate)


Workbook report = new Workbook();

string summaryPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.Summary);

string utilizationPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.Utilization);

string notUsingPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.NotUsing);

string booksPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.Books);

string financialsPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.Financials);

string orderDetailsPath = MonthlyLibraryReports.GetFilePath(folder, projectProgramID, reportEndDate, LibraryReportTab.OrderDetails);

Workbook financials = new Workbook();

Workbook summary = new Workbook();

Workbook utilization = new Workbook();

Workbook notUsing = new Workbook();

Workbook books = new Workbook();

Workbook orderDetails = new Workbook();







//combine all the tabs into one

financials.Worksheets[0].Name = "Financials";











financials.Worksheets[1].Name = summary.Worksheets[0].Name;

financials.Worksheets[2].Name = utilization.Worksheets[0].Name;

financials.Worksheets[3].Name = notUsing.Worksheets[0].Name;

financials.Worksheets[4].Name = books.Worksheets[0].Name;

financials.Worksheets[5].Name = orderDetails.Worksheets[0].Name;

financials.Worksheets.ActiveSheetIndex = 0;

//this didn't work

//financials.Worksheets[0].PageSetup.PrintArea = "A1:S52";

//financials.Worksheets[1].PageSetup.PrintArea = null;

//financials.Worksheets[2].PageSetup.PrintArea = null;

//financials.Worksheets[3].PageSetup.PrintArea = null;

//financials.Worksheets[4].PageSetup.PrintArea = null;

//financials.Worksheets[5].PageSetup.PrintArea = null;

//add some missing colors for the utilization report

//(overwriting primary colors that aren't in use at all)

financials.ChangePalette(System.Drawing.Color.Silver, 0);

financials.ChangePalette(System.Drawing.Color.LightGray, 2);

financials.ChangePalette(System.Drawing.Color.FromArgb(237, 243, 254), 3); //pale blue for alt.rows

financials.ChangePalette(System.Drawing.Color.DarkGray, 4);

//add grouping in the utilization report

string filePath = MonthlyLibraryReports.GetMasterReportFilePath(folder, projectProgramID, reportEndDate);

if (File.Exists(filePath)) File.Delete(filePath);

GroupUtilization(financials, 2);


//save the manager-only version

//remove Financials tab and delete Summary section of Summary tab


int summaryStartIndex = 3;

int numRows = 1;

while (financials.Worksheets[0].Cells[summaryStartIndex + numRows, 1].Value != null)


financials.Worksheets[0].Cells.DeleteRows(summaryStartIndex, numRows);

filePath = MonthlyLibraryReports.GetManagerReportFilePath(folder, projectProgramID, reportEndDate);

if (File.Exists(filePath)) File.Delete(filePath);




Do you use SheetRender.ToPrinter or Worksheet.SheetToPrinter (obsoleted now) method. Or you are manually printing the worksheet/file in MS Excel (by opening the generated file into it).

We appreciate kindly try our latest version, if it works fine:

If you still find the issue, kindly do post your sample file to be printed or preferably create a sample console demo application, zip it and post it here to reproduce the the issue with all the details. We will check it soon.

Thank you.

I downloaded the latest version and I am still having the same problem. To answer your previous quesiton on how we are opening the file; we our manually opening it via MS Excel. I can duplicate the problem by manually creating a multiple worksheet workbook, while holding down the ctrl key select every tab of the worksheet, then saving and closing the worksheet. When you open up the worksheet all the tabs our initially selected so if you try to print before clicking on one of the tab of the worksheet; then it will try and print the entire workbook not just the intial worksheet. I have attached an example report.

Thanks for your help.


Well, I think this is the behavior of MS Excel. If you manually (in MS Excel) select
every tab holding down the ctrl key, each worksheet would be selected, so each sheet would be printed.
Could you elaborate how did you create the file, did you use Aspose.Cells for .NET API to create such file and how did you make each tab selected in it. If you use Aspose.Cells API for it, could you create a console demo application to show the issue here, it will help us really to figure out your issue soon.

Thank you.

How the file is created is in the first post. Basically we create 5 workbooks

Workbook financials = new Workbook(financialsPath);

Workbook summary = new Workbook(summaryPath);

Set the first page of each workbook as the active sheet

financials.Worksheets.ActiveSheetIndex = 0;

summary.Worksheets.ActiveSheetIndex = 0;

Then use the combine method to add the 4 workbooks to the first workbook.

financials.Worksheets[0].Name = "Financials";



Then we name each worksheet:

financials.Worksheets[1].Name = summary.Worksheets[0].Name;

financials.Worksheets[2].Name = utilization.Worksheets[0].Name;

Make a few changes to the palette:

financials.ChangePalette(System.Drawing.Color.Silver, 0);

financials.ChangePalette(System.Drawing.Color.LightGray , 2);

We then check to see if the file exists (if so delete)

string filePath = MonthlyLibraryReports.GetMasterReportFilePath(folder, projectProgramID, reportEndDate);

if (File.Exists(filePath)) File.Delete(filePath);

we do some grouping in a subroutine

GroupUtilization(financials, 2);

Here is the subroutine:

protected static void GroupUtilization(Workbook wb, int utilizationIndex)


Cells cells = wb.Worksheets[utilizationIndex].Cells;

int startIndex = 5; //starting row for data

//group districts

for (int i = startIndex; i < cells.EndCellInColumn(1).Row; i++)


if (IsTerritoryRow(cells, i))


//make a district group

int districtGroupStartIndex = i;

do { i++; } while (IsTerritoryRow(cells, i));


int districtGroupEndIndex = i;

cells.GroupRows(districtGroupStartIndex, districtGroupEndIndex, false);



//group regions

int programGroupEndIndex = startIndex;

for (int i = startIndex + 1; i < cells.EndCellInColumn(1).Row; i++)


if (IsRegionBoundary(cells, i))



//make a region group

int regionGroupStartIndex = i;

do { i++; } while (!IsRegionBoundary(cells, i));


int regionGroupEndIndex = i;

cells.GroupRows(regionGroupStartIndex, regionGroupEndIndex, false);

programGroupEndIndex = regionGroupEndIndex; //for program grouping later



//group the program

if (programGroupEndIndex > startIndex + 1)

cells.GroupRows(startIndex + 1, programGroupEndIndex, false);

wb.Worksheets[utilizationIndex].Outline.SummaryRowBelow = false;


then we save the file: