zoukankan      html  css  js  c++  java
  • Npoi操作excel

     http://www.cnblogs.com/knowledgesea/archive/2012/11/16/2772547.html

    设置背景颜色,边框

             //设置样式
                     HSSFCellStyle ShenPiStyle = (HSSFCellStyle)workbook.CreateCellStyle();
    
                     ShenPiStyle.Alignment = (HorizontalAlignment)HorizontalAlign.Left;
                     ShenPiStyle.VerticalAlignment = VerticalAlignment.CENTER;
                     ShenPiStyle.WrapText = true; //自动换行
    
                     HSSFFont ShenPiStylefonts = (HSSFFont)workbook.CreateFont();
                     ShenPiStylefonts.FontHeightInPoints = 11;
                     ShenPiStylefonts.FontName = "宋体";
                     ShenPiStyle.SetFont(ShenPiStylefonts);
                     ShenPiStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
                     ShenPiStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.THIN;
                     ShenPiStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
                     ShenPiStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
    
                     ShenPiStyle.FillForegroundColor = HSSFColor.LIGHT_CORNFLOWER_BLUE.index;
                     ShenPiStyle.FillPattern = NPOI.SS.UserModel.FillPatternType.SOLID_FOREGROUND;
    
                     //ShenPiStyle.FillBackgroundColor = HSSFColor.BLUE.index;
                     
                     BeiZhu.GetCell(0).CellStyle = ShenPiStyle;

    合并单元格设置单元格的边框:

          HSSFRow BeiZhu = (HSSFRow)sheet.CreateRow(rowIndex); //第 3 行
                     BeiZhu.Height = 80 * 20;
    
                     CellRangeAddress region = new CellRangeAddress(rowIndex, rowIndex, 0, 6);
                     sheet.AddMergedRegion(region);
                     ((HSSFSheet)sheet).SetEnclosedBorderOfRegion(region, NPOI.SS.UserModel.BorderStyle.THIN, HSSFColor.BLACK.index);

    NPOI单元格颜色设置及对照表

     http://www.docin.com/p-665268648.html

    设置合并单元格文字竖行显示:

                     //竖行显示的文字样式
                     HSSFCreationHelper createHelper = (HSSFCreationHelper)workbook.GetCreationHelper();
    
                     HSSFCellStyle shu = (HSSFCellStyle)workbook.CreateCellStyle();
                     shu.VerticalAlignment = VerticalAlignment.CENTER;
                     shu.Alignment = (HorizontalAlignment)HorizontalAlign.Center;
                     //多行显示
                     shu.WrapText = true;
    
                     HSSFFont shufonts = (HSSFFont)workbook.CreateFont();
                     shufonts.FontHeightInPoints = 11;
                     shufonts.FontName = "宋体";
                     shufonts.Boldweight = 600;
                     shu.SetFont(shufonts);
                     //shu.Rotation = (short)-90;
    
                     shu.BorderBottom = NPOI.SS.UserModel.BorderStyle.THIN;
                     shu.BorderRight = NPOI.SS.UserModel.BorderStyle.THIN;
                     shu.BorderTop = NPOI.SS.UserModel.BorderStyle.THIN;
    
                     HSSFRow row3 = (HSSFRow)sheet.CreateRow(3); //第 3 行
                     row3.Height = 30 * 20;
    
                     row3.CreateCell(0, CellType.STRING).SetCellValue(createHelper.CreateRichTextString("本
    周
    工
    作
    总
    结
    ")); 
    
                     row3.GetCell(0).CellStyle = shu;
  • 相关阅读:
    My SqL 常用命令
    RGB颜色查询对照表
    Android 对话框(Dialog)大全
    【转】Android一些知识点汇总
    Google Maps API v2密钥申请
    蓝牙中文API文档
    IOS 电商类app 第一版架构 改进
    ios 开发小记 (四)
    ios 深度复制 copy & mutablecopy
    CCS绘制成的三角形箭头
  • 原文地址:https://www.cnblogs.com/kennyliu/p/4114983.html
Copyright © 2011-2022 走看看