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

  • 相关阅读:
    PyQt(Python+Qt)学习随笔:containers容器类部件QStackedWidget重要方法介绍
    什么叫工业4.0,这篇接地气的文章终于讲懂了
    怎样 真正认识一个 人
    华为的绩效管理:减人、增 效、加薪
    羽毛球战术
    魔方教程
    员工培养:事前指导,事后纠正
    一把手瞄准哪里,核心竞争力就在哪里
    海尔的五次战略变革
    如何提高基层员工的执行力
  • 原文地址:https://www.cnblogs.com/wsn1203/p/5387298.html
Copyright © 2011-2022 走看看