qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.36k stars 1.72k forks source link

How to add subtotals to a sheet? #805

Open tfonfara opened 3 years ago

tfonfara commented 3 years ago

Is there any way to add subtotals to a sheet?

Excel-table-05

SetRowOutlineLevel doesn't seem to help as it doesn't create the subtotals.

Thank you!

xuri commented 3 years ago

Thanks for your issue. SetRowOutlineLevel just group rows, and you can use SetCellFormula to set SUBTOTAL formula for the cell.

tfonfara commented 3 years ago

Actually the "subtotal" method in excel does automatically grouping that can be removed or adjusted very easy. If I use SetCellFormula this means that (1) I have to do all the calculations manually, also the grouping and the summarization and (2) that this is "hardcoded" in the table, it can't be switched off or modified in any way (which is a big benefit of the original subtotal feature).

Maybe to be precise, I'm not referring to the subtotal function, instead I'm talking about the subtotal command.