예제 #1
0
 public ObjectsToXls(string saveTo)
 {
     xWorker = XLSWorker.Create(saveTo, true);
 }
예제 #2
0
        /// <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;
        }
예제 #3
0
 public ObjectsToXls()
 {
     xWorker = new XLSWorker();
 }
예제 #4
0
        /// <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;
        }