如何在EPPlus中为整个列设置样式? [英] How to set the style for an entire column in EPPlus?
问题描述
是否可以在EPPlus中为整个列设置样式?我希望我可以只使用 Column
方法,但是当我这样做时,会得到奇怪的结果:
Is it possible to set the style for an entire column in EPPlus? I would expect that I could just use the Column
method, but when I do I get strange results:
//Sets all cells in all columns to Red
worksheet.Column(1).Style.Font.Color.SetColor(Color.Red);
//Sets some cells in column B to red.
worksheet.Column(2).Style.Font.Color.SetColor(Color.Red);
在两种情况下,我都在添加一些标题行之后但在添加大量行之前设置颜色是不是在其他任何地方设置颜色。设置水平对齐方式时,我还会得到类似的意外结果。目前,我不得不在单元格级别设置样式。
In both cases I am setting the colour after adding some header rows but before adding the bulk of the rows am an not setting the colour anywhere else. I also get similar unexpected results setting the horizontal alignment. At the moment I am resorting to having to set the style at the cell level.
我使用不正确吗?或者这是一个错误吗?使用EPPlus 3.1.2.0和Excel 2010(14.0.6129.5000)。
Am I using it incorrectly or is this a bug? Using EPPlus 3.1.2.0 and Excel 2010 (14.0.6129.5000) .
推荐答案
int indexOfColumn = ...;
worksheet.Column(indexOfColumn).Style.Font.Color.SetColor(Color.Red);
这篇关于如何在EPPlus中为整个列设置样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!