NPOI CloneStyleFrom无法正常工作

问题描述

ClonestyleFrom无法正常运行。

我希望cellStyleBorderThin.ClonestyleFrom(cellStyleBorderThick);能够克隆设置而不改变原始样式。更改 cellStyleBorderThin 设置后, cellStyleBorderThick 现在包含相同的边框设置。

我检查了每个cellStyleBorder索引。每个人都有一个唯一的ID。

我希望B,D和F列具有粗边框。

enter image description here

下面的代码示例。

// read the workbook
IWorkbook wb;
using (FileStream fs = new FileStream(newPath,FileMode.Open,FileAccess.Read))
{
    wb = new XSSFWorkbook(fs);
}

var cellStyleBorderThick = GetDefaultStyle(wb);

var cellStyleBorderThin = wb.CreateCellStyle();
cellStyleBorderThin.ClonestyleFrom(cellStyleBorderThick);
cellStyleBorderThin.BorderRight = BorderStyle.Thin;
cellStyleBorderThin.BorderBottom = BorderStyle.Thin;
cellStyleBorderThin.BorderLeft = BorderStyle.Thin;
cellStyleBorderThin.BorderTop = BorderStyle.Thin;
// Adding this font did not impact cellStyleBorderThick.  CurIoUs.  Only borders seem to be impacted.
cellStyleBorderThin.SetFont(GetFont(wb,20));

// helper function to create font
private static XSSFFont GetFont(IWorkbook wb,double size)
{
var font = (XSSFFont)wb.CreateFont();
font.FontHeightInPoints = size;
font.FontName = "Calibri";

return font;
}

// helper function to get default style
private static ICellStyle GetDefaultStyle(IWorkbook wb)
{

var cellStyleBorderThick = wb.CreateCellStyle();
cellStyleBorderThick.SetFont(GetFont(wb,10));
cellStyleBorderThick.VerticalAlignment = VerticalAlignment.Center;
cellStyleBorderThick.BorderRight = BorderStyle.Thick;
cellStyleBorderThick.BorderBottom = BorderStyle.Thick;
cellStyleBorderThick.BorderLeft = BorderStyle.Thick;
cellStyleBorderThick.BorderTop = BorderStyle.Thick;
cellStyleBorderThick.Alignment = HorizontalAlignment.Left;

return cellStyleBorderThick;
}

        
        

NPOI v2.5.1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...