Several times, the sheets are too large to be printed, so I would like to avoid printing if that is the case.
My current program:
- Opens an excel document
- Copies the first sheet
- Creates a new document
- Paste text and formulas into a new document
- Automatically validates columns when displaying text
- Print text (not yet implemented)
- Makes columns auto-validate when displaying formulas
- Print Formulas (not yet implemented)
The reason for copying / pasting is the ability to automatically prepare columns, even if the document / sheet / cell is password protected.
But I would like to avoid printing it if, for example, the current sheet fills more than 100 pages. How can I check this?
xlApp = new Excel.ApplicationClass();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Open(filename, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Excel.Sheets xlSheets = null;
xlSheets = xlWorkBook.Sheets as Excel.Sheets;
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.UsedRange.Copy(misValue);
Excel.Workbook xlWorkBook2;
xlWorkBook2 = xlApp.Workbooks.Add(misValue);
Excel.Worksheet xlWorkSheet2;
xlWorkSheet2 = (Excel.Worksheet)xlWorkBook2.Worksheets.get_Item(1);
xlWorkSheet2.Name = "temp";
Excel.Range range = (Excel.Range)((Excel.Worksheet)xlWorkSheet2).Cells[1, 1];
range.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteValues, Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, misValue, misValue);
range.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteFormulas, Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, misValue, misValue);
xlWorkSheet2.Columns.AutoFit();
xlWorkSheet2.Application.ActiveWindow.DisplayFormulas = true;
xlWorkSheet2.Columns.AutoFit();
xlWorkSheet2.PrintPreview(misValue);
xlWorkBook2.Close(false, false, misValue);
xlWorkBook.Close(false, false, misValue);
xlApp.Quit();