• NPOI导出Excel文件,对单元格的一些设置


     1 HSSFWorkbook book = new HSSFWorkbook();
     2 MemoryStream ms = new MemoryStream();
     3 ISheet sheet = book.CreateSheet("sheet1");
     4 ICellStyle cellStyle = book.CreateCellStyle();
     5 
     6 // 首列
     7 NPOI.SS.UserModel.IRow row1 = sheet.CreateRow(0);
     8 row1.CreateCell(0).SetCellValue(System.DateTime.Now.Year+"年XXXX");
     9 //设置单元格的样式:水平对齐居中
    10 row1.Cells[0].CellStyle.VerticalAlignment = VerticalAlignment.Justify;//垂直对齐(默认应该为center,如果center无效则用justify)
    11 row1.Cells[0].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;//水平对齐
    12 CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, 8);//开始行的索引,结束行的索引,开始列的索引,结束列的索引
    13 
    14 sheet.AddMergedRegion(cellRangeAddress);//要合并单元格所在的sheet

    参考网址:http://www.jb51.net/article/36002.htm

     1   NPOI.SS.UserModel.IRow row = sheet.CreateRow(1);
     2             row.CreateCell(0).SetCellValue("序号");
     3             row.CreateCell(1).SetCellValue("单位");
     4             row.CreateCell(2).SetCellValue("姓名");
     5             row.CreateCell(3).SetCellValue("性别");
     6             row.CreateCell(4).SetCellValue("年龄");
     7             row.CreateCell(5).SetCellValue("民族");
     8             row.CreateCell(6).SetCellValue("培训班名称");
     9             row.CreateCell(7).SetCellValue("电报号");
    10             row.CreateCell(8).SetCellValue("培训时间");
    11             sheet.SetColumnWidth(1, 30 * 256);//设置列宽
    12             sheet.SetColumnWidth(6, 30*256);
    13             sheet.SetColumnWidth(7, 30 * 256);
    14             sheet.SetColumnWidth(8, 50*256);

    参考网址:http://www.jb51.net/article/55407.htm

  • 相关阅读:
    del:根据索引值删除元素
    Python insert()方法插入元素
    Python extend()方法添加元素
    Python append()方法添加元素
    Python list列表添加元素的3种方法
    什么是序列,Python序列详解(包括序列类型和常用操作)
    Python运算符优先级和结合性一览表
    Python print()函数高级用法
    Python input()函数:获取用户输入的字符串
    Python变量的定义和使用
  • 原文地址:https://www.cnblogs.com/wsn1203/p/5387298.html
Copyright © 2020-2023  润新知