zoukankan      html  css  js  c++  java
  • 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;
            }
        }
    }
    

      

  • 相关阅读:
    In Java, how do I read/convert an InputStream to a String? Stack Overflow
    IFrame自动更改大小
    [置顶] 获取服务器上格式为JSON和XML两种格式的信息的小程序
    Qt VS MFC
    [技术分享]使用 UAG 发布 RemoteAPP
    linux2.6.32在mini2440开发板上移植(11)之配置USB外设
    MFC控件(2):Text_Edit_Control
    CentOS 6.4 安装 Oracle 10g2 备记
    sql lite 二个数据库之间的表进行复制
    变量和函数的定义和声明
  • 原文地址:https://www.cnblogs.com/ProDoctor/p/6796085.html
Copyright © 2011-2022 走看看