zoukankan      html  css  js  c++  java
  • NPOI设置Excel单元格字体、边框、对齐、背景色

    代码:

    ICellStyle cellStyle = workbook.CreateCellStyle();
    cellStyle.BorderBottom = BorderStyle.Thin;
    cellStyle.BorderLeft = BorderStyle.Thin;
    cellStyle.BorderRight = BorderStyle.Thin;
    cellStyle.BorderTop = BorderStyle.Thin;
    cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
    cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
    
    ICellStyle cellStyleTitle = workbook.CreateCellStyle();
    cellStyleTitle.BorderBottom = BorderStyle.Thin;
    cellStyleTitle.BorderLeft = BorderStyle.Thin;
    cellStyleTitle.BorderRight = BorderStyle.Thin;
    cellStyleTitle.BorderTop = BorderStyle.Thin;
    cellStyleTitle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
    cellStyleTitle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
    IFont font = workbook.CreateFont();
    font.IsBold = false;
    font.FontHeightInPoints = 12;
    cellStyleTitle.SetFont(font);
    HSSFPalette palette = ((HSSFWorkbook)workbook).GetCustomPalette();
    palette.SetColorAtIndex((short)9, 98, 185, 106);
    var color = palette.FindColor(98, 185, 106);
    //下面两行设置单元格背景色
    cellStyleTitle.FillPattern = FillPattern.SolidForeground;
    cellStyleTitle.FillForegroundColor = color.Indexed;
    
    ICellStyle cellStyleTitle2 = workbook.CreateCellStyle();
    cellStyleTitle2.CloneStyleFrom(cellStyleTitle);
    font = workbook.CreateFont();
    font.IsBold = false;
    font.FontHeightInPoints = 14;
    cellStyleTitle2.SetFont(font);
    View Code
  • 相关阅读:
    web-火狐浏览器下载地址
    如何使用jmeter录制app脚本
    Jmeter参数化(jmter和badboy的配合使用)
    monkey常用命令详解(多参数化)
    monkey常用命令
    mysql数据库命令
    Linux命令
    循环语句的使用
    K8S学习笔记一:K8S的基础概念
    jmeter做尖峰测试(浪潮测试)
  • 原文地址:https://www.cnblogs.com/s0611163/p/7337747.html
Copyright © 2011-2022 走看看