如何使用OpenXML SDK对Excel进行分组 [英] How to Group the Rows n a Excel using OpenXML SDK
问题描述
大家好,
我有一个要求,我需要使用OpenXMl SDK对excel中的行进行分组。
我已经浏览了几个网站但是运气不好。任何帮助将不胜感激。
谢谢!
Hello all,
I had a requirement where i need to group the rows in the excel using OpenXMl SDK.
I have gone through the several websites but was unlucky.Any help would be appreciated.
Thanks!!
推荐答案
这是荒谬简化的解决方案将是这样的:
Hi, well the absurdly simplified solution would be something like this:
SheetData sheetData = ...
int start = 5;
int count = 3;
foreach (var row in sheetData.Elements<Row>().Skip(start))
{
if (count-- > 0)
row.SetAttribute(new OpenXmlAttribute("outlineLevel", string.Empty, "1"));
else
break;
}
这导致分组行6,7和8,你可能会注意到你只需要添加 outlineLevel
属性,其中包含所需行的级别值。
但我需要指出这个非常简化的解决方案,我只是向您展示了什么你的目标是。
你看到在进行迭代时你需要实际评估 row.RowIndex
。此外,如果您要定位到组内的某些行缺失,则需要添加它们并在其上应用 outlineLevel
属性。
我希望这会让你开始朝着正确的方向前进,如果你需要更多让我知道的话。
This results in grouping rows "6", "7" and "8", you may notice that you just need to add outlineLevel
attribute with the level's value to the required rows.
But again I need to point out that this very very simplified solution with which I'm just showing you what your goal is.
You see you need to actually evaluate the row.RowIndex
when doing the iteration. Also in case some rows, that you are targeting to be inside your group, are missing you need to add them and apply the outlineLevel
attribute on them as well.
I hope this will get you started in the right direction, if you need more let me know.
这篇关于如何使用OpenXML SDK对Excel进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!