|
如何在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為列印的函數,第一個參數是列印起始頁,第二個參數列印結束頁,第三個參數是列印的份數。
|
|
|