//public static DataTable FillSchema(this WorksheetPart @this, DataTable data) // => @this.Worksheet.FillSchema(data); //public static DataTable FillSchema(this Worksheet @this, DataTable data) //{ // foreach (Column col in @this.Descendants<Column>()) // data.Columns.Add(ExcelHelper.GetColumnLabel(data.Columns.Count), typeof(object)); // return data; //} /// <summary> /// Get SheetData from WorksheetPart. /// Create new SheetData if not exsisted. /// </summary> /// <param name="@this">WorksheetPart</param> /// <returns>SheetData</returns> public static SheetData GetOrCreateSheetData(this WorksheetPart @this) { var sheetData = @this.GetSheetData(); if (sheetData == null) { sheetData = new SheetData(); @this.Worksheet.Append(sheetData); } return(sheetData); }
public List <T> GetExcelData <T>() { string shtName = GetSheetForObject(typeof(T)); WorkbookPart wkb = _spreadsheetDoc.WorkbookPart; //Get a list of the sheets we want to import Sheet sheet = wkb.Workbook.Descendants <Sheet>().First(s => s.Name == shtName); WorksheetPart wks = (WorksheetPart)wkb.GetPartById(sheet.Id); Dictionary <string, string> columnsToRead = GetColumnsToRead(typeof(T)); List <T> shtData = wks.GetSheetData <T>(wkb, shtName, FirstDataRow, columnsToRead, UseFirstRowHeaders); if (IgnoreBlankRows) { RemoveBlankRows <T>(ref shtData, columnsToRead); } return(shtData); }