-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Initial implementation of Excel's tables feature #2671
Conversation
Initial implementation of Excel's tables feature (i.e. Select Home > Format as Table in Excel App). Tables are similar to AutoFilter but tables have other advantages like named ranges, easy formatting, totals row and header row with filter. Tables can also be converted to charts and pivot tables easily. Usage: $table = new Table(); $table->setName('Sales_Data'); $table->setRange('A1:D17'); $spreadsheet->getActiveSheet()->addTable($table); In this Commit: - Added Table API with initial support for header and totals row. - Added complete styling options for Table. - Added Xlsx Writer for Table. - Added samples. - Covered with unit tests. To be done: - Filter expressions similar to AutoFilter. - Precalucate formulas for totals row (Check sample 2). - Table named ranges in formulas and calculation.
Sorry that it's taken me a while to look at this. Looking at the PR, I have a couple of questions:
|
And I already know that structured references are going to be a real pain in the Calculation Engine. I notice that you're explicitly setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a few comments, just to ensure that you're considering those factors
|
The ReferenceHelper should have the example of AutoFilters to provide you with an example; because deleting rows in a Table area is straightforward (especially as column style and calculated columns are for a future stage), but if columns are deleted you have to check remove those entries and adjust offsets. Hopefully it won't be too difficult. |
If you can reach the point where formulae can be applied and written; I'll try to work out how to process structured references in the Calculation engine... until then, I think it's easiest if the |
Thank you for the PR and the work that you're doing. This is probably the single most requested new feature for PhpSpreadsheet; and it's one that I've attempted (and failed) To implement twice in the past. Custom column formatting (if the style wasn't used elsewhere in the worksheet) was my biggest problem, because the Writer wasn't writing it... hopefully, if you're aware of that pitfall, you'll be able to avoid it. |
Validation added for - invalid characters - invalid names ("C", "c", "R", or "r") - cell references - space separate words - maxlength of 255 characters - unique table names across worksheet
Option to remove the table from table collection of worksheet
Automatically adjusts table range on insertion and deletion of rows and columns within table range
Option to add column formula that applied automatically for any new rows added to the table range
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made a few more comments here. Some of these issues might seem to be nit-picking; but this is very close to being ready now
Added support for UTF-8 Table names (including combined character)
testColumnInRange method renamed to isColumnInRange
Range must be at least 1 column and 2 rows
Replaced worksheet argument with table name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the one more change that I've noted;
You're well ahead of my work on Structured References in the Calculation Engine: I've started that, and have made some progress; but am having "fun" with the capturing regexp
Table name comparison changed to UTF-8 aware and case insensitive
Table constructor now accepts AddressRange and array of [$fromColumnIndex, $fromRow, $toColumnIndex, $toRow]
Implemented in d414f13 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution; it's much appreciated. I'll add the details to the Change Log.
Hi all! I have a question regarding this feature: Is this documented anywhere? I can't seem to find this in the documentation... |
@m-thalmann-athesia It's a complex feature, and being implemented in stages, with creation/writing first, and Reading basic tables is the second part included in the next release. Calculated table values won't be fully supported until I can get the Calculation Engine handling Structured References, which has been driving me insane for the past 9 months. Until then, calculated values can't be calculated after reading; and it's necessary to disable calculation when writing (although the formulae can still be written). Full documentation is likely to be created only after the calculation engine works with Structured References; though I might add some basic documentation over Christmas/New Year. |
@MarkBaker oh I see! Okay, thank you very much for the hard & great work! |
@MarkBaker with this code fragment // Create Table Style
$tableStyle = new TableStyle();
$tableStyle->setTheme(TableStyle::TABLE_STYLE_MEDIUM23);
$table->setStyle($tableStyle);
$spreadsheet->getActiveSheet()->addTable($table); I get with <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>Reparaturergebnis speichern in persons (27)0.xml</logFileName>
<summary>Fehler in Datei '/Users/beweiche/Downloads/persons (27).xlsx'</summary>
<repairedRecords summary="Die folgenden Reparaturen wurden durchgeführt:_x000d__x000a__x000d__x000a_">
<repairedRecord>Reparierte Datensätze: Tabelle von /xl/tables/table1.xml-Part (Tabelle)</repairedRecord>
</repairedRecords>
</recoveryLog> What can I do? |
@bwl21 Samples/Table/01_Table.php uses exactly the code you asked about, and does not create a corrupt file. (It does a little additional styling, but, even when I comment out those additional statements, there is no problem with the output.) In order to see what's going wrong for you, I need more information - the script or the output file or both. |
thanks for your investigatin. i will try to make a test case. |
@oleibman I managed to find the reason:
can you confirm this? |
Confirmed. Although my following statement may not be precisely correct, it captures the gist. Excel will report a problem if a table has columns with the same name, or a column with no name. We might be able to do something to prevent us creating a spreadsheet with those conditions. Please open a new issue if you want us to look into that. In the meantime, you should have enough information to be able to get around your problem for now. |
This is:
Checklist:
Why this change is needed?
Tables are similar to AutoFilter but tables have several other advantages like named ranges, easy formatting, totals row and header row with filter. Tables can also be converted to charts and pivot tables easily.
Unlike AutoFilter, Tables are not restricted to only one per worksheet.
Issue: #1816, #2337
Usage:
In this Commit:
To be done: