admin管理员组文章数量:1292149
I have a script that creates a pivot table, but I don't want to display subtotals, only final totals.
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getActiveWorksheet(); // Downloading the active sheet
// Finding the range with the data (I assume it starts with A1)
let dataRange = sheet.getRange("A1").getSurroundingRegion();
// Checking that the scope is correct
if (!dataRange) {
console.log("No data found.");
return;
}
// Creating a pivot table on the same sheet
let pivotTable = sheet.addPivotTable("February", dataRange, sheet.getRange("H1"));
let rowHierarchy = pivotTable.addRowHierarchy(pivotTable.getHierarchy("Posting date"));
// Pivot table configuration
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Project no."));
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Name"));
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Task No."));
// Dodanie wartości (Ilość)
let qtyHierarchy = pivotTable.getHierarchy("Time");
let dataField = pivotTable.addDataHierarchy(qtyHierarchy);
dataField.setSummarizeBy(ExcelScript.AggregationFunction.sum);
// Hiding subtotals for "Project No." and "Name"
// Alternate formatting (lines)
let pivotRange = pivotTable.getLayout().getRange();
let rowCount = pivotRange.getRowCount();
for (let i = 1; i < rowCount; i += 2) { // Every second line
let row = pivotRange.getCell(i, 0).getEntireRow();
row.getFormat().getFill();
}
console.log("The pivot table has been created.");
}
I would like the grand total not to be shown and I would like the column and row lines to be shown.
I have a script that creates a pivot table, but I don't want to display subtotals, only final totals.
function main(workbook: ExcelScript.Workbook) {
let sheet = workbook.getActiveWorksheet(); // Downloading the active sheet
// Finding the range with the data (I assume it starts with A1)
let dataRange = sheet.getRange("A1").getSurroundingRegion();
// Checking that the scope is correct
if (!dataRange) {
console.log("No data found.");
return;
}
// Creating a pivot table on the same sheet
let pivotTable = sheet.addPivotTable("February", dataRange, sheet.getRange("H1"));
let rowHierarchy = pivotTable.addRowHierarchy(pivotTable.getHierarchy("Posting date"));
// Pivot table configuration
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Project no."));
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Name"));
pivotTable.addColumnHierarchy(pivotTable.getHierarchy("Task No."));
// Dodanie wartości (Ilość)
let qtyHierarchy = pivotTable.getHierarchy("Time");
let dataField = pivotTable.addDataHierarchy(qtyHierarchy);
dataField.setSummarizeBy(ExcelScript.AggregationFunction.sum);
// Hiding subtotals for "Project No." and "Name"
// Alternate formatting (lines)
let pivotRange = pivotTable.getLayout().getRange();
let rowCount = pivotRange.getRowCount();
for (let i = 1; i < rowCount; i += 2) { // Every second line
let row = pivotRange.getCell(i, 0).getEntireRow();
row.getFormat().getFill();
}
console.log("The pivot table has been created.");
}
I would like the grand total not to be shown and I would like the column and row lines to be shown.
Share asked Feb 13 at 9:58 LucasLucas 31 bronze badge1 Answer
Reset to default 0The methods for setting and hiding grand totals are exposed via the PivotLayout interface.
pivotTable.getLayout().setShowRowGrandTotals(false)
pivotTable.getLayout().setShowColumnGrandTotals(false)
PivotTable interface, getLayout() method
PivotLayout interface, setShowRowGrandTotals method
本文标签: javascriptExcel script for generating pivot tables without subtotalsStack Overflow
版权声明:本文标题:javascript - Excel script for generating pivot tables without subtotals - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741550086a2384826.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论