2024-04-10 09:10:51 +08:00
using BLL ;
using NPOI.SS.UserModel ;
using NPOI.XSSF.UserModel ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
using System.IO ;
using System.Linq ;
using System.Web ;
using System.Web.UI ;
using NPOI.SS.UserModel ;
using NPOI.SS.Util ;
using NPOI.XSSF.UserModel ;
using Model ;
using NPOI.SS.Formula.Functions ;
namespace FineUIPro.Web.TestRun.ProduceTestRun
{
public partial class RunningLogManagementList : PageBase
{
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
//绑定数据
2024-04-22 00:36:04 +08:00
BindGrid ( ) ;
2024-04-10 09:10:51 +08:00
}
}
#region 绑 定 数 据
/// <summary>
/// 数据绑定
/// </summary>
public void BindGrid ( )
{
2024-05-04 00:43:11 +08:00
var years = DateTime . Now . Year ;
2024-04-22 00:36:04 +08:00
string strSql = @"select a.RunningId,a.ProjectId,project.ProjectName as ProjectName,a.InstallationId,a.ProcessesId,a.SystemId,inst.PreRunName as InstallationName,proce.PreRunName as ProcessesName,syst.PreRunName as SystemName,a.JobNo,a.ShiftType,(case a.ShiftType when 1 then '白班' else '夜班' end) as ShiftTypeName,a.ShiftUser,shiftuser.UserName as ShiftUserName,a.SuccessionUser,successuser.UserName as SuccessionUserName,a.StartData,a.EndData,a.AddUser,a.AddTime,a.Sort from Running_LogManagement as a inner join Sys_User as shiftuser on shiftuser.UserId=a.ShiftUser inner join Sys_User as successuser on successuser.UserId=a.SuccessionUser inner join Base_Project as project on project.ProjectId=a.ProjectId inner join PreRun_SysDevice as inst on inst.PreRunId=a.InstallationId inner join PreRun_SysDevice as proce on proce.PreRunId=a.ProcessesId inner join PreRun_SysDevice as syst on syst.PreRunId=a.SystemId where a.ProjectId=@ProjectId " ;
2024-04-10 09:10:51 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
2024-04-22 00:36:04 +08:00
listStr . Add ( new SqlParameter ( "@ProjectId" , this . CurrUser . LoginProjectId ) ) ;
2024-05-04 00:43:11 +08:00
if ( ! string . IsNullOrWhiteSpace ( txtStartData . Text ) )
2024-04-10 09:10:51 +08:00
{
2024-05-04 00:43:11 +08:00
strSql + = " and a.StartData>=@StartData" ;
listStr . Add ( new SqlParameter ( "@StartData" , DateTime . Parse ( txtStartData . Text ) . ToString ( "yyyy-MM-dd" ) + " 00:00:00" ) ) ;
years = DateTime . Parse ( txtStartData . Text ) . Year ;
2024-04-10 09:10:51 +08:00
}
2024-05-04 00:43:11 +08:00
if ( ! string . IsNullOrWhiteSpace ( txtEndData . Text ) )
2024-04-10 09:10:51 +08:00
{
2024-05-04 00:43:11 +08:00
strSql + = " and a.EndData<=@EndData" ;
listStr . Add ( new SqlParameter ( "@EndData" , DateTime . Parse ( txtEndData . Text ) . ToString ( "yyyy-MM-dd" ) + " 23:59:59" ) ) ;
2024-04-10 09:10:51 +08:00
}
if ( ! string . IsNullOrWhiteSpace ( ddlShiftType . SelectedValue ) )
{
strSql + = " and a.ShiftType=@ShiftType" ;
listStr . Add ( new SqlParameter ( "@ShiftType" , ddlShiftType . SelectedValue ) ) ;
}
2024-05-04 00:43:11 +08:00
strSql + = " order by inst.PreRunLevel,inst.Sort,proce.Sort,syst.Sort asc" ;
2024-04-10 09:10:51 +08:00
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
var table = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataSource = table ;
Grid1 . DataBind ( ) ;
2024-05-04 00:43:11 +08:00
if ( Funs . DB . Running_LogManagement . Count ( x = > x . StartData . Value . Year = = years ) > 0 )
{
var minTime = Funs . DB . Running_LogManagement . Where ( x = > x . StartData . Value . Year = = years ) . Min ( m = > m . StartData ) ;
lblminTime . Text = $"{years}年日志最小日期:{minTime.Value.ToString(" yyyy - MM - dd ")}" ;
}
else
{
lblminTime . Text = $"{years}年无日志信息" ;
}
2024-04-10 09:10:51 +08:00
}
/// <summary>
/// 分页
/// </summary>
protected void Grid1_PageIndexChange ( object sender , GridPageEventArgs e )
{
Grid1 . PageIndex = e . NewPageIndex ;
BindGrid ( ) ;
}
/// <summary>
/// 分页下拉框
/// </summary>
protected void ddlPageSize_SelectedIndexChanged ( object sender , EventArgs e )
{
Grid1 . PageSize = Convert . ToInt32 ( ddlPageSize . SelectedValue ) ;
BindGrid ( ) ;
}
/// <summary>
/// 排序
/// </summary>
protected void Grid1_Sort ( object sender , GridSortEventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 双击修改
/// </summary>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
btnMenuModify_Click ( null , null ) ;
}
#endregion
#region 按 钮
/// <summary>
/// 关闭弹框
/// </summary>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 搜索
/// </summary>
protected void btnQuery_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
/// <summary>
/// 添加
/// </summary>
protected void btnAdd_Click ( object sender , EventArgs e )
{
2024-04-22 00:36:04 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "RunningLogManagementEdit.aspx?RunningId=" , "新增 - " ) ) ) ;
2024-04-10 09:10:51 +08:00
}
/// <summary>
/// 修改
/// </summary>
protected void btnModify_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
2024-04-22 00:36:04 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "RunningLogManagementEdit.aspx?RunningId={0}" , Grid1 . SelectedRowID , "编辑 - " ) ) ) ;
2024-04-10 09:10:51 +08:00
}
/// <summary>
/// 删除
/// </summary>
protected void btnDel_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
var ids = Grid1 . SelectedRowIDArray . ToList ( ) ;
var list = Funs . DB . Running_LogManagement . Where ( x = > ids . Contains ( x . RunningId ) ) . ToList ( ) ;
if ( list . Count > 0 )
{
Funs . DB . Running_LogManagement . DeleteAllOnSubmit ( list ) ;
Funs . DB . SubmitChanges ( ) ;
BindGrid ( ) ;
Alert . ShowInTop ( "删除成功!" , MessageBoxIcon . Success ) ;
}
}
/// <summary>
/// 导出
/// </summary>
protected void btnExport_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 | | Grid1 . SelectedRowIndexArray . Length > 1 )
{
Alert . ShowInTop ( "请至少选择记录,最大只可选择一条!" , MessageBoxIcon . Warning ) ;
return ;
}
var runningId = this . Grid1 . Rows [ Grid1 . SelectedRowIndex ] . DataKeys [ 0 ] . ToString ( ) ;
string rootPath = Server . MapPath ( "~/" ) + Const . ExcelUrl ;
//导出文件
string filePath = rootPath + DateTime . Now . ToString ( "yyyyMMddhhmmss" ) + "\\" ;
if ( ! Directory . Exists ( filePath ) )
{
Directory . CreateDirectory ( filePath ) ;
}
var data = from a in Funs . DB . Running_LogManagement
join b in Funs . DB . Base_Project on a . ProjectId equals b . ProjectId
join c in Funs . DB . Sys_User on a . ShiftUser equals c . UserId
join d in Funs . DB . Sys_User on a . SuccessionUser equals d . UserId
where a . RunningId = = runningId
select new
{
a . RunningId ,
a . ProjectId ,
a . InstallationId ,
a . ProcessesId ,
a . SystemId ,
a . JobNo ,
a . ShiftType ,
ShiftTypeName = a . ShiftType = = "1" ? "白班" : "夜班" ,
a . ShiftUser ,
ShiftUserName = c . UserName ,
a . SuccessionUser ,
SuccessionUserName = d . UserName ,
2024-04-22 00:57:39 +08:00
a . HandoverCare ,
2024-04-10 09:10:51 +08:00
a . StartData ,
a . EndData ,
2024-04-22 00:36:04 +08:00
a . Situation ,
a . Remarks ,
2024-04-10 09:10:51 +08:00
a . AddUser ,
a . AddTime ,
a . Sort
} ;
var model = data . FirstOrDefault ( ) ;
if ( model ! = null )
{
2024-04-22 00:57:39 +08:00
//操作问题
var operations = Funs . DB . Running_Operation . Where ( x = > x . RunningId = = model . RunningId ) . ToList ( ) ;
//维护问题
var maintes = Funs . DB . Running_Maintenance . Where ( x = > x . RunningId = = model . RunningId ) . ToList ( ) ;
2024-04-10 09:10:51 +08:00
string ReportFileName = $"{filePath}Production report( {DateTime.Now.ToString(" yyyy - MM - dd ")} {model.ShiftUserName}).xlsx" ;
int rowIndex = 0 ;
XSSFWorkbook hssfworkbook = new XSSFWorkbook ( ) ;
XSSFSheet ws = ( XSSFSheet ) hssfworkbook . CreateSheet ( $"Production report( {DateTime.Now.ToString(" yyyy - MM - dd ")} {model.ShiftUserName})" ) ;
#region 列 宽
ws . SetColumnWidth ( 0 , ( 9 * 256 ) ) ;
ws . SetColumnWidth ( 1 , ( 9 * 256 ) ) ;
ws . SetColumnWidth ( 2 , ( 43 * 256 ) ) ;
ws . SetColumnWidth ( 3 , ( 7 * 256 ) ) ;
ws . SetColumnWidth ( 4 , ( 8 * 256 ) ) ;
ws . SetColumnWidth ( 5 , ( 5 * 256 ) ) ;
#endregion
#region 样 式
//头部样式居中
ICellStyle titleStyle = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 14 , true , true ) ;
//头部样式靠左
ICellStyle leftTitleStyle = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Left , 14 , true , true ) ;
//公共样式
ICellStyle style = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true ) ;
//公共样式靠左
ICellStyle leftStyle = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Left , 10.5 , true ) ;
//公共样式靠左上对其
ICellStyle leftTopStyle = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Top , HorizontalAlignment . Left , 10.5 , true ) ;
//公共样式加粗
ICellStyle styleBold = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Center , 10.5 , true , true ) ;
//公共样式靠左加粗
ICellStyle styleLeftBold = SetExcelStyle ( hssfworkbook , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , BorderStyle . Thin , VerticalAlignment . Center , HorizontalAlignment . Left , 10.5 , true , true ) ;
#endregion
#region 头 部
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , rowIndex , rowIndex + 5 , 0 , 5 ) ;
//行1
var region = new CellRangeAddress ( rowIndex , rowIndex + 3 , 0 , 1 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . SetCellValue ( "WUHUAN ENGINEERING CO.,LTD" ) ;
ws . GetRow ( rowIndex ) . GetCell ( 0 ) . CellStyle = titleStyle ;
ws . GetRow ( rowIndex ) . GetCell ( 2 ) . SetCellValue ( "PT PETROKIMIA GRESIK" ) ;
ws . GetRow ( rowIndex ) . GetCell ( 2 ) . CellStyle = titleStyle ;
region = new CellRangeAddress ( rowIndex , rowIndex , 3 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex ) . GetCell ( 3 ) . SetCellValue ( "WUHUAN Job. No." ) ;
ws . GetRow ( rowIndex ) . GetCell ( 3 ) . CellStyle = styleBold ;
//行2
ws . GetRow ( rowIndex + 1 ) . GetCell ( 2 ) . SetCellValue ( "AMMONIA-Urea II PROJECT" ) ;
ws . GetRow ( rowIndex + 1 ) . GetCell ( 2 ) . CellStyle = titleStyle ;
region = new CellRangeAddress ( rowIndex + 1 , rowIndex + 1 , 3 , 5 ) ;
ws . AddMergedRegion ( region ) ;
//行3行4
region = new CellRangeAddress ( rowIndex + 2 , rowIndex + 3 , 2 , 2 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 2 ) . SetCellValue ( "Production report" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 2 ) . CellStyle = titleStyle ;
region = new CellRangeAddress ( rowIndex + 2 , rowIndex + 3 , 3 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 3 ) . SetCellValue ( "Page 1" ) ;
ws . GetRow ( rowIndex + 2 ) . GetCell ( 3 ) . CellStyle = titleStyle ;
//行5
region = new CellRangeAddress ( rowIndex + 4 , rowIndex + 4 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 0 ) . SetCellValue ( $"Shift: ( {model.ShiftUserName}) Succession: ( {model.SuccessionUserName}) {model.StartData.Value.ToString(" yyyy - MM - dd ")}— {model.EndData.Value.ToString(" yyyy - MM - dd ")}" ) ;
ws . GetRow ( rowIndex + 4 ) . GetCell ( 0 ) . CellStyle = styleBold ;
//行6
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 0 , 3 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 0 ) . SetCellValue ( "Operation situation" ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 0 ) . CellStyle = styleBold ;
region = new CellRangeAddress ( rowIndex + 5 , rowIndex + 5 , 4 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 4 ) . SetCellValue ( "Remarks" ) ;
ws . GetRow ( rowIndex + 5 ) . GetCell ( 4 ) . CellStyle = styleBold ;
#endregion
#region 数 据
var dataIndex = 5 ;
2024-04-22 00:57:39 +08:00
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 3 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( "DW Station 脱盐水" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = styleLeftBold ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 4 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 4 ) . SetCellValue ( "" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 4 ) . CellStyle = leftStyle ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 2 , dataIndex + 2 , 0 , 5 , 90 ) ;
region = new CellRangeAddress ( dataIndex + 2 , dataIndex + 2 , 0 , 3 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 0 ) . SetCellValue ( model . Situation ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
region = new CellRangeAddress ( dataIndex + 2 , dataIndex + 2 , 4 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 4 ) . SetCellValue ( model . Remarks ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 4 ) . CellStyle = leftStyle ;
dataIndex + = 2 ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( "Attention of next shift交班注意" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = styleLeftBold ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 2 , dataIndex + 2 , 0 , 5 , 30 ) ;
region = new CellRangeAddress ( dataIndex + 2 , dataIndex + 2 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 0 ) . SetCellValue ( model . HandoverCare ) ;
ws . GetRow ( dataIndex + 2 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
dataIndex + = 2 ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( "operation issue操作问题" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = styleLeftBold ;
dataIndex + = 1 ;
foreach ( var itemoption in operations )
{
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 , 30 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( $"reason原因: {itemoption.OperationReason}" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
dataIndex + = 1 ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 , 30 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( $"solution处理: {itemoption.OperationHandle}" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
dataIndex + = 1 ;
}
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( "maintenance issue维护问题" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = styleLeftBold ;
dataIndex + = 1 ;
foreach ( var itemmait in maintes )
{
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 , 30 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( $"reason原因: {itemmait.MaintenanceReason}" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
dataIndex + = 1 ;
ws = ExcelCreateRowTitle ( ws , hssfworkbook , style , dataIndex + 1 , dataIndex + 1 , 0 , 5 , 30 ) ;
region = new CellRangeAddress ( dataIndex + 1 , dataIndex + 1 , 0 , 5 ) ;
ws . AddMergedRegion ( region ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . SetCellValue ( $"solution处理: {itemmait.MaintenanceHandle}" ) ;
ws . GetRow ( dataIndex + 1 ) . GetCell ( 0 ) . CellStyle = leftStyle ;
dataIndex + = 1 ;
}
2024-04-10 09:10:51 +08:00
#endregion
ws . PrintSetup . Landscape = false ;
ws . PrintSetup . PaperSize = 9 ;
ws . ForceFormulaRecalculation = true ;
using ( FileStream filess = File . OpenWrite ( ReportFileName ) )
{
hssfworkbook . Write ( filess ) ;
}
FileInfo filet = new FileInfo ( ReportFileName ) ;
Response . Clear ( ) ;
Response . Charset = "GB2312" ;
Response . ContentEncoding = System . Text . Encoding . UTF8 ;
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
Response . AddHeader ( "Content-Disposition" , "attachment; filename=" + Server . UrlEncode ( $"Production report( {DateTime.Now.ToString(" yyyy - MM - dd ")} {model.ShiftUserName}).xlsx" ) ) ;
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
Response . AddHeader ( "Content-Length" , filet . Length . ToString ( ) ) ;
// 指定返回的是一个不能被客户端读取的流,必须被下载
Response . ContentType = "application/ms-excel" ;
// 把文件流发送到客户端
Response . WriteFile ( filet . FullName ) ;
// 停止页面的执行
Response . End ( ) ;
}
}
/// <summary>
///右击修改
/// </summary>
protected void btnMenuModify_Click ( object sender , EventArgs e )
{
btnModify_Click ( null , null ) ;
}
#endregion
#region 私 有 方 法
/// <summary>
/// 创建样式
/// </summary>
/// <returns></returns>
public static ICellStyle SetExcelStyle ( XSSFWorkbook wb , BorderStyle Bottom , BorderStyle Left , BorderStyle Right , BorderStyle Top , VerticalAlignment VerAig , HorizontalAlignment HorAig , double FontSize , bool WrapText = true , bool Bold = false , string FontName = "宋体" )
{
ICellStyle style = wb . CreateCellStyle ( ) ;
style . BorderBottom = Bottom ;
style . BorderLeft = Left ;
style . BorderRight = Right ;
style . BorderTop = Top ;
style . VerticalAlignment = VerAig ;
style . Alignment = HorAig ;
IFont font = wb . CreateFont ( ) ;
font . FontHeightInPoints = FontSize ;
font . IsBold = Bold ;
font . FontName = FontName ;
style . SetFont ( font ) ;
style . WrapText = WrapText ;
return style ;
}
/// <summary>
/// 创建头部
/// </summary>
/// <returns></returns>
private XSSFSheet ExcelCreateRowTitle ( XSSFSheet ws , XSSFWorkbook hssfworkbook , ICellStyle style , int sRows , int eRows , int cStart , int cEnd , float height = 21 )
{
for ( int i = sRows ; i < = eRows ; i + + )
{
ws . CreateRow ( i ) ;
ws . GetRow ( i ) . HeightInPoints = height ;
for ( int j = cStart ; j < = cEnd ; j + + )
{
ws . GetRow ( i ) . CreateCell ( j ) ;
ws . GetRow ( i ) . CreateCell ( j ) . CellStyle = style ;
}
}
return ws ;
}
#endregion
}
}