|
使用ExcelPlate,如何不要透過Excel即可直接印表? |
|
|
可以在ExcelPlate的AfterOutput事件中加入印表的程式,如下: using System.Reflection; using System.Runtime.InteropServices; private void excelPlate1_AfterOutput(object sender, EventArgs e) { Excel.Application objExcel = new Excel.Application(); objExcel.Visible= false; Excel.Workbook objWorkBook = objExcel.Workbooks.Open(excelPlate1.FilePath, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); try { objWorkBook.PrintOut(1, 1, 1, false, Missing.Value, Missing.Value, Missing.Value, Missing.Value); } finally { objExcel.Quit(); Marshal.ReleaseComObject(objExcel); Marshal.ReleaseComObject(objWorkBook); objExcel = null; objWorkBook = null; GC.Collect(); } } PrintOut為打印的函數,第一個參數是打印起始頁,第二個參數打印結束頁,第三個參數是打印的份數
|
|
|