引用 伊翱 在 2016/11/24 10:56:02 发言【内容省略】
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