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 4.8.1.0.
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();
summary.Open(summaryPath);
utilization.Open(utilizationPath);
notUsing.Open(notUsingPath);
books.Open(booksPath);
financials.Open(financialsPath);
orderDetails.Open(orderDetailsPath);
//combine all the tabs into one
financials.Worksheets[0].Name = "Financials";
financials.Worksheets.Add();
financials.Worksheets.Add();
financials.Worksheets.Add();
financials.Worksheets.Add();
financials.Worksheets.Add();
financials.Worksheets[1].Copy(summary.Worksheets[0]);
financials.Worksheets[2].Copy(utilization.Worksheets[0]);
financials.Worksheets[3].Copy(notUsing.Worksheets[0]);
financials.Worksheets[4].Copy(books.Worksheets[0]);
financials.Worksheets[5].Copy(orderDetails.Worksheets[0]);
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);
financials.Save(filePath);
//save the manager-only version
//remove Financials tab and delete Summary section of Summary tab
financials.Worksheets.RemoveAt(0);
int summaryStartIndex = 3;
int numRows = 1;
while (financials.Worksheets[0].Cells[summaryStartIndex + numRows, 1].Value != null)
numRows++;
financials.Worksheets[0].Cells.DeleteRows(summaryStartIndex, numRows);
filePath = MonthlyLibraryReports.GetManagerReportFilePath(folder, projectProgramID, reportEndDate);
if (File.Exists(filePath)) File.Delete(filePath);
financials.Save(filePath);
}