0

I'm trying to open an excel file, and that it appears on the screen, but I can't manage to do it... Here is my code so far:

public class PPE_Process {
    public static void EditProcess() {
        PPE_ExcelFiles.Initialize("Excel.Application");

        OpenDataDlg = new OpenFileDialog(); 
        OpenDataDlg.Filter = "Cahier PPE|*.xlsx";

        if (OpenDataDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK && OpenDataDlg.FileName != "") {
            PPE_ExcelFiles.OpenPPE(OpenDataDlg);
        }
    }
}

public class PPE_ExcelFiles {

    public static Excel.Application excelApp;
    public static Excel.Workbook ppeWorkbook;

    public static void OpenPPE(OpenFileDialog opf) {
        ppeWorkbook = excelApp.Workbooks.Open(opf.FileName);
        ppeWorkbook.Open += new Excel.WorkbookEvents_OpenEventHandler(OpenWorkBook);
    }

    public static void Initialize(string labelAppli)
    {
        excelApp = (Excel.Application)System.Runtime.InteropServices.Marshal.GetActiveObject(labelAppli);
        excelApp.DisplayAlerts = false; 
    }

    private static void OpenWorkBook() {
        excelApp.WindowState = Excel.XlWindowState.xlMaximized;
    }
}

So, have I done something wrong, do I miss something, or is there no way to do it? And tell me if you need more details :)

(By the way, if you see something in my code that can be written in a better way, or I don't know, don't hesitate to tell me, I'm a pretty new coder)

Thank you for your time !

EDIT :

That's not a duplicate of " How to open an Excel file in C#? ", because in his case, he just wants to open the file, so that he can "work" on it with his code, and I've already done that. I want to do that this file appears on the screen, so that you can work on it manually (I don't know if that's clear, with my english).

1408786user
  • 1,868
  • 1
  • 21
  • 39
Sanimys
  • 101
  • 1
  • 10
  • @Chawin Thank you for replying, but sadly I have already seen this post, and that's not a duplicate. I said why in my "edit". – Sanimys Jul 17 '17 at 07:55
  • 2
    [Open excel file in new window (i.e. not an existing Excel instance)](https://stackoverflow.com/questions/20984352/open-excel-file-in-new-window-i-e-not-an-existing-excel-instance) – Chawin Jul 17 '17 at 07:59
  • @Chawin This time it works ! Thank you a lot ! :) – Sanimys Jul 17 '17 at 08:06

0 Answers0