如何使用 Epplus c# 在同一个大纲中添加多个折叠
How to add multiple collapse in same outline using Epplus c#
我需要在同一大纲级别进行多次折叠。
for (var j = 0; j <= 2; j++)
{
workSheet.Row(j).OutlineLevel = 1;
workSheet.Row(j).Collapsed = true;
workSheet.Row(j+3).OutlineLevel = 1;
workSheet.Row(j+3).Collapsed = true;
}
是否可以在同一个大纲中实现两个折叠。
提前致谢:)
我认为在 Excel 中做到这一点的唯一方法(暂时搁置 Epplus)是在各组之间制造差距。在 Epplus 中,你可以这样做:
[TestMethod]
public void Row_Multiple_Grouping_Test()
{
//
//Throw in some data
var dataTable = new DataTable("tblData");
dataTable.Columns.AddRange(new[]
{
new DataColumn("Header", typeof (string)),
new DataColumn("Col1", typeof (int)),
new DataColumn("Col2", typeof (int)),
new DataColumn("Col3", typeof (object))
});
for (var i = 0; i < 10; i++)
{
var row = dataTable.NewRow();
row[0] = $"Header {i}";
row[1] = i; row[2] = i * 10;
row[3] = Path.GetRandomFileName();
dataTable.Rows.Add(row);
}
//Create a test file
var fi = new FileInfo(@"c:\temp\Row_Multiple_Grouping_Test.xlsx");
if (fi.Exists)
fi.Delete();
using (var pck = new ExcelPackage(fi))
{
var worksheet = pck.Workbook.Worksheets.Add("Sheet1");
worksheet.Cells.LoadFromDataTable(dataTable, true);
//Create the grouping
for (var i = 2; i <= 11; i++)
{
worksheet.Row(i).OutlineLevel = 1;
worksheet.Row(i).Collapsed = true;
}
//Create a gap - cant shrink or hide it because it hides the collapse button in GUI
worksheet.InsertRow(7, 1);
pck.Save();
}
}
给出:
问题是您不能在不松开 Expand/Collapse 按钮的情况下缩小或隐藏该行。你能做的最好的就是在组中加上 header/footer。
我需要在同一大纲级别进行多次折叠。
for (var j = 0; j <= 2; j++)
{
workSheet.Row(j).OutlineLevel = 1;
workSheet.Row(j).Collapsed = true;
workSheet.Row(j+3).OutlineLevel = 1;
workSheet.Row(j+3).Collapsed = true;
}
是否可以在同一个大纲中实现两个折叠。 提前致谢:)
我认为在 Excel 中做到这一点的唯一方法(暂时搁置 Epplus)是在各组之间制造差距。在 Epplus 中,你可以这样做:
[TestMethod]
public void Row_Multiple_Grouping_Test()
{
//
//Throw in some data
var dataTable = new DataTable("tblData");
dataTable.Columns.AddRange(new[]
{
new DataColumn("Header", typeof (string)),
new DataColumn("Col1", typeof (int)),
new DataColumn("Col2", typeof (int)),
new DataColumn("Col3", typeof (object))
});
for (var i = 0; i < 10; i++)
{
var row = dataTable.NewRow();
row[0] = $"Header {i}";
row[1] = i; row[2] = i * 10;
row[3] = Path.GetRandomFileName();
dataTable.Rows.Add(row);
}
//Create a test file
var fi = new FileInfo(@"c:\temp\Row_Multiple_Grouping_Test.xlsx");
if (fi.Exists)
fi.Delete();
using (var pck = new ExcelPackage(fi))
{
var worksheet = pck.Workbook.Worksheets.Add("Sheet1");
worksheet.Cells.LoadFromDataTable(dataTable, true);
//Create the grouping
for (var i = 2; i <= 11; i++)
{
worksheet.Row(i).OutlineLevel = 1;
worksheet.Row(i).Collapsed = true;
}
//Create a gap - cant shrink or hide it because it hides the collapse button in GUI
worksheet.InsertRow(7, 1);
pck.Save();
}
}
给出:
问题是您不能在不松开 Expand/Collapse 按钮的情况下缩小或隐藏该行。你能做的最好的就是在组中加上 header/footer。