/// <summary> /// Add a new sheet to the workbook that is being created /// </summary> /// <param name="sheetName">Name of the sheet</param> /// <param name="htmlString">HTML string to generate the the table from</param> /// <param name="settings">Settings for this sheet only.</param> /// <returns></returns> public WorkbookBuilder AddSheet(string sheetName, string htmlString, HtmlToExcelSettings settings = null) { IBrowsingContext context = BrowsingContext.New(Configuration.Default); IElement htmlDoc = context.OpenAsync(req => req.Content(htmlString)).Result.DocumentElement; IElement table = new AngleSharpUtilities().GetHtmlTableNode(htmlDoc); new ClosedXmlUtilities(settings ?? Settings).CreateWorksheet(Workbook, sheetName, table); return(this); }
public void GetHtmlTableNode_HtmlWithSingleTable_ShouldReturnTableHtmlNode() { string htmlWithTable = "<div><table><thead></thead><tbody></tbody></table></div>"; IBrowsingContext ctx = BrowsingContext.New(Configuration.Default.WithDefaultLoader()); var doc = ctx.OpenAsync(r => r.Content(htmlWithTable)).Result; IElement element = new AngleSharpUtilities().GetHtmlTableNode(doc.DocumentElement); Assert.IsTrue(element != null && element.NodeName.Equals("table", StringComparison.InvariantCultureIgnoreCase)); }
public void GetHtmlTableNode_HtmlWithNoTables_ShouldThrowException() { string htmlWithTable = "<div></div>"; IBrowsingContext ctx = BrowsingContext.New(Configuration.Default.WithDefaultLoader()); var doc = ctx.OpenAsync(r => r.Content(htmlWithTable)).Result; try { IElement element = new AngleSharpUtilities().GetHtmlTableNode(doc.DocumentElement); } catch (Exception ex) { StringAssert.Contains(ex.Message, AngleSharpUtilities.NoTableNodesFoundMessage); } }
/// <summary> /// /// </summary> /// <param name="htmlDoc"></param> /// <returns></returns> private byte[] ProcessDocument(IElement htmlDoc) { IElement table = new AngleSharpUtilities().GetHtmlTableNode(htmlDoc); return(new EPPlusUtilities(HtmlToExcelSettings).GenerateWorkbookFromHtmlNode(table)); }