nopi使用 设置列样式 宽高 设置分页符

            HSSFWorkbook book = new HSSFWorkbook();
            ISheet sheet = book.CreateSheet("test_01");
            sheet.FitToPage = false;//设置不过滤分页符号
//设置第一列宽度
            sheet.SetColumnWidth(0, 3600);
          //设置第一列默认样式GetDefaultCellStyleCell()为自己写的扩展方法
            sheet.SetDefaultColumnStyle(0, book.GetDefaultCellStyleCell());
          
            IRow row = null;
创建第0行
       row = sheet.CreateRow(i); i++;
创建行第0列
                ICell ICell = row.CreateCell(0);
                ICell = book.GetCellTitleStyleCell(ICell, "      宜花网(Easyflower)发货单       ");
                row = sheet.CreateRow(i); i++;
                //标题信息加重字体
                row.CreateCell(0);
                row.Cells[0] = book.GetCellImportantStyleCell(row.Cells[0], "订货单号:");
                row.CreateCell(1).SetCellValue(item.orderInfo.oId);
                row.CreateCell(2);
                row.Cells[2] = book.GetCellImportantStyleCell(row.Cells[2], "花店编号:");
                row.CreateCell(3).SetCellValue("72710");
                row = sheet.CreateRow(i); i++;    
sheet.SetRowBreak(i);//插入分页符号

  

using NPOI.SS.UserModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NPOI.HSSF.UserModel
{
  public  static  class HSSFWorkbookExtend
    {
        /// <summary>
        /// 获取标题类ExcelStyle列格式
        /// </summary>
        /// <param name="hssf"></param>
        /// <param name="cell"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ICell  GetCellTitleStyleCell(this HSSFWorkbook hssf, ICell cell, string value )
        {


            ICellStyle styleTitle = hssf.CreateCellStyle();
            styleTitle.BorderDiagonalLineStyle = BorderStyle.DashDotDot;
            IFont font = hssf.CreateFont();
            font.FontName = "黑体";
            font.FontHeightInPoints = 18;
            font.Color = 200;

            styleTitle.SetFont(font);
            cell.CellStyle = styleTitle;

            cell.SetCellValue(value);
            return cell;
        }
        /// <summary>
        /// 获取重要的信息格式
        /// </summary>
        /// <param name="hssf"></param>
        /// <param name="cell"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ICell GetCellImportantStyleCell(this HSSFWorkbook hssf, ICell cell, string value)
        {


            ICellStyle styleTitle = hssf.CreateCellStyle();
            styleTitle.BorderDiagonalLineStyle = BorderStyle.Dotted;
            IFont font = hssf.CreateFont();
            styleTitle.Alignment= HorizontalAlignment.Left;//【Left】左对齐  
            font.FontName = "黑体";
            font.FontHeightInPoints = 11;
            font.Color = 200;
            styleTitle.SetFont(font);
            font.Boldweight = 500;
            cell.CellStyle = styleTitle;
           
            cell.SetCellValue(value);
            return cell;
        }

        /// <summary>
        /// 获取重要的信息格式
        /// </summary>
        /// <param name="hssf"></param>
        /// <param name="cell"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static ICellStyle GetDefaultCellStyleCell(this HSSFWorkbook hssf)
        {

            ICellStyle styleTitle = hssf.CreateCellStyle();
            styleTitle.BorderDiagonalLineStyle = BorderStyle.Hair;
            IFont font = hssf.CreateFont();
            font.FontName = "宋体";
            styleTitle.Alignment = HorizontalAlignment.Left;//【Left】左对齐  

            font.FontHeightInPoints =11;
            font.Boldweight = 200;
            font.Color = 200;
            styleTitle.SetFont(font);
            return styleTitle;
        }
    }
}

  

原文地址:https://www.cnblogs.com/ProDoctor/p/6796085.html