【发布时间】:2010-10-25 23:49:06
【问题描述】:
我有以下代码:[谢谢 Mike Rosenblum!]
使用系统; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 Microsoft.Office.Interop.Excel; 使用 System.Runtime.InteropServices;
命名空间 ConsoleApplication17 { 课堂节目 {
static void Main(string[] args) {
//public void PrintMyExcelFile()
//{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
// Open the Workbook:
Microsoft.Office.Interop.Excel.Workbook wb = excelApp.Workbooks.Open(
@"C:\hello.xls",
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing,Type.Missing,Type.Missing);
// Get the first worksheet.
// (Excel uses base 1 indexing, not base 0.)
Microsoft.Office.Interop.Excel.Worksheet ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
// Print out 1 copy to the default printer:
ws.PrintOut(
Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// Cleanup:
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(ws);
wb.Close(false, Type.Missing, Type.Missing);
Marshal.FinalReleaseComObject(wb);
excelApp.Quit();
Marshal.FinalReleaseComObject(excelApp);
}
}
}
我想要完成的是,我希望出现一个打印对话框,以便我可以选择特定的打印机,而不是立即打印我的 excel 文件。
我正在为 Excel 使用 12.0.0.0 .NET 互操作。
有人有什么想法吗?
提前致谢
【问题讨论】: