Excel自动化:是否知道一张纸将打印多少页的任何方式?

问题描述

| 有时候,纸张太大而无法打印出来,因此,在这种情况下,我希望避免打印出来。 我当前的程序: 打开一个Excel文档 复制第一张纸 创建一个新文件 在新文档中插入文本和公式 显示文本时使列自动适应 打印文字(尚未实现) 显示公式时自动在列上拟合 打印公式(尚未实现) 复制/粘贴的原因是即使文档/表格/单元格受到密码写保护,也能够自动调整列。 但是,例如,如果当前工作表填充了100多页,我想避免打印它。我该如何检查?
        // Open Excel
        xlApp = new Excel.ApplicationClass();
        xlApp.Visible = true;

        // Open document
        xlWorkBook = xlApp.Workbooks.Open(filename,true,5,\"\",Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,\"\\t\",false,1,0);

        // Select the sheet we want to copy
        Excel.Sheets xlSheets = null;
        xlSheets = xlWorkBook.Sheets as Excel.Sheets;
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

        // Mark all cells and copy
        xlWorkSheet.UsedRange.Copy(misValue);

        // Make a new empty document
        Excel.Workbook xlWorkBook2;
        xlWorkBook2 = xlApp.Workbooks.Add(misValue);

        // Select the first sheet and insert
        Excel.Worksheet xlWorkSheet2;
        xlWorkSheet2 = (Excel.Worksheet)xlWorkBook2.Worksheets.get_Item(1);
        xlWorkSheet2.Name = \"temp\";

        // Just copies to range starting at cell A1
        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,misValue);

        // Adjust width of cells (autofit must be called on a column)
        xlWorkSheet2.Columns.AutoFit();

        // Show formulas
        xlWorkSheet2.Application.ActiveWindow.DisplayFormulas = true;
        xlWorkSheet2.Columns.AutoFit();

        xlWorkSheet2.PrintPreview(misValue);

        // Close Excel
        xlWorkBook2.Close(false,misValue);
        xlWorkBook.Close(false,misValue);
        xlApp.Quit();
    

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)