【问题标题】:Print excel (generated using Spreadsheetgear) in C#在 C# 中打印 excel(使用 Spreadsheetgear 生成)
【发布时间】:2014-11-05 14:13:30
【问题描述】:

在 c# 中,我正在生成特定格式的 excel,我必须在 click_print 上打印相同的 excel 格式。

P.s.-Microsoft Office 不可用,为此使用 SpreadSheetGear。

【问题讨论】:

  • GetExcel() - 以给定格式下载 excel,现在我必须在点击事件上编写一个新函数 PrintExcel(),我无法找出任何方法或任何函数来做到这一点。详细说明,例如:如果使用 Microsoft Office,我们有 sheet.Printout() 方法,那么 SpreadsheetGear 将如何完成

标签: c# excel printing spreadsheetgear


【解决方案1】:

如果您有 UI 并且正在使用 WorkbookView 控件,我建议您使用 Chuck 的答案。如果您在没有 UI 的情况下在代码中生成此工作簿,您还可以使用 WorkbookPrintDocument 类打印工作簿。下面是一个在控制台应用程序中演示这一点的示例:

using SpreadsheetGear;
using SpreadsheetGear.Printing;
using SpreadsheetGear.Drawing.Printing;

static void Main(string[] args)
{
    // Create a workbook with some cell data
    IWorkbook workbook = Factory.GetWorkbook();
    IWorksheet worksheet = workbook.ActiveWorksheet;
    IRange cells = worksheet.Cells;
    cells["A1:D10"].Value = "=RAND()";

    // Create a WorkbookPrintDocument.  
    WorkbookPrintDocument printDocument = new WorkbookPrintDocument(worksheet, PrintWhat.Sheet);

    // Set the printer if necessary...let's go old school.
    printDocument.PrinterSettings.PrinterName = "Epson MX-80";

    // Print it
    printDocument.Print();
}

如果您使用的是 SpreadsheetGear 2012 的 .NET 4.0 版本,则需要添加对 SpreadsheetGear2012.Drawing.dll 程序集的引用才能访问 SpreadsheetGear.Drawing.Printing 命名空间。

还请注意,我指定通过 PrintWhat.Sheet 打印(使用范围)工作表。有关更多选项,请参阅 SpreadsheetGear.Printing.PrintWhat 枚举。

【讨论】:

    【解决方案2】:

    Spreadsheetgear 对它们提供的对象有一个打印方法。

    http://www.spreadsheetgear.com/support/help/spreadsheetgear.net.3.0/SpreadsheetGear~SpreadsheetGear.Windows.Forms.WorkbookView~Print.html

    这应该让你开始。

    【讨论】:

      猜你喜欢
      • 2014-12-16
      • 2016-09-06
      • 2011-06-15
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2023-03-06
      • 2022-12-05
      • 2012-12-04
      相关资源
      最近更新 更多