如何使用xssfworkbook npoi在字体中设置RGB颜色
如何使用npoi使用类xssfworkbook
在cell backgroudn
设置RGB颜色?
byte[] rgb = new byte[3] { 192, 50, 90 }; XSSFCellStyle HeaderCellStyle1 = (XSSFCellStyle)wb.CreateCellStyle(); HeaderCellStyle1.SetFillForegroundColor(new XSSFColor(new Color(255, 255, 255)));
我不想使用这种模式:
titlestyle.BottomBorderColor = IndexedColors.Grey25Percent.Index;
solution of your problem is here here simply define new xssfcolor and assign it to xssfcellstyle var color = new XSSFColor(new byte[] { 0,255, 0 }); var rowstyle =(XSSFCellStyle)wb.CreateCellStyle(); rowstyle.SetFillForegroundColor(color)
您必须首先确保将字体转换为XSSFFont
,IFont不提供对字体的RGB颜色属性的访问。
然后,您可以使用XSSColor
设置颜色, XSSColor
可以从字节数组或System.Drawing.Color对象构造。
示例代码,注释中构造函数的不同变种:
上述就是C#学习教程:如何使用xssfworkbook npoi在字体中设置RGB颜色分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
var wb = new XSSFWorkbook(); var sheet = wb.CreateSheet("Sheet 1"); // Create a colored font var font = (XSSFFont) wb.CreateFont(); // var color = new XSSFColor(ColorTranslator.FromHtml("#C88C14")); // var color = new XSSFColor(new Color(255, 255, 255)); var color = new XSSFColor(new byte[] {200, 140, 20}); font.SetColor(color); // Create a dedicated cell style using that font var style = wb.CreateCellStyle(); style.SetFont(font); // Create some cell values var row = sheet.CreateRow(0); row.CreateCell(0).SetCellValue("Standard text"); var cell = row.CreateCell(1); cell.SetCellValue("Colored text"); // Apply the cellstyle we created cell.CellStyle = style;
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/942630.html