607 lines
34 KiB
C#
607 lines
34 KiB
C#
|
using BLL;
|
|||
|
using NPOI.SS.UserModel;
|
|||
|
using NPOI.SS.Util;
|
|||
|
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;
|
|||
|
|
|||
|
namespace FineUIPro.Web.ContinuousPrint
|
|||
|
{
|
|||
|
public partial class WeldingRecordPrint : PageBase
|
|||
|
{
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 绑定Grid1
|
|||
|
/// <summary>
|
|||
|
/// 绑定Grid1
|
|||
|
/// </summary>
|
|||
|
public void BindGrid()
|
|||
|
{
|
|||
|
var project = BLL.Base_ProjectService.GetOnProjectListByUserId(this.CurrUser.UserId, "1");
|
|||
|
if (!string.IsNullOrEmpty(txtProjectCode.Text))
|
|||
|
{
|
|||
|
project = project.Where(e => e.ProjectCode.Contains(txtProjectCode.Text.Trim())).ToList();
|
|||
|
}
|
|||
|
Grid1.RecordCount = project.Count;
|
|||
|
var table = this.GetPagedDataTable(Grid1, project);
|
|||
|
Grid1.DataSource = table;
|
|||
|
Grid1.DataBind();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 绑定Grid2
|
|||
|
/// <summary>
|
|||
|
/// 绑定Grid2
|
|||
|
/// </summary>
|
|||
|
public void BindGrid1(string ProjectId)
|
|||
|
{
|
|||
|
string strSql = @"select a.ISO_ID,a.ISO_IsoNo,b.ProjectCode,b.ProjectName,b.ShortName,b.StartDate,b.EndDate from HJGL_PW_IsoInfo as a inner join Base_Project as b on a.ProjectId=b.ProjectId where a.ProjectId= @ProjectId";
|
|||
|
List<SqlParameter> listStr = new List<SqlParameter>();
|
|||
|
listStr.Add(new SqlParameter("@ProjectId", ProjectId));
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
Grid2.DataSource = SQLHelper.GetDataTableRunText(strSql, parameter);
|
|||
|
Grid2.DataBind();
|
|||
|
Grid2.SelectAllRows();
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 分页、排序
|
|||
|
/// <summary>
|
|||
|
/// 分页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageIndex = e.NewPageIndex;
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分页显示条数下拉框
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 排序
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_Sort(object sender, FineUIPro.GridSortEventArgs e)
|
|||
|
{
|
|||
|
Grid1.SortDirection = e.SortDirection;
|
|||
|
Grid1.SortField = e.SortField;
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 选择加载
|
|||
|
/// <summary>
|
|||
|
/// 选择加载
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Grid1_RowClick(object sender, GridRowClickEventArgs e)
|
|||
|
{
|
|||
|
BindGrid1(this.Grid1.SelectedRowID);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 私有方法
|
|||
|
/// <summary>
|
|||
|
/// 得到热处理类型
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
protected string ConvertProessTypes(object ProessTypes)
|
|||
|
{
|
|||
|
string proessTypes = string.Empty;
|
|||
|
if (ProessTypes != null)
|
|||
|
{
|
|||
|
proessTypes = BLL.HJGL_PW_JointInfoService.ConvertProessTypes(ProessTypes.ToString());
|
|||
|
}
|
|||
|
|
|||
|
return proessTypes;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 关闭弹出窗口
|
|||
|
/// <summary>
|
|||
|
/// 关闭窗口
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void Window1_Close(object sender, EventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 查询
|
|||
|
/// <summary>
|
|||
|
/// 查询
|
|||
|
/// </summary>
|
|||
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
BindGrid();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 打印焊接记录打印
|
|||
|
/// <summary>
|
|||
|
/// 打印焊接记录打印
|
|||
|
/// </summary>
|
|||
|
protected void btnWeldingRecord_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Grid2.SelectedRowIndexArray.Length <= 0)
|
|||
|
{
|
|||
|
Alert.ShowInTop("最少选中一行!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
string rootPath = Server.MapPath("~/") + Const.ExcelUrl;
|
|||
|
//导出文件
|
|||
|
string filePath = rootPath + DateTime.Now.ToString("yyyyMMddhhmmss") + "\\";
|
|||
|
if (!Directory.Exists(filePath))
|
|||
|
{
|
|||
|
Directory.CreateDirectory(filePath);
|
|||
|
}
|
|||
|
string ReportFileName = filePath + "out.xlsx";
|
|||
|
if (Grid2.Rows.Count > 0)
|
|||
|
{
|
|||
|
int rowIndex = 0;
|
|||
|
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
|
|||
|
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("焊接工作记录");
|
|||
|
|
|||
|
#region 列宽
|
|||
|
ws.SetColumnWidth(0, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(1, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(2, (7 * 256) - 95);//(6.08)6.08
|
|||
|
ws.SetColumnWidth(3, (11 * 256) - 95);//(10.08)10.08
|
|||
|
ws.SetColumnWidth(4, (15 * 256) - 15);//(14.33)14.25
|
|||
|
ws.SetColumnWidth(5, (21 * 256) + 15);//(20.55)20.5
|
|||
|
ws.SetColumnWidth(6, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(7, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(8, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(9, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(10, (9 * 256) - 95);//(8.08)8.08
|
|||
|
ws.SetColumnWidth(11, (5 * 256) + 100);//(4.83)4.83
|
|||
|
ws.SetColumnWidth(12, (13 * 256) + 200);//(12.17)12.17
|
|||
|
#endregion
|
|||
|
|
|||
|
for (int gi = 0; gi < Grid2.Rows.Count; gi++)
|
|||
|
{
|
|||
|
if (Grid2.SelectedRowIndexArray.Contains(gi))
|
|||
|
{
|
|||
|
System.Web.UI.WebControls.HiddenField hidISO_ID = Grid2.Rows[gi].FindControl("hidISO_ID") as System.Web.UI.WebControls.HiddenField;
|
|||
|
System.Web.UI.WebControls.HiddenField hidProjectName = Grid2.Rows[gi].FindControl("hidProjectName") as System.Web.UI.WebControls.HiddenField;
|
|||
|
var listStr = new List<SqlParameter>();
|
|||
|
listStr.Add(new SqlParameter("@IsoId", hidISO_ID.Value));
|
|||
|
listStr.Add(new SqlParameter("@Flag", "0"));
|
|||
|
SqlParameter[] parameter = listStr.ToArray();
|
|||
|
var tb = SQLHelper.GetDataTableRunProc("HJGL_spJointWorkRecordNew", parameter);
|
|||
|
if (tb.Rows.Count > 0)
|
|||
|
{
|
|||
|
CellRangeAddress region;
|
|||
|
//尾页面总数
|
|||
|
var pageNum = 0d;
|
|||
|
//尾部增加行
|
|||
|
var endaddNum = 0;
|
|||
|
//公共样式
|
|||
|
ICellStyle style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true);
|
|||
|
//文字靠左左侧无边框
|
|||
|
ICellStyle styleFontLeft = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true);
|
|||
|
//文字靠左右边无边框
|
|||
|
ICellStyle styleRightNoneFontLeft = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true);
|
|||
|
//头部样式
|
|||
|
ICellStyle styleTou = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true);
|
|||
|
//计算页
|
|||
|
pageNum =
|
|||
|
tb.Rows.Count <= 11 ? 1
|
|||
|
: (tb.Rows.Count > 11 && tb.Rows.Count <= 27) ? 2
|
|||
|
: Math.Ceiling((float)(tb.Rows.Count - 27) / 16) + 2;
|
|||
|
//循环页
|
|||
|
for (int i = 1; i <= pageNum; i++)
|
|||
|
{
|
|||
|
//取数据开始和结束条数
|
|||
|
var dStart = 0;
|
|||
|
var dEnd = 0;
|
|||
|
//excel数据开始行和结束行
|
|||
|
var tStart = 0;
|
|||
|
var tEnd = 0;
|
|||
|
|
|||
|
#region 头部和每页数据参数
|
|||
|
//第一页和第二页需要创建头
|
|||
|
if (i == 1)
|
|||
|
{
|
|||
|
//尾部增加行
|
|||
|
endaddNum = 8;
|
|||
|
//创建头部行和列
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, rowIndex, rowIndex + 2, style, 0, 12);
|
|||
|
//取数据开始和结束条数
|
|||
|
dStart = 0;
|
|||
|
dEnd = 11;
|
|||
|
//excel数据开始行和结束行
|
|||
|
tStart = rowIndex + 3;
|
|||
|
tEnd = rowIndex + 13;
|
|||
|
|
|||
|
#region 头部
|
|||
|
//行1
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex + 1, 0, 2);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3503-J415-1");
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex + 1, 3, 8);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(3).SetCellValue("管道焊接工作记录");
|
|||
|
ws.GetRow(rowIndex).GetCell(3).CellStyle = styleTou;
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex, 9, 10);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(9).SetCellValue("工程名称:");
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex, 11, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(10).CellStyle = styleRightNoneFontLeft;
|
|||
|
ws.GetRow(rowIndex).GetCell(11).SetCellValue(hidProjectName.Value);
|
|||
|
ws.GetRow(rowIndex).GetCell(11).CellStyle = styleFontLeft;
|
|||
|
//行2
|
|||
|
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 9, 10);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("单位工程名称:");
|
|||
|
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 11, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(10).CellStyle = styleRightNoneFontLeft;
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(11).SetCellValue("管道");
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(11).CellStyle = styleFontLeft;
|
|||
|
//行3
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("管道编号/单线号");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 0, 1);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("焊口\n编号");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(3).SetCellValue("焊工\n代号");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(4).SetCellValue("规格\nmm");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(5).SetCellValue("材质");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(6).SetCellValue("焊接位置");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(7).SetCellValue("焊接方法");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(8).SetCellValue("焊材牌号");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue("实际预热\n温度℃");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 10, 11);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(12).SetCellValue("焊接日期");
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//尾部增加行
|
|||
|
endaddNum = 2;
|
|||
|
//创建头部行和列
|
|||
|
ws = ExcelCreateRowTitle(ws, hssfworkbook, rowIndex, rowIndex + 3, style, 0, 12);
|
|||
|
var pNum = (i - 1) * 16;
|
|||
|
//取数据开始和结束条数
|
|||
|
dStart = 11 + ((i - 2) * 16);
|
|||
|
dEnd = 11 + pNum;
|
|||
|
//excel数据开始行和结束行
|
|||
|
tStart = rowIndex + 3;
|
|||
|
tEnd = rowIndex + 18;
|
|||
|
|
|||
|
#region 头部(续)
|
|||
|
//行1
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex + 1, 0, 2);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3503-J415-2");
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex + 1, 3, 8);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(3).SetCellValue("管道焊接工作记录(续)");
|
|||
|
ws.GetRow(rowIndex).GetCell(3).CellStyle = styleTou;
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex, 9, 10);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(9).SetCellValue("工程名称:");
|
|||
|
region = new CellRangeAddress(rowIndex, rowIndex, 11, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex).GetCell(10).CellStyle = styleRightNoneFontLeft;
|
|||
|
ws.GetRow(rowIndex).GetCell(11).SetCellValue(hidProjectName.Value);
|
|||
|
ws.GetRow(rowIndex).GetCell(11).CellStyle = styleFontLeft;
|
|||
|
//行2
|
|||
|
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 9, 10);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(9).SetCellValue("单位工程名称:");
|
|||
|
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 11, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(10).CellStyle = styleRightNoneFontLeft;
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(11).SetCellValue("管道");
|
|||
|
ws.GetRow(rowIndex + 1).GetCell(11).CellStyle = styleFontLeft;
|
|||
|
//行3
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(0).SetCellValue("管道编号/单线号");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 0, 1);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(2).SetCellValue("焊口\n编号");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(3).SetCellValue("焊工\n代号");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(4).SetCellValue("规格\nmm");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(5).SetCellValue("材质");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(6).SetCellValue("焊接位置");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(7).SetCellValue("焊接方法");
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(8).SetCellValue("焊材牌号");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue("实际预热\n温度℃");
|
|||
|
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 10, 11);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(rowIndex + 2).GetCell(12).SetCellValue("焊接日期");
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 数据
|
|||
|
//创建数据行和列
|
|||
|
ws = ExcelCreateRow(ws, hssfworkbook, tStart, tEnd, style, 0, 12);
|
|||
|
//获取当前页数据
|
|||
|
var pageTb = GetPageToTable(tb, dStart, dEnd);
|
|||
|
//遍历数据
|
|||
|
for (int j = 0; j < pageTb.Rows.Count; j++)
|
|||
|
{
|
|||
|
int dataRow = tStart + j;
|
|||
|
ws.GetRow(dataRow).GetCell(0).SetCellValue(pageTb.Rows[j]["ISO_IsoNo"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(2).SetCellValue(pageTb.Rows[j]["JOT_JointNo"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(3).SetCellValue(pageTb.Rows[j]["WED_Code"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(4).SetCellValue(pageTb.Rows[j]["JOT_JointDesc"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(5).SetCellValue(pageTb.Rows[j]["STE_Code"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(6).SetCellValue(pageTb.Rows[j]["weldLocal"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(7).SetCellValue(pageTb.Rows[j]["WME_Name"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(8).SetCellValue(pageTb.Rows[j]["WMT_MatName"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(10).SetCellValue(pageTb.Rows[j]["JOT_PrepareTemp"].ToString());
|
|||
|
ws.GetRow(dataRow).GetCell(12).SetCellValue(pageTb.Rows[j]["WeldDate"].ToString());
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 尾部
|
|||
|
if (i == 1)
|
|||
|
{
|
|||
|
//尾部样式无线条
|
|||
|
ICellStyle noneStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10);
|
|||
|
int ej = 0;
|
|||
|
//创建尾部
|
|||
|
ws.CreateRow(tEnd + 1);
|
|||
|
ws.CreateRow(tEnd + 1).HeightInPoints = 21f;
|
|||
|
ws.CreateRow(tEnd + 2);
|
|||
|
ws.CreateRow(tEnd + 2).HeightInPoints = 21f;
|
|||
|
ws.CreateRow(tEnd + 3);
|
|||
|
ws.CreateRow(tEnd + 3).HeightInPoints = 21f;
|
|||
|
ws.CreateRow(tEnd + 4);
|
|||
|
ws.CreateRow(tEnd + 4).HeightInPoints = 21f;
|
|||
|
ws.CreateRow(tEnd + 5);
|
|||
|
ws.CreateRow(tEnd + 5).HeightInPoints = 21f;
|
|||
|
for (int eIndex = 0; eIndex <= 12; eIndex++)
|
|||
|
{
|
|||
|
//行1
|
|||
|
ws.GetRow(tEnd + 1).CreateCell(eIndex);
|
|||
|
ws.GetRow(tEnd + 1).GetCell(eIndex).CellStyle = style;
|
|||
|
//行2
|
|||
|
ws.GetRow(tEnd + 2).CreateCell(eIndex);
|
|||
|
ws.GetRow(tEnd + 2).GetCell(eIndex).CellStyle = noneStyle;
|
|||
|
//行3
|
|||
|
ws.GetRow(tEnd + 3).CreateCell(eIndex);
|
|||
|
ws.GetRow(tEnd + 3).GetCell(eIndex).CellStyle = noneStyle;
|
|||
|
//行4
|
|||
|
ws.GetRow(tEnd + 4).CreateCell(eIndex);
|
|||
|
ws.GetRow(tEnd + 4).GetCell(eIndex).CellStyle = noneStyle;
|
|||
|
//行5
|
|||
|
ws.GetRow(tEnd + 5).CreateCell(eIndex); ej++;
|
|||
|
}
|
|||
|
//尾部样式左侧线文字靠右
|
|||
|
ICellStyle leftStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10);
|
|||
|
//尾部样式左侧线文字居中
|
|||
|
ICellStyle createStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10);
|
|||
|
//尾部样式右侧线条文字靠右
|
|||
|
ICellStyle rightStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10);
|
|||
|
//尾部样式左下线文字靠右
|
|||
|
ICellStyle leftBottStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10);
|
|||
|
//尾部样式右下线条文字靠右
|
|||
|
ICellStyle rightBottStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Right, 10);
|
|||
|
|
|||
|
//尾部行1
|
|||
|
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 0, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 1).GetCell(0).SetCellValue("建设/监理单位");
|
|||
|
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 4, 7);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 1).GetCell(4).SetCellValue("总承包单位");
|
|||
|
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 8, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 1).GetCell(8).SetCellValue("施工单位");
|
|||
|
//尾部行2
|
|||
|
ws.GetRow(tEnd + 2).GetCell(0).SetCellValue("专业工程师:");
|
|||
|
ws.GetRow(tEnd + 2).GetCell(0).CellStyle = createStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 2, tEnd + 2, 0, 1);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 2).GetCell(4).SetCellValue("专业工程师:");
|
|||
|
ws.GetRow(tEnd + 2).GetCell(4).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 2, tEnd + 2, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 2).GetCell(8).SetCellValue("记录人:");
|
|||
|
ws.GetRow(tEnd + 2).GetCell(8).CellStyle = leftStyle;
|
|||
|
ws.GetRow(tEnd + 2).GetCell(12).CellStyle = rightStyle;
|
|||
|
//尾部行3
|
|||
|
ws.GetRow(tEnd + 3).GetCell(0).CellStyle = leftStyle;
|
|||
|
ws.GetRow(tEnd + 3).GetCell(4).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 3, tEnd + 3, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 3).GetCell(8).SetCellValue("质量检查员:");
|
|||
|
ws.GetRow(tEnd + 3).GetCell(8).CellStyle = leftStyle;
|
|||
|
ws.GetRow(tEnd + 3).GetCell(12).CellStyle = rightStyle;
|
|||
|
//尾部行4
|
|||
|
ws.GetRow(tEnd + 4).GetCell(0).CellStyle = leftStyle;
|
|||
|
ws.GetRow(tEnd + 4).GetCell(4).CellStyle = leftStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 4, tEnd + 4, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 4).GetCell(8).SetCellValue("焊接责任工程师:");
|
|||
|
ws.GetRow(tEnd + 4).GetCell(8).CellStyle = leftStyle;
|
|||
|
ws.GetRow(tEnd + 4).GetCell(12).CellStyle = rightStyle;
|
|||
|
//尾部行5
|
|||
|
ws.GetRow(tEnd + 5).GetCell(0).SetCellValue("日期:");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(0).CellStyle = leftBottStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 5, tEnd + 5, 1, 3);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 5).GetCell(1).SetCellValue("年 月 日");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(1).CellStyle = ws.GetRow(tEnd + 5).GetCell(2).CellStyle = ws.GetRow(tEnd + 5).GetCell(3).CellStyle = rightBottStyle;
|
|||
|
|
|||
|
ws.GetRow(tEnd + 5).GetCell(4).SetCellValue("日期:");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(4).CellStyle = leftBottStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 5, tEnd + 5, 5, 7);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 5).GetCell(5).SetCellValue(" 年 月 日");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(5).CellStyle = ws.GetRow(tEnd + 5).GetCell(6).CellStyle = ws.GetRow(tEnd + 5).GetCell(7).CellStyle = rightBottStyle;
|
|||
|
|
|||
|
region = new CellRangeAddress(tEnd + 5, tEnd + 5, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 5).GetCell(8).SetCellValue("日期:");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(8).CellStyle = ws.GetRow(tEnd + 5).GetCell(9).CellStyle = leftBottStyle;
|
|||
|
region = new CellRangeAddress(tEnd + 5, tEnd + 5, 10, 12);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
ws.GetRow(tEnd + 5).GetCell(10).SetCellValue("年 月 日");
|
|||
|
ws.GetRow(tEnd + 5).GetCell(10).CellStyle = ws.GetRow(tEnd + 5).GetCell(11).CellStyle = ws.GetRow(tEnd + 5).GetCell(12).CellStyle = rightBottStyle;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
rowIndex = tEnd + endaddNum;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
ws.SetMargin(MarginType.LeftMargin, 0.6);
|
|||
|
ws.SetMargin(MarginType.RightMargin, 0.2);
|
|||
|
//ws.SetMargin(MarginType.BottomMargin, 1);
|
|||
|
//ws.SetMargin(MarginType.TopMargin, 1);
|
|||
|
ws.PrintSetup.Landscape = true;
|
|||
|
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("管道焊接记录.xlsx"));
|
|||
|
// 添加头信息,指定文件大小,让浏览器能够显示下载进度
|
|||
|
Response.AddHeader("Content-Length", filet.Length.ToString());
|
|||
|
// 指定返回的是一个不能被客户端读取的流,必须被下载
|
|||
|
Response.ContentType = "application/ms-excel";
|
|||
|
// 把文件流发送到客户端
|
|||
|
Response.WriteFile(filet.FullName);
|
|||
|
// 停止页面的执行
|
|||
|
Response.End();
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 私有方法
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 行和列
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
private XSSFSheet ExcelCreateRowTitle(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd)
|
|||
|
{
|
|||
|
for (int i = sRows; i <= eRows; i++)
|
|||
|
{
|
|||
|
ws.CreateRow(i);
|
|||
|
ws.GetRow(i).HeightInPoints = i == sRows ? 30
|
|||
|
: i == (sRows + 1) ? 27 :
|
|||
|
i == (sRows + 2) ? 28 : 24;
|
|||
|
|
|||
|
for (int j = cStart; j <= cEnd; j++)
|
|||
|
{
|
|||
|
ws.GetRow(i).CreateCell(j);
|
|||
|
ws.GetRow(i).GetCell(j).CellStyle = style;
|
|||
|
}
|
|||
|
}
|
|||
|
return ws;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 数据行
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
private XSSFSheet ExcelCreateRow(XSSFSheet ws, XSSFWorkbook hssfworkbook, int sRows, int eRows, ICellStyle style, int cStart, int cEnd)
|
|||
|
{
|
|||
|
CellRangeAddress region;
|
|||
|
for (int i = sRows; i <= eRows; i++)
|
|||
|
{
|
|||
|
ws.CreateRow(i);
|
|||
|
ws.GetRow(i).HeightInPoints = 24f;
|
|||
|
for (int j = cStart; j <= cEnd; j++)
|
|||
|
{
|
|||
|
ws.GetRow(i).CreateCell(j);
|
|||
|
ws.GetRow(i).GetCell(j).CellStyle = style;
|
|||
|
}
|
|||
|
region = new CellRangeAddress(i, i, 0, 1);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
region = new CellRangeAddress(i, i, 8, 9);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
region = new CellRangeAddress(i, i, 10, 11);
|
|||
|
ws.AddMergedRegion(region);
|
|||
|
|
|||
|
}
|
|||
|
return ws;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 查询指定条数分页
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
public static DataTable GetPageToTable(DataTable dt, int StartNum, int EndNum)
|
|||
|
{
|
|||
|
//0页代表每页数据,直接返回
|
|||
|
if (EndNum == 0) return dt;
|
|||
|
//数据源为空返回空DataTable
|
|||
|
if (dt == null) return new DataTable();
|
|||
|
|
|||
|
DataTable newdt = dt.Copy();
|
|||
|
newdt.Clear();//copy dt的框架
|
|||
|
|
|||
|
if (StartNum >= dt.Rows.Count)
|
|||
|
return newdt;//源数据记录数小于等于要显示的记录,直接返回dt
|
|||
|
|
|||
|
if (EndNum > dt.Rows.Count)
|
|||
|
EndNum = dt.Rows.Count;
|
|||
|
for (int i = StartNum; i <= EndNum - 1; i++)
|
|||
|
{
|
|||
|
DataRow newdr = newdt.NewRow();
|
|||
|
DataRow dr = dt.Rows[i];
|
|||
|
foreach (DataColumn column in dt.Columns)
|
|||
|
{
|
|||
|
newdr[column.ColumnName] = dr[column.ColumnName];
|
|||
|
}
|
|||
|
newdt.Rows.Add(newdr);
|
|||
|
}
|
|||
|
return newdt;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|