我正在尝试在Excel中设置链接的样式,但是由于某些原因,我无法使CellStyle Font
正常工作
。NET Core 2.1
NPOI:2.1.4
错误:
Excel已完成文件级验证和修复。该工作簿的某些部分可能已被修复或拒绝。修复的记录:/xl/styles.xml(样式)中的字体
这很好用:
var myStyle = workbook.CreateCellStyle();
myStyle.BorderBottom = BorderStyle.Double;
cell.Hyperlink = new XSSFHyperlink(HyperlinkType.Url) { Address = url };
cell.CellStyle = myStyle;
这不是:
var myStyle = workbook.CreateCellStyle();
var myFont = workbook.CreateFont();
myStyle.BorderBottom = BorderStyle.Double;
myStyle.SetFont(myFont);
cell.Hyperlink = new XSSFHyperlink(HyperlinkType.Url) { Address = url };
cell.CellStyle = myStyle;
这不是2:
var myStyle = workbook.CreateCellStyle();
var myFont = workbook.CreateFont();
myStyle.BorderBottom = BorderStyle.Double;
myFont.Color = IndexedColors.Blue.Index;
myStyle.SetFont(myFont);
cell.Hyperlink = new XSSFHyperlink(HyperlinkType.Url) { Address = url };
cell.CellStyle = myStyle;
我尝试使用myFont.Color
设置
IndexedColors.Blue.Index;
HSSFColor.Blue.Index;
HSSFColor.Blue.Index2;
新XSSFColor(Color.Blue).Indexed;
并且每次结果都相同-Excel正在修复工作表。
任何想法?
编辑
如果删除了超链接的代码,字体可以工作吗?只是想看看超链接和字体的组合是否不起作用...
var myStyle = workbook.CreateCellStyle();
var myFont = workbook.CreateFont();
myStyle.BorderBottom = BorderStyle.Double;
myStyle.SetFont(myFont);
//cell.Hyperlink = new XSSFHyperlink(HyperlinkType.Url) { Address = url };
cell.CellStyle = myStyle;
仍然是相同的结果
Excel已完成文件级验证和修复。该工作簿的某些部分可能已被修复或拒绝。修复的记录:/xl/styles.xml(样式)中的字体
这是NPOI 2.4.1中的错误,它将在下一版本中修复:
https://github.com/tonyqus/npoi/issues/165
现在仅设置FontHeight或FontHeightInPoints,它将起作用。