예제 #1
0
 private void CloseExcelFile_Func()// Release the file for use without closing the application
 {
     if (ExcelApp != null)
     {
         if (ExcelApp.IsOpen)
         {
             ExcelApp.Terminate();
             LoadedFileText = "Aucun fichier chargé";// Restoring default value
             OnPropertyChanged("LoadedFileText");
         }
     }
 }
예제 #2
0
        private void OpenExcelFile_Func()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();   // Instanciates the class

            openFileDialog.Filter = "Tableau Excel |*.xlsx;*.xlsm"; // Adds a filter for Excel files only
            if (openFileDialog.ShowDialog() == DialogResult.OK)     // Enters the IF if the user selected a file and clicked OK
            {
                if (ExcelApp != null)
                {
                    if (ExcelApp.IsOpen)
                    {
                        ExcelApp.Terminate();// Automatically releases the previous file when the user loads a new one without releasing first.
                    }
                }
                ExcelApp       = new ExcelApp(openFileDialog.FileName);             // Initating my Excel object and passing the Excel file to open
                LoadedFileText = "Fichier chargé : " + openFileDialog.SafeFileName; //Displays the proper filename instead of the entire path for the UI
                OnPropertyChanged("LoadedFileText");                                // Updating the view
                // Couldn't find a way to select the button to re-enable it. Going to check if document is loaded directly inside the next function.
            }
        }