Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add pivot table with limitations#2551

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Siemienik merged 4 commits intoexceljs:masterfrommikez:master
Oct 31, 2023
Merged

Conversation

mikez
Copy link
Contributor

@mikezmikez commentedOct 9, 2023
edited
Loading

worksheet.addPivotTable(configuration);

Note: Pivot table support is in its early stages with certain limitations, including:

  • No support for reading xlsx documents with existing pivot tables (writing is supported).
  • Pivot table configurations must consist of one "value" item and use the sum metric.
  • Only one pivot table can be added for the entire document.

Example usage

constworkbook=newExcel.Workbook();constworksheet1=workbook.addWorksheet('Sheet1');worksheet1.addRows([['A','B','C','D','E'],['a1','b1','c1',4,5],['a1','b2','c1',4,5],['a2','b1','c2',14,24],['a2','b2','c2',24,35],['a3','b1','c3',34,45],['a3','b2','c3',44,45],]);constworksheet2=workbook.addWorksheet('Sheet2');worksheet2.addPivotTable({// Source data: entire sheet rangesourceSheet:worksheet1,// Pivot table fields: via header row in `worksheet1`rows:['A','B'],columns:['C'],values:['E'],// Exactly 1 fieldmetric:'sum',// Metric: 'sum' only});

michaelhays, Siemienik, CloudBudgetInc, and jybleau reacted with thumbs up emojimichaelhays, Siemienik, sgalich, jens1101, and kaiquye reacted with heart emoji
Copy link
Member

@SiemienikSiemienik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hello@mikez , Thank you for the latest changes, I'm really happy that Exceljs has possibility to gain new feature even with limitations.
I added few comments, I would be glad for answering that 😄

Good job and I love the direction when it comes. 🥇

Comment on lines +72 to +82
if(!model.rows.length){
thrownewError('No pivot table rows specified.');
}

if(!model.columns.length){
thrownewError('No pivot table columns specified.');
}

if(model.values.length!==1){
thrownewError('Exactly 1 value needs to be specified at this time.');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Would It be enabled to add partially configured pivot table without for instance rows set?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

At this time, the code doesn't support that. You need at least one item in each of {rows, columns, values}.
However, this could be a potential feature down the road if it is requested.

Siemienik reacted with thumbs up emoji
// { name: 'E', sharedItems: null }
// ]

constnames=worksheet.getRow(1).values;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does it always start from row 1?

Copy link
ContributorAuthor

@mikezmikezOct 24, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I made the simplifying assumption that the source data is represented by the entire sheet, with the first row representing the header. Do you think this assumption is too simplistic and won't capture 95% of the cases?

Siemienik reacted with thumbs up emoji
Comment on lines +817 to +824
this.pivotTables.push(pivotTable);
this.workbook.pivotTables.push(pivotTable);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What will happen if someone remove the pivot table from one of these places, or overwrite one of them?
What do you think about makingwb.workbook.pivotTables a getter returning pivottables from all worksheets? Or .. a function?
Can it attach onepivotTable to multiple sheets?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What will happen if someone remove the pivot table from one of these places, or overwrite one of them?

@Siemienik It seems you're pointing at the mutability ofworksheet.pivotTables andworksheet.workbook.pivotTables and concerns for that clients might mutate this. If you think this type of safety is needed and consistent with elsewhere in ExcelJS, we can definitely make it a getter. I'll take your advice here.

Can it attach one pivotTable to multiple sheets?

At this time, I intend for there to be at most one pivotTable in at most one sheet across the entire workbook. The user should not have to mutateworksheet.pivotTables orworksheet.workbook.pivotTables and only accessworksheet.addPivotTable.

return`
<pivotField axis="${axis}"${defaultAttributes}>
<items count="${sharedItems.length+1}">
${[...range(0,sharedItems.length)].map(index=>`<item x="${index}" />`).join('\n ')}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You may try this way:

Suggested change
${[...range(0,sharedItems.length)].map(index=>`<item x="${index}" />`).join('\n ')}
${sharedItems.map((item,index)=>`<item x="${index}" />`).join('\n ')}

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Clever. I like this. I will update and force push this.

@mikez
Copy link
ContributorAuthor

@Siemienik: I added few comments, I would be glad for answering that 😄

Thank you. Please guide me where I might want to add clarifications to the documentation or comments to make it clearer for other readers.

```jsworksheet.addPivotTable(configuration);```**Note:** Pivot table support is in its early stages with certain limitations, including:- Xlsx files with existing pivot tables can't be read (writing is supported).- Pivot table configurations must have one "value"-item and use the "sum" metric.- Only one pivot table can be added for the entire document.
Copy link
Member

@SiemienikSiemienik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM, thank you for booting up new feature into exceljs 👏

@SiemienikSiemienik merged commitddab279 intoexceljs:masterOct 31, 2023
@mikez
Copy link
ContributorAuthor

👉 Feedback and discussionhere.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@SiemienikSiemienikSiemienik approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@mikez@Siemienik

[8]ページ先頭

©2009-2025 Movatter.jp