Nopi Excel下载功能
#region //table
var list = _instrumentservice.GetInstrManageStatisticDto(null,null,null);DataTable table = new DataTable(); //1
table.Columns.Add("管理员姓名", typeof(string));
table.Columns.Add("所在学院-所在实验室", typeof(string));
table.Columns.Add("累计预约总时长(本年度)", typeof(string));
table.Columns.Add("累计预约结算时长(本年度)", typeof(string));
List<int> widths = new List<int>(); widths.Add(7000); widths.Add(7000); widths.Add(7000); widths.Add(7000);//5
foreach (var item in list)
{
table.Rows.Add(item.PinYin_AdminName + "_" + item.AdminName, item.DepartName + "-" + item.LabName, item.OrderTotalTime + "小时", item.SettledTotalTime + "小时");
}
#endregion
string sheetName = "实验人员工作评价(本年度)"; //3
string cellTitleValue = sheetName + "---" + DateTime.Now.Year + "-1 至 " + DateTime.Now.Year + "-" + DateTime.Now.Month;//4
//int columncount = 7; //5
#region //styleTitle
IWorkbook workbook = new HSSFWorkbook();//2
ICellStyle styleTitle = workbook.CreateCellStyle(); //6
IFont font = SetFont(workbook, "BOLD", 14, "Arial"); //设置字体 //workbook.CreateFont();
//font.Boldweight = (short)FontBoldWeight.BOLD;//加粗
//font.FontHeightInPoints = 14;
styleTitle.SetFont(font);
styleTitle.FillForegroundColor = HSSFColor.WHITE.index;
styleTitle.FillPattern = FillPatternType.LEAST_DOTS; //背景图文
styleTitle.FillBackgroundColor = HSSFColor.WHITE.index; //背景色
styleTitle = SetCellStyle(styleTitle, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//styleTitle.Alignment = HorizontalAlignment.CENTER; //左右 横向样式
//styleTitle.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//create a font style
ICellStyle StyleHead = workbook.CreateCellStyle(); //7
IFont FontCell = SetFont(workbook, "NORMAL", 12, "Arial"); //设置字体
//IFont FontCell = workbook.CreateFont();//创建字体样式
//FontCell.Boldweight = (short)FontBoldWeight.NORMAL;//加粗
//FontCell.FontHeightInPoints = 12; //字体大小
//FontCell.FontName = "Arial"; //字体
StyleHead.SetFont(FontCell); //加入字体样式
StyleHead.SetFont(FontCell);
StyleHead.FillForegroundColor = HSSFColor.WHITE.index;
StyleHead.FillBackgroundColor = HSSFColor.WHITE.index;
StyleHead = SetCellStyle(StyleHead, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//StyleHead.FillForegroundColor = HSSFColor.WHITE.index; //
//StyleHead.FillPattern = FillPatternType.LEAST_DOTS; //
//StyleHead.FillBackgroundColor = HSSFColor.WHITE.index; //背景色
//StyleHead.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;//横样式
//StyleHead.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//StyleHead.BorderBottom = CellBorderType.THIN; //边框
//StyleHead.BorderTop = CellBorderType.THIN;//边框
//StyleHead.BorderLeft = CellBorderType.THIN;//边框
//StyleHead.BorderRight = CellBorderType.THIN;//边框
ICellStyle StyleCell = workbook.CreateCellStyle(); //8
FontCell = SetFont(workbook, "NORMAL", 12, "Arial"); //设置字体
StyleCell.SetFont(FontCell);
StyleCell.FillForegroundColor = HSSFColor.WHITE.index;
StyleCell.FillBackgroundColor = HSSFColor.WHITE.index;
StyleCell = SetCellStyle(StyleCell, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//FontCell = workbook.CreateFont();//创建字体样式
//FontCell.Boldweight = (short)FontBoldWeight.NORMAL;//普通
//FontCell.FontHeightInPoints = 12;
//FontCell.FontName = "Arial";
//StyleCell.SetFont(FontCell);
//StyleCell.Alignment =HorizontalAlignment.LEFT;//横样式
//StyleCell.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//StyleCell.BorderBottom = CellBorderType.THIN;
//StyleCell.BorderTop = CellBorderType.THIN;
//StyleCell.BorderLeft = CellBorderType.THIN;
//StyleCell.BorderRight = CellBorderType.THIN;
//StyleCell.FillForegroundColor = HSSFColor.WHITE.index;
//StyleCell.FillPattern = FillPatternType.LEAST_DOTS;
//StyleCell.FillBackgroundColor = HSSFColor.WHITE.index;
#endregion
//HttpContext.Request
DownExcel(table, workbook, sheetName, cellTitleValue, widths, styleTitle, StyleHead, StyleCell, HttpContext);
return new EmptyResult();#region //table
var list = _instrumentservice.GetInstrManageStatisticDto(null,null,null);
DataTable table = new DataTable(); //1
table.Columns.Add("管理员姓名", typeof(string));
table.Columns.Add("所在学院-所在实验室", typeof(string));
table.Columns.Add("累计预约总时长(本年度)", typeof(string));
table.Columns.Add("累计预约结算时长(本年度)", typeof(string));
List<int> widths = new List<int>(); widths.Add(7000); widths.Add(7000); widths.Add(7000); widths.Add(7000);//5
foreach (var item in list)
{
table.Rows.Add(item.PinYin_AdminName + "_" + item.AdminName, item.DepartName + "-" + item.LabName, item.OrderTotalTime + "小时", item.SettledTotalTime + "小时");
}
#endregion
string sheetName = "实验人员工作评价(本年度)"; //3
string cellTitleValue = sheetName + "---" + DateTime.Now.Year + "-1 至 " + DateTime.Now.Year + "-" + DateTime.Now.Month;//4
//int columncount = 7; //5
#region //styleTitle
IWorkbook workbook = new HSSFWorkbook();//2
ICellStyle styleTitle = workbook.CreateCellStyle(); //6
IFont font = SetFont(workbook, "BOLD", 14, "Arial"); //设置字体 //workbook.CreateFont();
//font.Boldweight = (short)FontBoldWeight.BOLD;//加粗
//font.FontHeightInPoints = 14;
styleTitle.SetFont(font);
styleTitle.FillForegroundColor = HSSFColor.WHITE.index;
styleTitle.FillPattern = FillPatternType.LEAST_DOTS; //背景图文
styleTitle.FillBackgroundColor = HSSFColor.WHITE.index; //背景色
styleTitle = SetCellStyle(styleTitle, HorizontalAlignment.CENTER, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//styleTitle.Alignment = HorizontalAlignment.CENTER; //左右 横向样式
//styleTitle.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//create a font style
ICellStyle StyleHead = workbook.CreateCellStyle(); //7
IFont FontCell = SetFont(workbook, "NORMAL", 12, "Arial"); //设置字体
//IFont FontCell = workbook.CreateFont();//创建字体样式
//FontCell.Boldweight = (short)FontBoldWeight.NORMAL;//加粗
//FontCell.FontHeightInPoints = 12; //字体大小
//FontCell.FontName = "Arial"; //字体
StyleHead.SetFont(FontCell); //加入字体样式
StyleHead.SetFont(FontCell);
StyleHead.FillForegroundColor = HSSFColor.WHITE.index;
StyleHead.FillBackgroundColor = HSSFColor.WHITE.index;
StyleHead = SetCellStyle(StyleHead, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//StyleHead.FillForegroundColor = HSSFColor.WHITE.index; //
//StyleHead.FillPattern = FillPatternType.LEAST_DOTS; //
//StyleHead.FillBackgroundColor = HSSFColor.WHITE.index; //背景色
//StyleHead.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;//横样式
//StyleHead.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//StyleHead.BorderBottom = CellBorderType.THIN; //边框
//StyleHead.BorderTop = CellBorderType.THIN;//边框
//StyleHead.BorderLeft = CellBorderType.THIN;//边框
//StyleHead.BorderRight = CellBorderType.THIN;//边框
ICellStyle StyleCell = workbook.CreateCellStyle(); //8
FontCell = SetFont(workbook, "NORMAL", 12, "Arial"); //设置字体
StyleCell.SetFont(FontCell);
StyleCell.FillForegroundColor = HSSFColor.WHITE.index;
StyleCell.FillBackgroundColor = HSSFColor.WHITE.index;
StyleCell = SetCellStyle(StyleCell, HorizontalAlignment.LEFT, VerticalAlignment.CENTER, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, CellBorderType.THIN, FillPatternType.LEAST_DOTS);
//FontCell = workbook.CreateFont();//创建字体样式
//FontCell.Boldweight = (short)FontBoldWeight.NORMAL;//普通
//FontCell.FontHeightInPoints = 12;
//FontCell.FontName = "Arial";
//StyleCell.SetFont(FontCell);
//StyleCell.Alignment =HorizontalAlignment.LEFT;//横样式
//StyleCell.VerticalAlignment = VerticalAlignment.CENTER;//垂直样式
//StyleCell.BorderBottom = CellBorderType.THIN;
//StyleCell.BorderTop = CellBorderType.THIN;
//StyleCell.BorderLeft = CellBorderType.THIN;
//StyleCell.BorderRight = CellBorderType.THIN;
//StyleCell.FillForegroundColor = HSSFColor.WHITE.index;
//StyleCell.FillPattern = FillPatternType.LEAST_DOTS;
//StyleCell.FillBackgroundColor = HSSFColor.WHITE.index;
#endregion
//HttpContext.Request
DownExcel(table, workbook, sheetName, cellTitleValue, widths, styleTitle, StyleHead, StyleCell, HttpContext);
return new EmptyResult();