示例#1
0
        /// <summary>
        /// [扩展方法]根据名称获取指定sheetdata对象
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        public static SheetData GetSheetData(this SpreadsheetDocument document, string sheetName)
        {
            //获取指定Worksheet
            var sheet = document.GetWorksheet(sheetName);

            if (sheet == null)
            {
                throw new NullSheetException("请确认WorkSheet对象是否为null!");
            }

            return(sheet.GetFirstChild <SheetData>());
        }
示例#2
0
 public ExcelHelper(string fileName, bool editable = true, int header = 1)
 {
     if (string.IsNullOrEmpty(fileName))
     {
         throw new Exception("Check if current filename is empty!");
     }
     if (!File.Exists(fileName))
     {
         throw new Exception("Please make sure current file exists!");
     }
     document              = SpreadsheetDocument.Open(fileName, editable);
     worksheet             = document.GetWorksheet(0);
     sheetData             = worksheet.GetSheetData();
     styleSheet            = document.GetStylesheet();
     this.Header           = header;
     this.cellFormatOption = CellFormatOption.OverWrite;
 }
示例#3
0
 public void SetActiveSheet(int index)
 {
     this.Save();
     this.worksheet = document.GetWorksheet(index);
     this.sheetData = worksheet.GetSheetData();
 }
示例#4
0
 /// <summary>
 /// 获取第一个SheetData
 /// </summary>
 /// <param name="document">SpreadsheetDocument对象</param>
 /// <param name="sheetName">sheetName可为空</param>
 /// <returns>SheetData对象</returns>
 public static SheetData GetFirstSheetData(this SpreadsheetDocument document, string sheetName = null)
 {
     return(document.GetWorksheet(sheetName).GetFirstChild <SheetData>());
 }