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).