首页 > 其他 > 详细

NPOI操作

时间:2019-12-28 18:59:44      阅读:53      评论:0      收藏:0      [点我收藏+]
HSSFWorkbook workbook = new HSSFWorkbook();
ICellStyle cellStyle = workbook.CreateCellStyle();
//设置字体
 IFont font = workbook.CreateFont();
font.Color = HSSFColor.Red.Index;
cellStyle.SetFont(font);
//设置背景色
//cellStyle.FillForegroundColor = HSSFColor.Red.Index;
//cellStyle.FillPattern = FillPattern.SolidForeground;
ISheet sheet = workbook.CreateSheet("sheet1");
//设置标题行
IRow headRow = sheet.CreateRow(0);
 //创建单元格 
ICell headCell = headRow.CreateCell(i);  
//设置值
headCell.SetCellValue("姓名") 
//设置之前的样式
bodyRow.GetCell(i).CellStyle = cellStyle;i
string newPath = $"/ExcelReport/{year}-{month}/";
string filename = $"{year}-{month}.xls";
if (!Directory.Exists(HttpContext.Current.Server.MapPath(newPath)))
{
    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(newPath));
}
using (FileStream fs = new FileStream(HttpContext.Current.Server.MapPath(newPath) + filename, FileMode.Create, FileAccess.Write))
{
    workbook.Write(fs);
}

写入文件流中并保存文件

 

NPOI操作

原文:https://www.cnblogs.com/litianfeng-net/p/12112561.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!