public ObjectsToXls(string saveTo) { xWorker = XLSWorker.Create(saveTo, true); }
/// <summary> /// Open an Existing xls file for Reading and Modfification /// </summary> /// <param name="path"></param> /// <returns></returns> public static XLSWorker Open(string path) { if (!File.Exists(path)) { throw new FileNotFoundException("File Not Found", path); } var xWorker = new XLSWorker { WorkBookPath = path, WorkBook = new XLWorkbook(path) }; xWorker.WorkSheets = xWorker.WorkBook.Worksheets; xWorker.CurrentSheet = xWorker.WorkSheets.FirstOrDefault(); return xWorker; }
public ObjectsToXls() { xWorker = new XLSWorker(); }
/// <summary> /// Creates a new Excel Workbook - Overwrites Existing File /// </summary> /// <param name="path"></param> /// <returns></returns> public static XLSWorker Create(string path, bool overwrite) { if (File.Exists(path)) { if (overwrite) { File.Delete(path); } else { throw new Exception("File Already Exists : " + path); } } var xWorker = new XLSWorker() { WorkBookPath = path, WorkBook = new XLWorkbook() }; xWorker.WorkBook.Worksheets.Add("Sheet1"); xWorker.WorkSheets = xWorker.WorkBook.Worksheets; xWorker.CurrentSheet = xWorker.WorkSheets.FirstOrDefault(); return xWorker; }