提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:李显亮|2020-01-13 09:47:21.320|阅读 666 次
概述:Excel中的数据透视表被广泛用于数据的汇总和分析。基于Excel数据透视表的重要性,本文旨在向您展示如何在Excel中创建数据透视表并排序或隐藏数据。
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
Aspose.Cells for .NET是Excel电子表格编程API,可加快电子表格管理和处理任务,同时支持构建具有生成,修改,转换,呈现和打印电子表格功能的跨平台应用程序。
用于生成和操作Excel电子表格的自动化解决方案如今已被广泛使用。Excel中的数据透视表被广泛用于数据的汇总和分析。而对数据透视表中的数据进行排序对于检查Excel电子表格中的大量数据非常有用。
数据透视表中的数据排序可用于按字母顺序(AZ或ZA)排列文本值的项目,或在数字的情况下从最高值到最低值或从最低值到最高值。基于Excel数据透视表的重要性,本文旨在向您展示如何:
如果你还没有使用过Aspose.Cells,可以点击此处下载最新版体验。
为了进行演示,下面图示的Excel电子表格将在整个示例中使用。
首先让我们看看如何使用Aspose.Cells for .NET在C#中创建Excel数据透视表。创建数据透视表后,我们将隐藏行并根据其列或行字段对数据进行排序。下面的代码示例演示如何创建Excel数据透视表。
Workbook wb = new Workbook("SampleExcel.xlsx");
// Obtaining the reference of the newly added worksheet
Worksheet sheet = wb.Worksheets[0];
PivotTableCollection pivotTables = sheet.PivotTables;
// source PivotTable
// Adding a PivotTable to the worksheet
int index = pivotTables.Add("=Sheet1!A1:C10", "E3", "PivotTable2");
//Accessing the instance of the newly added PivotTable
PivotTable pivotTable = pivotTables[index];
// Unshowing grand totals for rows.
pivotTable.RowGrand = false;
pivotTable.ColumnGrand = false;
// Dragging the first field to the row area.
pivotTable.AddFieldToArea(PivotFieldType.Row, 1);
PivotField rowField = pivotTable.RowFields[0];
rowField.IsAutoSort = true;
rowField.IsAscendSort = true;
// Dragging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, 0);
PivotField colField = pivotTable.ColumnFields[0];
colField.NumberFormat = "dd/mm/yyyy";
colField.IsAutoSort = true;
colField.IsAscendSort = true;
// Dragging the third field to the data area.
pivotTable.AddFieldToArea(PivotFieldType.Data, 2);
pivotTable.RefreshData();
pivotTable.CalculateData();
// end of source PivotTable
//Saving the Excel file
wb.Save("output.xlsx");
输出结果
现在,我们将创建另一个数据透视表,并对数据进行排序。下面的代码示例创建并按“ SeaFood”行字段值对数据透视表进行排序。
Workbook wb = new Workbook("SampleExcel.xlsx");
// Obtaining the reference of the Excel worksheet.
Worksheet sheet = wb.Worksheets[0];
PivotTableCollection pivotTables = sheet.PivotTables;
// Adding a PivotTable to the Excel worksheet.
int index = pivotTables.Add("=Sheet1!A1:C10", "E3", "PivotTable2");
// Accessing the instance of the newly added PivotTable.
PivotTable pivotTable = pivotTables[index];
// Unshowing grand totals for rows.
pivotTable.RowGrand = false;
pivotTable.ColumnGrand = false;
// Dragging the first field to the row area.
pivotTable.AddFieldToArea(PivotFieldType.Row, 1);
PivotField rowField = pivotTable.RowFields[0];
rowField.IsAutoSort = true;
rowField.IsAscendSort = true;
// Dragging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, 0);
PivotField colField = pivotTable.ColumnFields[0];
colField.NumberFormat = "dd/mm/yyyy";
colField.IsAutoSort = true;
colField.IsAscendSort = true;
colField.AutoSortField = 0;
// Dragging the third field to the data area.
pivotTable.AddFieldToArea(PivotFieldType.Data, 2);
pivotTable.RefreshData();
pivotTable.CalculateData();
// Saving the Excel file.
wb.Save("output.xlsx");
输出结果
以下C#代码示例对“ 28/07/2000”列的字段值进行排序。
Workbook wb = new Workbook("SampleExcel.xlsx");
// Obtaining the reference of the Excel worksheet.
Worksheet sheet = wb.Worksheets[0];
PivotTableCollection pivotTables = sheet.PivotTables;
// Adding a PivotTable to the Excel worksheet.
int index = pivotTables.Add("=Sheet1!A1:C10", "E3", "PivotTable2");
// Accessing the instance of the newly added PivotTable.
PivotTable pivotTable = pivotTables[index];
// Unshowing grand totals for rows.
pivotTable.RowGrand = false;
pivotTable.ColumnGrand = false;
// Dragging the first field to the row area.
pivotTable.AddFieldToArea(PivotFieldType.Row, 1);
PivotField rowField = pivotTable.RowFields[0];
rowField.IsAutoSort = true;
rowField.IsAscendSort = true;
colField.AutoSortField = 0;
// Dragging the second field to the column area.
pivotTable.AddFieldToArea(PivotFieldType.Column, 0);
PivotField colField = pivotTable.ColumnFields[0];
colField.NumberFormat = "dd/mm/yyyy";
colField.IsAutoSort = true;
colField.IsAscendSort = true;
// Dragging the third field to the data area.
pivotTable.AddFieldToArea(PivotFieldType.Data, 2);
pivotTable.RefreshData();
pivotTable.CalculateData();
// Saving the Excel file.
wb.Save("output.xlsx");
输出结果
根据希望应用的某些条件隐藏Excel数据透视表中的行。下面的代码示例展示了如何使用c#隐藏数据透视表中的特定行。
Workbook workbook = new Workbook("output.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
var pivotTable = worksheet.PivotTables[0];
var dataBodyRange = pivotTable.DataBodyRange;
int currentRow = 1;
int rowsUsed = dataBodyRange.EndRow;
// Sorting values in descending
PivotField field = pivotTable.RowFields[0];
field.IsAutoSort = true;
field.IsAscendSort = false;
field.AutoSortField = 0;
pivotTable.RefreshData();
pivotTable.CalculateData();
// Hiding rows with value less than 15
while (currentRow < rowsUsed) { Cell cell = worksheet.Cells[currentRow, 2]; double score = Convert.ToDouble(cell.Value); if (score < 15) { worksheet.Cells.HideRow(currentRow); } currentRow++; } pivotTable.RefreshData(); pivotTable.CalculateData(); // Saving the Excel file workbook.Save("PivotTableHideAndSort.xlsx");
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@hmdbvip.cn




Parasoft C/C++test是一款专为C/C++代码设计的自动化测试工具,通过静态代码分析、单元测试和运行时错误检测等功能,帮助开发团队在早期发现并修复缺陷,提升代码质量和开发效率 。在实际使用中,尤其是在VC6此类旧版开发环境中执行单元测试时,可能会因环境兼容性问题触发链接错误。
本文主要介绍如何在MVVM应用程序中使用虚拟源,欢迎下载最新版组件体验!
Aspose.Slides for Java使用户能够轻松地操作幻灯片、添加注释和转换文件。其易用性和集成能力提高了工作效率,使开发人员能够专注于更关键的任务。
在嵌入式软件测试领域,对交叉编译代码进行单元测试是一大挑战。Parasoft C/C++test作为专业的C/C++测试工具,能够与劳特巴赫Trace32调试器深度集成。下面会详细介绍如何在C++test中配置Trace32调试器,实现对PowerPC架构程序的单元测试,涵盖环境设置、项目导入到测试执行的全过程。
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@hmdbvip.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
永利最大(官方)网站