亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 C# 中激活數據透視表總計的顯示詳細信息

在 C# 中激活數據透視表總計的顯示詳細信息

C#
至尊寶的傳說 2022-11-22 16:39:07
我正在嘗試使用 C# 從 Excel 自動創建數據透視表的“顯示詳細信息”using Excel = Microsoft.Office.Interop.Excel;我的代碼:var excelApp = new Excel.Application();excelApp.Visible = true;Excel.Workbook workbook = excelApp.Workbooks.Open(@"D:\path_to_excel_file.xlsm");Excel.Worksheet worksheet = (Excel.Worksheet)workbook.Worksheets["Sheet_Name"];Excel.PivotTable pivot = worksheet.PivotTables("defined_pivot_table_name");pivot.DataBodyRange.ShowDetail = true;該代碼有效,但它僅顯示第一個“總計”值的詳細信息。但我想要的是獲得“總計”的“顯示詳細信息”。在這種情況下,對于這個數據透視表,它將創建一個包含 4 個元素的新工作表,但我想要的是總計 (202)。我試過先選擇它,pivot.PivotSelect("Grand Total");但仍然沒有結果。我也檢查過pivot.RowGrand,pivot.ColumnGrand它們都返回 True。
查看完整描述

2 回答

?
當年話下

TA貢獻1890條經驗 獲得超9個贊

如果您的數據透視表同時具有RowGrandAND ColumnGrand,那么它也有一個總計


if (pivot.RowGrand && pivot.ColumnGrand)

然后您可以使用數據透視表的最后一個單元格TableRange1生成詳細信息ShowDetail


int countRows = pivot.TableRange1.Rows.Count;

int countColumns = pivot.TableRange1.Columns.Count;

pivot.TableRange1.Cells[countRows, countColumns].ShowDetail = true;


查看完整回答
反對 回復 2022-11-22
?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

也許可以幫助

// Access the pivot table by its name in the collection. 

PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];



// Access the pivot field by its name in the collection. 

PivotField field = pivotTable.Fields["Category"];



// Display multiple subtotals for the field.   

field.SetSubtotal(PivotSubtotalFunctions.Sum | PivotSubtotalFunctions.Average);


// Show all subtotals at the bottom of each group. 

pivotTable.Layout.ShowAllSubtotals(false);


// Hide grand totals for rows.

pivotTable.Layout.ShowRowGrandTotals = False


// Hide grand totals for columns.

pivotTable.Layout.ShowColumnGrandTotals = False


// custom label for grand totals

pivotTable.View.GrandTotalCaption = "Total Sales";


查看完整回答
反對 回復 2022-11-22
  • 2 回答
  • 0 關注
  • 114 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號