/// <summary> /// Метод для чтения файла и получения результата /// </summary> /// <param name="filePath">Путь к файлу</param> /// <returns>Результат чтения</returns> public static ReadFileResult GetResult(string filePath) { try { using (FileStream openFileStream = new FileStream(path: filePath, mode: FileMode.Open, access: FileAccess.Read)) { IFileReader reader; if (filePath.EndsWith(".xls") || filePath.EndsWith(".xlsx")) { reader = new XLSFileReader(openFileStream); } else { reader = new CSVFileReader(); } return(reader.GetReadingResult()); } } catch (Exception e) { return(new ReadFileResult(errorMessage: e.Message)); } }
///<summary> ///Loads the existing XLS file (optionally preserving MS Excel records). ///</summary> ///<remarks> ///<p>If the only purpose of loading the file is to read data values and formatting using ///ExcelLite API, you should use <i>xlsOptions</i> set to <see cref="MB.WinEIDrive.Excel.XlsOptions.None">XlsOptions.None</see> ///as this will speed up the loading process.</p> ///<p>If you load the existing file to use it as template for a new file, you can choose ///whether you want to preserve specific MS Excel records not recognized by ExcelLite API.</p> ///</remarks> ///<param name="fileName">Existing XLS file name (opened for reading).</param> ///<param name="xlsOptions">XLS options.</param> public void LoadXls(string fileName, XlsOptions xlsOptions) { this.Reset(); AbsXLSRecords records1 = ExcelFile.ReadHelper(fileName, (xlsOptions & XlsOptions.PreserveSummaries) != XlsOptions.None, ref this.summaryStream, ref this.documentSummaryStream); XLSFileReader reader1 = new XLSFileReader(this, xlsOptions); reader1.ImportRecords(records1, fileName); }