由于我是 NPOI 新手,我想向 Excel 工作表中的单元格添加颜色。我有一个像“#ffeeff”这样的十六进制值,并且ICellStyle.FillForegroundColor只能分配短整型值。
System.OverflowException:对于 Int16 来说值太大或太小。
我已经尝试过这样的代码并且它正在工作
style.FillForegroundColor = HSSFColor.Grey25Percent.Index;
Run Code Online (Sandbox Code Playgroud)
但我只有可以转换为 int 的十六进制值,但它仅支持短 int 值。
//it is working
style.FillForegroundColor = HSSFColor.Grey25Percent.Index;
// not working for me as '#ffeeff' canot be converted to short, it can only be converted to int
style.FillForegroundColor = short.Parse(fontcolorCode.Substring(1), NumberStyles.HexNumber)
style.FillForegroundColor = short.Parse(fontcolorCode.Substring(1), NumberStyles.HexNumber)
Run Code Online (Sandbox Code Playgroud)
它不应该抛出错误,并且在 Excel 工作表中,必须将相同的颜色(fontcolorCode)应用于单元格