Example #1
0
        protected ExcelInterop saveAs(string fileName)
        {
            try{
                // Check, if output path exists. Create if not exists
                string dirName = Path.GetDirectoryName(fileName);
                if (!Directory.Exists(dirName))
                {
                    Directory.CreateDirectory(dirName);
                }

                // Save excel file
                this.wb.SaveAs(
                    fileName,
                    MsExcel.XlFileFormat.xlWorkbookDefault,
                    Type.Missing,
                    Type.Missing,
                    Type.Missing,
                    false,
                    MsExcel.XlSaveAsAccessMode.xlNoChange,
                    MsExcel.XlSaveConflictResolution.xlLocalSessionChanges,
                    Type.Missing,
                    Type.Missing
                    );
                return(this);
            } catch (COMException ex) {
                AppBase.addOutput("Nebylo možné uložit soubor " + fileName);
                throw new ExcelInteropException(ex.Message);
            }
        }
Example #2
0
 protected ExcelInterop load(string fileName)
 {
     try{
         this.wb = excel.Workbooks.Open(fileName);
         return(this);
     } catch (COMException ex) {
         AppBase.addOutput("Nebylo možné otevřít soubor " + fileName);
         throw new ExcelInteropException(ex.Message);
     }
 }
Example #3
0
        public ExcelInterop(string fileName = null)
        {
            if (ExcelInterop.excel == null)
            {
                try {
                    ExcelInterop.excel               = new MsExcel.Application();
                    ExcelInterop.excel.Visible       = false;
                    ExcelInterop.excel.DisplayAlerts = false;
                } catch (COMException ex) {
                    AppBase.addOutput("Nebylo možné otevřít aplikaci Excel");
                    throw new ExcelInteropException(ex.Message);
                }
            }

            if (fileName != null)
            {
                // Open Excel file
                this.load(fileName);
            }
        }