/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> /// <param name="documentFilePath">Full path to the output file.</param> /// <param name="sheetName">Name of the Excel sheet where data is to be written to or read from.</param> /// <param name="replaceExistingFile">True to overwrite existing file with same name. Otherwise, set to false to modify contents of existing file.</param> public PFExcelDocument(enExcelOutputFormat excelOutputFormat, string documentFilePath, string sheetName, bool replaceExistingFile) { _excelOutputFormat = excelOutputFormat; _documentFilePath = documentFilePath; _sheetName = sheetName; _replaceExistingFile = replaceExistingFile; }
/// <summary> /// Writes data contained in ADO.NET DataTable object to path stored in OutputFileName property. /// </summary> /// <param name="dt">DataTable object containing data to be output.</param> /// <returns>True if output operation is successful. False if write fails.</returns> /// <remarks>Non Ext version of WriteDataToOutput will report an error if ReplaceExistingFile is false and file exists.</remarks> public bool WriteDataToOutput(DataTable dt) { bool success = true; try { if (File.Exists(_outputFileName)) { if (_replaceExistingFile) { File.SetAttributes(_outputFileName, FileAttributes.Normal); File.Delete(_outputFileName); } else { _msg.Length = 0; _msg.Append("File exists and ReplaceExistingFile set to False. Write to Output has failed."); throw new System.Exception(_msg.ToString()); } } enExcelOutputFormat outputFormat = enExcelOutputFormat.NotSpecified; switch (this.ExcelVersion) { case enExcelVersion.Excel2007: outputFormat = enExcelOutputFormat.Excel2007; break; case enExcelVersion.Excel2003: outputFormat = enExcelOutputFormat.Excel2003; break; case enExcelVersion.CSV: outputFormat = enExcelOutputFormat.CSV; break; default: outputFormat = enExcelOutputFormat.CSV; break; } PFExcelDocument excelDoc = new PFExcelDocument(outputFormat, this.OutputFileName, this.SheetName, this.ReplaceExistingFile); excelDoc.WriteDataToDocument(dt); } catch (System.Exception ex) { success = false; _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); throw new System.Exception(_msg.ToString()); } finally { ; } return(success); }
/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> /// <param name="documentFilePath">Full path to the output file.</param> /// <param name="sheetName">Name of the Excel sheet where data is to be written to or read from.</param> public PFExcelInterop(enExcelOutputFormat excelOutputFormat, string documentFilePath, string sheetName) { _excelOutputFormat = excelOutputFormat; _documentFilePath = documentFilePath; _sheetName = sheetName; }
/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> /// <param name="documentFilePath">Full path to the output file.</param> /// <param name="replaceExistingFile">True to overwrite existing file with same name. Otherwise, set to false to throw an error if file with same name already exists.</param> public PFExcelInterop(enExcelOutputFormat excelOutputFormat, string documentFilePath, bool replaceExistingFile) { _excelOutputFormat = excelOutputFormat; _documentFilePath = documentFilePath; _replaceExistingFile = replaceExistingFile; }
/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> /// <param name="documentFilePath">Full path to the output file.</param> public PFExcelInterop(enExcelOutputFormat excelOutputFormat, string documentFilePath) { _excelOutputFormat = excelOutputFormat; _documentFilePath = documentFilePath; }
/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> public PFExcelInterop(enExcelOutputFormat excelOutputFormat) { _excelOutputFormat = excelOutputFormat; }
/// <summary> /// Constructor. /// </summary> /// <param name="excelOutputFormat">Set to enExcelOutputFormat.Excel2003 for an XLS file. Set to enExcelOutputFormat.Excel2007 for an XLSX file.</param> public PFExcelDocument(enExcelOutputFormat excelOutputFormat) { _excelOutputFormat = excelOutputFormat; }