/// <summary> /// Create a sheet with the specified name. If it already exists, delete it first. /// </summary> public static Worksheet CreateNewWorksheet(this Workbook wb, string name, bool visible = true) { // have to search through sheets first, as otherwise indexing throws an (uncatchable?) exception. foreach (var sheet in wb.Sheets.Cast<Worksheet>().Where(s => s.Name.Equals(name))) { sheet.DeleteWithoutWarning(); } Worksheet newSheet = wb.AddSheet(name); newSheet.Visible = visible ? XlSheetVisibility.xlSheetVisible : XlSheetVisibility.xlSheetHidden; return newSheet; }
public static void AddSheet(this ExcelPackage ep, IDataReader rd, string filename = "People.xlsx", bool useTable = false) { var dt = new DataTable(); dt.Load(rd); ep.AddSheet(dt, filename, useTable); }
/// <summary> /// Regenerates the sheet list in this drawing source. /// </summary> /// <param name="source"></param> /// <returns>True if sheets were regenerated. False otherwise</returns> public static bool RegenerateSheetList(this IDrawingSource source) { Check.NotNull(source, "source"); Check.NotNull(source.CurrentConnection, "source.CurrentConection"); //NOXLATE Check.NotEmpty(source.ResourceID, "source.ResourceID"); //NOXLATE IDrawingService dwSvc = (IDrawingService)source.CurrentConnection.GetService((int)ServiceType.Drawing); var sheets = dwSvc.EnumerateDrawingSections(source.ResourceID); bool bRegen = sheets.Section.Count > 0; source.RemoveAllSheets(); if (bRegen) { foreach (var sht in sheets.Section) { source.AddSheet(source.CreateSheet(sht.Name, 0, 0, 0, 0)); } } return bRegen; }