以下是引用伊翱在2016/11/24 10:56:02的发言:
怎么实现 打印已有的excel表格? PrintOut? 各位有什么好方法吗?初学一脸懵 能说说具体的实现方法吗
using System;
using System.Drawing.Printing;
using System.Windows.Forms;
using Spire.Xls;
namespace Print_Excel_in_csharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.PageSetup.PrintArea = "A7:T8";
sheet.PageSetup.PrintTitleRows = "$1:$1";
sheet.PageSetup.FitToPagesWide = 1;
sheet.PageSetup.FitToPagesTall = 1;
//sheet.PageSetup.Orientation = PageOrientationType.Landscape;
//sheet.PageSetup.PaperSize = PaperSizeType.PaperA3;
PrintDialog dialog = new PrintDialog();
dialog.AllowPrintToFile = true;
dialog.AllowCurrentPage = true;
dialog.AllowSomePages = true;
dialog.AllowSelection = true;
dialog.UseEXDialog = true;
dialog.PrinterSettings.Duplex = Duplex.Simplex;
dialog.PrinterSettings.FromPage = 0;
dialog.PrinterSettings.ToPage = 8;
dialog.PrinterSettings.PrintRange = PrintRange.SomePages;
workbook.PrintDialog = dialog;
PrintDocument pd = workbook.PrintDocument;
if (dialog.ShowDialog() == DialogResult.OK)
{ pd.Print(); }
}
}
}
原文请阅读:
http://www.cnblogs.com/Yesi/p/5505756.html
[此贴子已经被作者于2016/11/24 12:20:36编辑过]