{"id":22320301,"url":"https://github.com/struttower/htmltoexcel","last_synced_at":"2025-07-29T13:32:10.696Z","repository":{"id":65432510,"uuid":"188577847","full_name":"StrutTower/HtmlToExcel","owner":"StrutTower","description":"Uses ClosedXML and AngleSharp to convert an HTML table to an Excel file","archived":false,"fork":false,"pushed_at":"2024-12-04T19:37:47.000Z","size":96,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-03T13:55:58.269Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StrutTower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-05-25T14:45:20.000Z","updated_at":"2025-06-12T16:10:53.000Z","dependencies_parsed_at":"2024-03-14T16:43:29.063Z","dependency_job_id":"f88b005a-4812-4094-976d-4ea3878922d3","html_url":"https://github.com/StrutTower/HtmlToExcel","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/StrutTower/HtmlToExcel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrutTower%2FHtmlToExcel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrutTower%2FHtmlToExcel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrutTower%2FHtmlToExcel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrutTower%2FHtmlToExcel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StrutTower","download_url":"https://codeload.github.com/StrutTower/HtmlToExcel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StrutTower%2FHtmlToExcel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267694877,"owners_count":24129149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T00:13:11.557Z","updated_at":"2025-07-29T13:32:10.447Z","avatar_url":"https://github.com/StrutTower.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TowerSoft HtmlToExcel\n\nSmall Nuget package that uses AngleSharp to read an HTML table and generate an Excel file using ClosedXML\n\n### Usage\n\nSingle sheet\n```csharp\nstring htmlString = \"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003eCell contents\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\";\n\nbyte[] fileData = new WorkbookGenerator().FromHtmlString(htmlString);\n```\n\nMultiple sheets\n```csharp\nstring htmlString1 = \"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003eCell contents\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\";\nstring htmlString2 = \"\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003eCell contents\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\";\n\nbyte[] fileData;\nusing (WorkbookBuilder workbookBuilder = new WorkbookBuilder()) {\n    workbookBuilder.AddSheet(\"sheet1\", htmlString1);\n    workbookBuilder.AddSheet(\"sheet2\", htmlString2);\n\n    fileData = workbookBuilder.GetAsByteArray();\n}\n```\n\n### Settings\n\nSome settings do not work if there are any colspans in the table.\nThis is because Excel does not allow tables with merged cells and those settings only work in tables.\n\n| Setting Name | Default Value | Description                                                                            |\n|--------------|---------------|----------------------------------------------------------------------------------------|\n| AutofitColumns | true          | Enables/disables fitting the width of the columns to fit the contents.                 |\n| ShowFilter | true          | Enables/disables showing table filters. Does not work with the table has any colspans. |\n| ShowRowStripes | true          | Enables/disables row stripes. Does not work with the table has any colspans.           |\n| PrintingPageOrientationPortrait | true          | Sets the printing page default orientation to Portrait (Landscape if false)            |\n| ShowGridLines | false         | Enables/disables grid lines                                                            |\n\nYou can change the settings using `HtmlToExcellSettings`\nand passing it in the constructor of `htmlToEzxel`\n\n```csharp\nHtmlToExcelSettings settings = HtmlToExcelSettings.Defaults;\nsettings.AutofitColumns = false;\nsettings.ShowFilter = false;\nsettings.ShowRowStripes = false;\n\n// Using custom settings with a single sheet\nbyte[] fileData new WorkbookGenerator(settings).FromHtmlString(htmlString);\n\n// Using custom settings with multiple sheets\nusing (WorkbookBuilder workbookBuilder = new WorkbookBuilder(settings) {\n    // Settings can also be used in the AddSheet method which overrides the setting on the WorkbookBuilder\n    workbookBuilder.AddSheet(\"sheetName\", htmlString, settings)\n}\n```\n\n#### Individual Cell Options\n\n\n| Attribute Name | Expected Data Type | Comments                                                                                                                          |\n|----------------|--------------------|-----------------------------------------------------------------------------------------------------------------------------------|\n| data-excel-hyperlink | URI | Creates a hyperlink on the cell. Must be a parsable absolute URI.                                                                 |\n| data-excel-bold | Boolean | Sets if the cell style will be set to bold.                                                                                       |\n| data-wrap | Boolean | Sets if the cell text is wrapped.                                                                                                 |\n| data-type | String | Sets the data type for the cell. Valid options are: Text, Number, Boolean, DateTime, TimeSpan                                     |\n| data-format | String | Sets the cell format. Only works with data-type=\"Number\" and data-type=\"DateTime\"                                                 |\n| data-excel-comment | String | Adds a comment to the cell                                                                                                        |\n| data-excel-comment-author | String | Sets the author for the comment                                                                                                   |\n| data-horizontal-alignment | String | Sets the cell horizontal alignment. Valid options are: Center, CenterContinuous, Distributed, Fill, General, Justify, Left, Right |\n| colspan | Integer | Merges this cell with the following cells                                                                                         |\n| data-font-size | Integer | Sets the cell font size                                                                                                           |\n| data-font-color | String(HexColor) | Sets the font color of the cell. Must be a valid hex color code, Example: #006688                                                 |\n| data-background-color | String(HexColor) | Sets the fill/background color of the cell. Must be a valid hex color code, Example: #006688                                      |\n\n\n#### ASP Core Example\nAdd the following code to your project to render a view to a string:\n[CustomController.cs](https://gist.github.com/StrutTower/da303d31f2c930cb5a34af7a0968a0d3)\n\nUse this example to return the file to the client. Make sure you change the inherited class to your custom controller class.\n\n```csharp\npublic class HomeController : CustomController {\n    public IActionResult ExcelFile() {\n        var model = //Get model data\n\n        string htmlString = RenderViewAsync(\"viewName\", model, true);\n        byte[] fileData = new WorkbookGenerator().FromHtmlString(htmlString);\n\n        return File(fileData, MimeType.xlsx, \"filename.xlsx\");\n    }\n}\n```\n\n\n#### MVC 5 Example\nAdd the following code to your project to render a view to a string:\n[ViewExtensions.cs](https://gist.github.com/StrutTower/d5aa7677f5bb22fb5a5c28c0faab885c)\n\n```csharp\npublic ActionResult GetExcelFile() {\n    var model = //Get model data\n\n    string htmlString = PartialView(\"ViewName\", model).RenderToString();\n    byte[] fileData = new WorkbookGenerator().FromHtmlString(htmlString);\n\n    return File(fileData, MimeType.xlsx, \"filename.xlsx\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstruttower%2Fhtmltoexcel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstruttower%2Fhtmltoexcel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstruttower%2Fhtmltoexcel/lists"}