Using Excel Interop and getting the print dialog

I have the following code: [Thanks, Mike Rosenblum!]

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Excel; using System.Runtime.InteropServices;

namespace ConsoleApplication17 {cool 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);



}
    }




    }

What I'm trying to accomplish is that instead of printing my excel file right away, I need a print dialog so that I can select a specific printer if I want.
I am using 12.0.0.0.NET integration for Excel. Does anyone have any idea?

Thank you in advance

+3
source share
1

.NET Excel 2007 12.0 PIA. Dialog.Show() 30 . # 4.0 ( ), VB.NET , # 3.0 , Type.Missing . 30 :

bool userDidntCancel =
    excelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrint].Show(
        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, 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, Type.Missing, Type.Missing);

Show() 'true', , ; "false", , escape (esc), .

, ...

+8

Source: https://habr.com/ru/post/1708284/


All Articles