try { object misValue = System.Reflection.Missing.Value; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Add(path); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlApp.DisplayAlerts = false; //Excel.Range excelCell = xlApp.get_Range("A1", "F10"); Excel.Range excelCell = (Excel.Range)xlWorkSheet.get_Range("A1", "F10"); excelCell.NumberFormat = "@"; //Excel.Ranges excelCell1 = xlApp.get_Range("H1", "O10"); Excel.Range excelCell1 = (Excel.Range)xlWorkSheet.get_Range("H1", "O10"); excelCell1.NumberFormat = "@"; //xlWorkBook.SaveAs(path, Excel.XlFileFormat.xlXMLSpreadsheet, misValue, misValue, //false, false, Excel.XlSaveAsAccessMode.xlExclusive,misValue, misValue, misValue, misValue, misValue); xlWorkBook.Save(); xlWorkBook.Close(false, false, misValue); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp); } catch (Exception ex) { System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet); MessageBox.Show(ex.Message); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)