0

I'm new to C#/OpenXML and could not find an answer to this. Apologies in advance if it's a stupid question... Basically, I am writing an application that creates Excel files from an input string. This input string may contain information about multiple files that need to be created and opened in the print preview dialog simultaneously. However, using the following function, the code is suspended on the printpreview.show() method as it waits for the user to close the preview.

    public static void ExcelOpen(string fileName)
    {
        Excel.Application excelApp = new Excel.Application();
        excelApp.Visible = true;
        Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(fileName, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, false, 0, false, false);
        Excel.Worksheet ws = (Excel.Worksheet)excelWorkbook.Worksheets[1];
        excelApp.Dialogs[Excel.XlBuiltInDialog.xlDialogPrintPreview].Show();
        System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
        return;
    }

How can I avoid this and make sure the window stays opened in print preview but my program continues to run and create/display further files?

  • This looks like the excel interop, not OpenXml. Is that correct? – Broom Nov 26 '18 at 14:01
  • Yes, sorry for being unclear. OpenXml is used to write the file, and Interop to open it after saving. – Nick McGurk Nov 26 '18 at 14:02
  • Well, I just asked someone for an office installation so I can test out calling this method in a new thread. Might take a bit, but if no-one answers by then, I'll take a shot. – Broom Nov 26 '18 at 14:12

0 Answers0