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

  • 相关阅读:
    自定义响应结果
    JsonUtils (JSON与对象之间的转换)
    IDUtils (ID生成策略)
    ExceptionUtil(异常使用工具类)
    Hbuilder连接夜神模拟器
    夜神模拟器开启开发者选项
    java.lang.OutOfMemoryError: Java heap space的解决方法
    Android开发LogCat一直不停输出的解决方法
    windows无法停用“Android Composite Interface”设备的解决方法
    android:digits属性
  • 原文地址:https://www.cnblogs.com/wsn1203/p/5387298.html
Copyright © 2011-2022 走看看