Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of Excel tables #42

Open
anton-voroshilin opened this issue Apr 8, 2024 · 3 comments
Open

Support of Excel tables #42

anton-voroshilin opened this issue Apr 8, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@anton-voroshilin
Copy link

Hi!
Are there any plans to support Excel tables?

By the way, thank you for your work. This library is great!

@salvois
Copy link
Owner

salvois commented Apr 20, 2024

Hi @anton-voroshilin ,
currently I have no plans for them to be honest, but I'm keeping your request as a reminder.
Thanks!
Salvo

@salvois salvois added the enhancement New feature or request label Apr 20, 2024
@nhamawi
Copy link

nhamawi commented Nov 19, 2024

I have implemented support for excel tables and would love to contribute my solution for review if I can be added as a contributor. I'm just waiting on my company for permission to safely contribute code from our personal accounts which I hope will be within a week or two. Here are the highlights:

Tables

Tables provide a way to ensure data rows remain intact, can be easily inserted or deleted as single entities (avoids misaligned data due to row/column shifting), and support alternating style patterns (i.e., "banded" rows) that don't change with inserted/deleeted rows. Furthermore, tables include persistent headers allowing you to easily sort and filter your data without having to navigate to the top of the table. Finally, tables can be used as named ranges and can auto-expend/contract when rows are added/removed. Some features that are not yet supported are:

  • Calculated columns
  • Totals row
  • Custom table styles (must use default styles)

Since version TBD, call BeginTable on an XlsxWriter when you want to define the beginning of a table (the upper-left cell) immediately before writing the first cell of that table. Ensure you are already on the same row and column where your table starts. If you are starting at the beginning of your worksheet, you must call BeginRow() to initialize the current row and column to A1. Call EndTable to mark the end of the table immediately after writing the final cell on the last row. Optionally, you can apply a pre-defined table style by name.

public XlsxWriter BeginTable(string tableName, IEnumerable<string> headers, string tableStyle = default)

BeginTable requires a table name and a list of table column headers (not to be confused with page headers and footers). These headers must appear on the first row of your data with exactly the same names. For example:

IEnumerable<string> headers = ["one", "two", "three"];
xlsxWriter.BeginRow().BeginTable("MyTable", headers, "TableStyleMedium2");
headers.ForEach(header => xlsxWriter.Write(header));
//...write cells as usual
xlsxWriter.EndTable()

@salvois
Copy link
Owner

salvois commented Nov 24, 2024

Thanks @nhamawi, I'll be more than happy to review your pull request when your contribution is green-lit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants