zoukankan      html  css  js  c++  java
  • NPOI2.0学习(三)

    HSSFWorkbook wk = new HSSFWorkbook();//你用来操作的HSSFWorkbook的实例  
    ICellStyle cellStyle = wk.CreateCellStyle(); 
    ICellStyle cellStyle = wk.CreateCellStyle();  
    //设置单元格上下左右边框线  
    cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;  
    cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;  
    cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;  
    cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;  
    //文字水平和垂直对齐方式  
    cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;  
    cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;  
    //是否换行  
    //cellStyle.WrapText = true;  
    //缩小字体填充  
    cellStyle.ShrinkToFit = true; 
    
    
     ICellStyle style2 = wb.CreateCellStyle();//样式
        IFont font1 = wb.CreateFont();//字体
        font1.FontName = "楷体";
        font1.Color = HSSFColor.Red.Index;//字体颜色
        font1.Boldweight = (short)FontBoldWeight.Normal;//字体加粗样式
        style2.SetFont(font1);//样式里的字体设置具体的字体样式
        //设置背景色
        style2.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
        style2.FillPattern = FillPattern.SolidForeground;
        style2.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index;
        style2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;//文字水平对齐方式
        style2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//文字垂直对齐方式
    ICell Cell = sheet.CreateRow(0).CreateCell(0);  
    Cell.CellStyle = cellStyle;  
    Cell.SetCellValue("测试格式效果");  
    ICellStyle newCellStyle = wk.CreateCellStyle();  
    newCellStyle.CloneStyleFrom(cellStyle);  
    newCellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left; 
  • 相关阅读:
    汪曾祺《生活是很好玩的》有感
    中小学Python编程语言教学
    1. python 基础课程目录
    白盒测试之gmock入门篇
    Apache与Tomcat 区别联系
    白盒测试之gtest第一个demo
    白盒测试之初识gtest工具
    纯手工打造dropdownlist控件
    android 线程的使用总结
    染色板QPlette
  • 原文地址:https://www.cnblogs.com/shy1766IT/p/5357670.html
Copyright © 2011-2022 走看看