/// <summary>
 /// Releases all Excel Document COM Objects
 /// </summary>
 public void Dispose()
 {
     using (excelDoc)
     {
         excelDoc.Dispose();
     }
 }
示例#2
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    ExcelStream.Dispose();
                    ExcelDoc.Dispose();
                }

                ExcelStream   = null;
                ExcelDoc      = null;
                disposedValue = true;
            }
        }
示例#3
0
        /// <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);
        }
示例#4
0
        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();
            }
        }