我有以下代码:[感谢 Mike Rosenblum!]
使用 System; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 Microsoft.Office.Interop.Excel; 使用 System.Runtime.InteropServices;
命名空间 ConsoleApplication17 { 类 Program {
我想实现的是,不直接打印我的Excel文件,而是弹出一个打印对话框,以便我可以选择特定的打印机。
我正在使用Excel的12.0.0.0 .NET互操作性。 有人有什么想法吗?
提前致谢。
使用 System; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 Microsoft.Office.Interop.Excel; 使用 System.Runtime.InteropServices;
命名空间 ConsoleApplication17 { 类 Program {
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互操作性。 有人有什么想法吗?
提前致谢。
Excel.Workbook wb = excelApp.Workbooks.Open(@"C:\\Documents and Settings \\Admin \\Desktop \\DoCoMo\\ news5.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); Excel.Worksheet ws = (Excel.Worksheet)wb.Worksheets[1];
- M.Thillai