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

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

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

   NPOI.SS.UserModel.IRow row = sheet.CreateRow();
row.CreateCell().SetCellValue("序号");
row.CreateCell().SetCellValue("单位");
row.CreateCell().SetCellValue("姓名");
row.CreateCell().SetCellValue("性别");
row.CreateCell().SetCellValue("年龄");
row.CreateCell().SetCellValue("民族");
row.CreateCell().SetCellValue("培训班名称");
row.CreateCell().SetCellValue("电报号");
row.CreateCell().SetCellValue("培训时间");
sheet.SetColumnWidth(, * );//设置列宽
sheet.SetColumnWidth(, *);
sheet.SetColumnWidth(, * );
sheet.SetColumnWidth(, *);

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

上一篇:IT技术团队管理-总结


下一篇:[xsd学习]复合元素