/// <summary> /// Releases all Excel Document COM Objects /// </summary> public void Dispose() { using (excelDoc) { excelDoc.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { ExcelStream.Dispose(); ExcelDoc.Dispose(); } ExcelStream = null; ExcelDoc = null; disposedValue = true; } }
/// <summary> /// Opens the specified filepath for reading /// </summary> /// <returns></returns> public void OpenExcelReader() { if (ExcelDoc != null) { ExcelDoc.Close(); ExcelDoc.Dispose(); } if (ExcelStream != null) { ExcelStream.Close(); ExcelStream.Dispose(); } ExcelStream = System.IO.File.Open(ExcelFilePath, FileMode.Open, FileAccess.Read); ExcelDoc = DocumentFormat.OpenXml.Packaging.SpreadsheetDocument.Open(ExcelStream, false); }
public void Create() { var doc = new ExcelDoc(); try { var i = 1; foreach (MileageReport item in _mileageReportList) { if (item.IsFailed) { doc.setValue(i, 1, item.ToString()); i++; } } doc.SetList(2); i = 1; foreach (MileageReport item in _mileageReportList) { if (!item.IsFailed) { doc.setValue(i, 1, item.ToString()); i++; } } doc.Show(); } catch { doc.Dispose(); } }