Это текущий код:
Код: Выделить всё
using OfficeOpenXml.Table.PivotTable;
using OfficeOpenXml.Table;
using OfficeOpenXml;
namespace EPPlus_POC
{
public class TransactionEPPlus
{
public string CustomerName { get; set; }
public string Items { get; set; }
public string TransactionDate { get; set; }
public string PostingDate { get; set; }
public string DueDate { get; set; }
public double TransactionAmount { get; set; }
public double TransactionAmountReporting { get; set; }
}
public static class EPPlusExample
{
public static void CreatePivotTable(List transactions)
{
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (ExcelPackage package = new ExcelPackage())
{
// Add a worksheet
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Transactions");
ExcelWorksheet worksheet2 = package.Workbook.Worksheets.Add("Transactions-Pivot");
// Load the data into the worksheet, starting from cell A1
worksheet.Cells["A1"].LoadFromCollection(transactions, true);
// Define the data range
var dataRange = worksheet.Cells[1, 1, transactions.Count + 1, 7];
// Add a pivot table
var pivotTable = worksheet2.PivotTables.Add(worksheet2.Cells["A1"], dataRange, "PivotTable");
// Configure the values
var tAmount = pivotTable.DataFields.Add(pivotTable.Fields["TransactionAmount"]);
tAmount.Format = "#,##0.00";
pivotTable.DataFields.Add(pivotTable.Fields["TransactionAmountReporting"]);
// Configure the rows
pivotTable.RowFields.Add(pivotTable.Fields["CustomerName"]);
pivotTable.RowFields.Add(pivotTable.Fields["Items"]);
var tDate = pivotTable.RowFields.Add(pivotTable.Fields["TransactionDate"]);
tDate.Name = "Transaction date";
pivotTable.RowFields.Add(pivotTable.Fields["PostingDate"]);
pivotTable.RowFields.Add(pivotTable.Fields["DueDate"]);
// Configure subtotals and grand totals
pivotTable.RowFields[0].SubTotalFunctions = eSubTotalFunctions.Default; // No subtotals for all rows except CustomerName
pivotTable.RowFields[0].Outline = false;
pivotTable.RowFields[0].Compact = false;
for (int i = 1; i < pivotTable.RowFields.Count; i++)
{
pivotTable.RowFields[i].SubTotalFunctions = eSubTotalFunctions.None;
pivotTable.RowFields[i].Outline = false;
pivotTable.RowFields[i].Compact = false;
pivotTable.RowFields[i].ShowInFieldList = true;
}
pivotTable.RowGrandTotals = true; // Show grand totals for columns
pivotTable.ColumnGrandTotals = false; // Do not show grand totals for rows
// Display in tabular form
pivotTable.PivotTableStyle = PivotTableStyles.Light15;
pivotTable.Compact = true;
pivotTable.CompactData = true;
pivotTable.UseAutoFormatting = true;
pivotTable.ShowMemberPropertyTips = false;
pivotTable.DataOnRows = false;
pivotTable.RowHeaderCaption = "Customer name";
pivotTable.ShowValuesRow = false;
pivotTable.DataCaption = "wow";
// SHow filter for all the columns except calculated fields
foreach (var pivotField in pivotTable.Fields)
{
pivotField.Outline = false;
pivotField.Compact = false;
}
worksheet.Hidden = eWorkSheetHidden.VeryHidden;
// Save the Excel package to a file
FileInfo fileInfo = new FileInfo("EPPlus.xlsx");
package.SaveAs(fileInfo);
Console.WriteLine("Excel file created successfully!");
}
}
}
}
Код: Выделить всё
using EPPlus_POC;
List transactions = new List
{
new TransactionEPPlus { CustomerName = "Customer A", Items = "Item 1", TransactionDate = "06/10/2024", PostingDate = "06/10/2024", DueDate = "06/10/2024", TransactionAmount = 10900.55, TransactionAmountReporting = 900400 },
new TransactionEPPlus { CustomerName = "Customer B", Items = "Item 2", TransactionDate = "06/10/2024", PostingDate = "06/10/2024", DueDate = "06/10/2024", TransactionAmount = 20560.78, TransactionAmountReporting = 180870 },
new TransactionEPPlus { CustomerName = "Customer B", Items = "Item 2", TransactionDate = "12/10/2024", PostingDate = "06/10/2024", DueDate = "06/10/2024", TransactionAmount = 25000.43, TransactionAmountReporting = 330600 },
new TransactionEPPlus { CustomerName = "Customer C", Items = "Item 3", TransactionDate = "12/10/2024", PostingDate = "06/10/2024", DueDate = "06/10/2024", TransactionAmount = 30560.11, TransactionAmountReporting = 56000.55 },
new TransactionEPPlus { CustomerName = "Customer C", Items = "Item 4", TransactionDate = "12/10/2024", PostingDate = "06/10/2024", DueDate = "06/10/2024", TransactionAmount = 1700, TransactionAmountReporting = 100600 }
// Add more transactions as needed
};
EPPlusExample.CreatePivotTable(transactions);
Сводная таблица с текущим кодом

Но я не могу понять, что я здесь делаю не так, потому что я хочу скрыть строку, в которой есть текст «вау», это заголовок данных, я хочу удалить эту строку, не скрывая ее с помощью библиотеки EPPlus.
Итоговая таблица должна выглядеть следующим образом, т. е. без строки данных (строка «вау»):
Окончательный результат

Кто-нибудь знает, как я могу достичь то же самое, используя библиотеку EPPlus в C#?
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/789 ... ivot-table