NPOI设置word单元格颜色XWPFTableCell.setcolor
一、NPOI设置word单元格颜色XWPFTableCell.setcolor
使用案例:
XWPFDocument doc = new XWPFDocument(); //创建一个段落 XWPFParagraph para = doc.createParagraph(); //一个XWPFRun代表具有相同属性的一个区域:一段文本 XWPFRun run = para.createRun(); run.setBold(true); //加粗 run.setText("加粗的内容"); run = para.createRun(); run.setColor("FF0000"); run.setText("红色的字。"); OutputStream os = new FileOutputStream("D:\\simpleWrite.docx"); //把doc输出到输出流 doc.write(os); this.close(os);
使用案例2
//复制单元格样式 private void CopyCellStyle(XWPFTableCell newCell, XWPFTableCell oldCell) { CT_Tc cttc1 = newCell.GetCTTc(); CT_TcPr tcpr1 = cttc1.AddNewTcPr(); tcpr1.tcW = oldCell.GetCTTc().tcPr.tcW; tcpr1.tcBorders = oldCell.GetCTTc().tcPr.tcBorders; tcpr1.tcMar = oldCell.GetCTTc().tcPr.tcMar; tcpr1.gridSpan = oldCell.GetCTTc().tcPr.gridSpan; //newCell.SetColor("#ffffff"); ---此中带#好的不兼容 newCell.SetColor("ffffff"); }
更多:
NPOI Excel导出报错 Cannot access a closed stream
NPOI Excel导出超出65536行报错 Invalid row number (65536) outside allowable range (0..65535)解决方法