ZHJA_HJGL/HJGL_ZH/FineUIPro.Web/ContinuousPrint/HardnessTestReportPrint.asp...

697 lines
41 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 HardnessTestReportPrint : 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)
{
var str = string.Empty;
//是否打印
if (!string.IsNullOrEmpty(this.drpIsPrint.SelectedValue))
{
str += " and a.IsPrintReport=" + this.drpIsPrint.SelectedValue + "";
}
string strSql = @"select a.HardTestReportId,a.HardTestReportCode,a.ProjectId,b.ProjectName,a.ISO_ID,a.TestDate,a.InstrumentType,a.TestStandard,a.HotHardCode,a.HotProessState,a.SurfaceAppearance,a.TestMethod,a.MaterialStandard,a.TestRate,a.ContractUnit,(case a.IsPrintReport when 1 then '已打印' else '未打印' end) as IsPrintReportName from HJGL_CH_HardTestReport as a inner join Base_Project as b on a.ProjectId=b.ProjectId WHERE a.ProjectId= @ProjectId" + str;
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>
/// <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();
}
/// <summary>
/// 是否打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drpIsPrint_SelectedIndexChanged(object sender, EventArgs e)
{
BindGrid1(this.Grid1.SelectedRowID);
}
#endregion
#region
/// <summary>
/// 硬度检测报告
/// </summary>
protected void btnPrint_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 + "out1.xlsx";
if (Grid2.Rows.Count > 0)
{
int rowIndex = 0;
XSSFWorkbook hssfworkbook = new XSSFWorkbook();
XSSFSheet ws = (XSSFSheet)hssfworkbook.CreateSheet("项目管理管线单线图附页");
#region
ws.SetColumnWidth(0, (11 * 256) + 200);//(10.17)10.18
ws.SetColumnWidth(1, (4 * 256) + 15);//(3.5)3.55
ws.SetColumnWidth(2, (12 * 256) + 55);//(11.67)11.64
ws.SetColumnWidth(3, (3 * 256) + 55);//(2.67)2.64
ws.SetColumnWidth(4, (2 * 256) + 120);//(1.92)1.91
ws.SetColumnWidth(5, (5 * 256) + 100);//(4.83)4.82
ws.SetColumnWidth(6, (3 * 256) + 15);//(2.5)2.55
ws.SetColumnWidth(7, (3 * 256) + 100);//(2.83)2.82
ws.SetColumnWidth(8, 256 + 15);//(0.5)0.5
ws.SetColumnWidth(9, (9 * 256) + 15);//(8.5)8.55
ws.SetColumnWidth(10, (3 * 256) + 200);//(3.17)3.18
ws.SetColumnWidth(11, (10 * 256) - 15);//(9.33)9.36
ws.SetColumnWidth(12, (3 * 256) + 100);//(2.83)2.82
ws.SetColumnWidth(13, (13 * 256) + 15);//(12.5)12.55
#endregion
for (int gi = 0; gi < Grid2.Rows.Count; gi++)
{
if (Grid2.SelectedRowIndexArray.Contains(gi))
{
System.Web.UI.WebControls.HiddenField hidHardTestReportId = Grid2.Rows[gi].FindControl("hidHardTestReportId") as System.Web.UI.WebControls.HiddenField;
//打印赋值
Model.HJGL_CH_HardTestReport report = BLL.HJGL_CH_HardTestReportService.GetCH_HardTestReportByID(hidHardTestReportId.Value);
if (report != null)
{
report.IsPrintReport = true;
report.PrintTrustDate = DateTime.Now;
report.TrustName = report.HotHardCode + "-" + string.Format("{0:yyyy-MM-dd}", DateTime.Now);
BLL.HJGL_CH_HardTestReportService.UpdateCH_HardTestReport(report);
}
//头部
var listTitleStr = new List<SqlParameter>();
listTitleStr.Add(new SqlParameter("@HardTestReportId", hidHardTestReportId.Value));
SqlParameter[] titleparameter = listTitleStr.ToArray();
var tbTitle = SQLHelper.GetDataTableRunProc("HJGL_spCH_HardTestReport", titleparameter);
//列表
var listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@HardTestReportId", hidHardTestReportId.Value));
listStr.Add(new SqlParameter("@Flag", "0"));
SqlParameter[] parameter = listStr.ToArray();
var tb = SQLHelper.GetDataTableRunProc("HJGL_spCH_HardTestReportItem", parameter);
if (tb.Rows.Count > 0 && tbTitle.Rows.Count > 0)
{
CellRangeAddress region;
var pageNum =
tb.Rows.Count < 18 ? 1
: Math.Ceiling((float)(tb.Rows.Count - 18) / 21) + 1;
//公共样式
ICellStyle style = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true);
//页码样式
ICellStyle pageStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 7, true);
//文字靠左
ICellStyle leftStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true);
//头部样式
ICellStyle titleStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Center, 16, true, true);
//循环页
for (int i = 1; i <= pageNum; i++)
{
#region
//创建头部行和列
ws = ExcelCreateRowTitle(ws, hssfworkbook, rowIndex, rowIndex + 8, style, 0, 13);
//行1
region = new CellRangeAddress(rowIndex, rowIndex + 3, 0, 1);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(0).SetCellValue("SH/T 3503-J130");
region = new CellRangeAddress(rowIndex, rowIndex + 2, 2, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(2).SetCellValue("硬度检测报告");
ws.GetRow(rowIndex).GetCell(2).CellStyle = titleStyle;
region = new CellRangeAddress(rowIndex, rowIndex, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(10).SetCellValue("工程名称:");
ws.GetRow(rowIndex).GetCell(10).CellStyle = leftStyle;
region = new CellRangeAddress(rowIndex, rowIndex, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex).GetCell(12).SetCellValue(tbTitle.Rows[0]["ProjectName"].ToString());
//行2
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(10).SetCellValue("(施工号):");
ws.GetRow(rowIndex + 1).GetCell(10).CellStyle = leftStyle;
region = new CellRangeAddress(rowIndex + 1, rowIndex + 1, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 1).GetCell(12).SetCellValue(tbTitle.Rows[0]["ProjectCode"].ToString());
//行3
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(10).SetCellValue("单位工程名称:");
ws.GetRow(rowIndex + 2).GetCell(10).CellStyle = leftStyle;
region = new CellRangeAddress(rowIndex + 2, rowIndex + 2, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 2).GetCell(12).SetCellValue("");
//行4
ws.GetRow(rowIndex + 3).GetCell(3).SetCellValue("第");
ws.GetRow(rowIndex + 3).GetCell(4).SetCellValue(i);
ws.GetRow(rowIndex + 3).GetCell(5).SetCellValue("页 共");
ws.GetRow(rowIndex + 3).GetCell(6).SetCellValue(pageNum);
ws.GetRow(rowIndex + 3).GetCell(7).SetCellValue("页");
ws.GetRow(rowIndex + 3).GetCell(3).CellStyle =
ws.GetRow(rowIndex + 3).GetCell(4).CellStyle =
ws.GetRow(rowIndex + 3).GetCell(5).CellStyle =
ws.GetRow(rowIndex + 3).GetCell(6).CellStyle =
ws.GetRow(rowIndex + 3).GetCell(7).CellStyle = pageStyle;
//行5
ws.GetRow(rowIndex + 4).GetCell(0).SetCellValue("委托单位");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(1).SetCellValue(tbTitle.Rows[0]["TrustUnitName"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 4, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(4).SetCellValue("施工单位");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 7, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(7).SetCellValue(tbTitle.Rows[0]["ContractUnitName"].ToString());
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(10).SetCellValue("报告编号");
region = new CellRangeAddress(rowIndex + 4, rowIndex + 4, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 4).GetCell(12).SetCellValue(tbTitle.Rows[0]["HardTestReportCode"].ToString());
//行6
ws.GetRow(rowIndex + 5).GetCell(0).SetCellValue("检件名称");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(1).SetCellValue(tbTitle.Rows[0]["ISO_IsoNo"].ToString());
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 4, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(4).SetCellValue("检测标准");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 7, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(7).SetCellValue(tbTitle.Rows[0]["TestStandard"].ToString());
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(10).SetCellValue("验收标准");
region = new CellRangeAddress(rowIndex + 5, rowIndex + 5, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 5).GetCell(12).SetCellValue(tbTitle.Rows[0]["MaterialStandard"].ToString());
//行7
ws.GetRow(rowIndex + 6).GetCell(0).SetCellValue("检件规格");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(1).SetCellValue("见检验部位编号");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 4, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(4).SetCellValue("检件材质");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 7, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(7).SetCellValue(tbTitle.Rows[0]["STE_Code"].ToString());
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(10).SetCellValue("检测比例");
region = new CellRangeAddress(rowIndex + 6, rowIndex + 6, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 6).GetCell(12).SetCellValue(tbTitle.Rows[0]["TestRate"].ToString());
//行8
ws.GetRow(rowIndex + 7).GetCell(0).SetCellValue("检测方法");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 1, 3);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(1).SetCellValue(tbTitle.Rows[0]["TestMethod"].ToString());
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 4, 6);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(4).SetCellValue("热处理状态");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 7, 9);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(7).SetCellValue(tbTitle.Rows[0]["HotProessState"].ToString());
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 10, 11);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(10).SetCellValue("设备型号");
region = new CellRangeAddress(rowIndex + 7, rowIndex + 7, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 7).GetCell(12).SetCellValue(tbTitle.Rows[0]["EquipmentId"].ToString());
//行9
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 0, 1);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(0).SetCellValue("检测部位编号");
ws.GetRow(rowIndex + 8).GetCell(2).SetCellValue("硬度值HB");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 3, 8);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(3).SetCellValue("检测部位编号");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 9, 10);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(9).SetCellValue("硬度值HB");
region = new CellRangeAddress(rowIndex + 8, rowIndex + 8, 11, 12);
ws.AddMergedRegion(region);
ws.GetRow(rowIndex + 8).GetCell(11).SetCellValue("检测部位编号");
ws.GetRow(rowIndex + 8).GetCell(13).SetCellValue("硬度值HB");
#endregion
//EXCEL每页数据开始和结束条数
var dStart = i == 1 ? 0 : (18 + ((i - 2) * 21));
var dEnd = i == 1 ? 18 : (18 + ((i - 1) * 21));
//取数据开始行和结束行
var tStart = rowIndex + 9;
var tEnd = rowIndex + (i == 1 ? 26 : 29);
#region
//创建数据行和列
ws = ExcelCreateRow(ws, hssfworkbook, tStart, tEnd, style, 0, 13);
//获取当前页数据
var pageTb = GetPageToTable(tb, dStart, dEnd);
//遍历数据
bool dbNum = true;
for (int j = 0; j < pageTb.Rows.Count; j++)
{
dbNum = (j == 0 || ((float)j % 3) == 0) ? true : false;
var dataRow = tStart + j;
if (dbNum)
{
ws.GetRow(dataRow).GetCell(0).SetCellValue(pageTb.Rows[j]["NewJOT_JointNoStr1"].ToString());//检测部位编号
ws.GetRow(dataRow).GetCell(3).SetCellValue(pageTb.Rows[j]["NewJOT_JointNoStr2"].ToString());//检测部位编号
ws.GetRow(dataRow).GetCell(11).SetCellValue(pageTb.Rows[j]["NewJOT_JointNoStr3"].ToString());//检测部位编号
}
ws.GetRow(dataRow).GetCell(2).SetCellValue(pageTb.Rows[j]["HardNessValue1"].ToString());//硬度值HB
ws.GetRow(dataRow).GetCell(9).SetCellValue(pageTb.Rows[j]["HardNessValue2"].ToString());//硬度值HB
ws.GetRow(dataRow).GetCell(13).SetCellValue(pageTb.Rows[j]["HardNessValue3"].ToString());//硬度值HB
}
#endregion
#region
//尾部页码
ws.CreateRow(tEnd + 1);
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
ws.CreateRow(tEnd + 2);
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
ws.CreateRow(tEnd + 3);
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
ws.CreateRow(tEnd + 4);
ws.GetRow(tEnd + 1).HeightInPoints = 21.8f;
//上无边框
ICellStyle topTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Center, 10, true, false, "楷体");
//下无边框
ICellStyle bottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false, "楷体");
//左下无边框
ICellStyle leftBottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.None, BorderStyle.Thin, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false, "楷体");
//右下无边框
ICellStyle rightBottTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false, "楷体");
//左上无边框
ICellStyle leftTopTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.None, BorderStyle.Thin, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false, "楷体");
//右上无边框
ICellStyle rightTopTailStyle = CommonPrint.SetExcelStyle(hssfworkbook, BorderStyle.Thin, BorderStyle.Thin, BorderStyle.None, BorderStyle.None, VerticalAlignment.Center, HorizontalAlignment.Left, 10, true, false, "楷体");
//生成列
for (int eIndex = 0; eIndex <= 13; eIndex++)
{
ws.GetRow(tEnd + 1).CreateCell(eIndex);
if (i == 1)
{
ws.GetRow(tEnd + 2).CreateCell(eIndex);
ws.GetRow(tEnd + 3).CreateCell(eIndex);
ws.GetRow(tEnd + 4).CreateCell(eIndex);
}
}
if (i == 1)
{
//尾部行1
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 0, 13);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 1).GetCell(0).CellStyle =
ws.GetRow(tEnd + 1).GetCell(1).CellStyle =
ws.GetRow(tEnd + 1).GetCell(2).CellStyle =
ws.GetRow(tEnd + 1).GetCell(3).CellStyle =
ws.GetRow(tEnd + 1).GetCell(4).CellStyle =
ws.GetRow(tEnd + 1).GetCell(5).CellStyle =
ws.GetRow(tEnd + 1).GetCell(6).CellStyle =
ws.GetRow(tEnd + 1).GetCell(7).CellStyle =
ws.GetRow(tEnd + 1).GetCell(8).CellStyle =
ws.GetRow(tEnd + 1).GetCell(9).CellStyle =
ws.GetRow(tEnd + 1).GetCell(10).CellStyle =
ws.GetRow(tEnd + 1).GetCell(11).CellStyle =
ws.GetRow(tEnd + 1).GetCell(12).CellStyle =
ws.GetRow(tEnd + 1).GetCell(13).CellStyle = bottTailStyle;
ws.GetRow(tEnd + 1).GetCell(0).SetCellValue("检测结论:");
//尾部行2
region = new CellRangeAddress(tEnd + 2, tEnd + 2, 0, 13);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 2).GetCell(0).CellStyle =
ws.GetRow(tEnd + 2).GetCell(0).CellStyle =
ws.GetRow(tEnd + 2).GetCell(1).CellStyle =
ws.GetRow(tEnd + 2).GetCell(2).CellStyle =
ws.GetRow(tEnd + 2).GetCell(3).CellStyle =
ws.GetRow(tEnd + 2).GetCell(4).CellStyle =
ws.GetRow(tEnd + 2).GetCell(5).CellStyle =
ws.GetRow(tEnd + 2).GetCell(6).CellStyle =
ws.GetRow(tEnd + 2).GetCell(7).CellStyle =
ws.GetRow(tEnd + 2).GetCell(8).CellStyle =
ws.GetRow(tEnd + 2).GetCell(9).CellStyle =
ws.GetRow(tEnd + 2).GetCell(10).CellStyle =
ws.GetRow(tEnd + 2).GetCell(11).CellStyle =
ws.GetRow(tEnd + 2).GetCell(12).CellStyle =
ws.GetRow(tEnd + 2).GetCell(13).CellStyle = topTailStyle;
ws.GetRow(tEnd + 2).GetCell(0).SetCellValue(tbTitle.Rows[0]["testResult"].ToString());
//尾部行3
ws.GetRow(tEnd + 3).GetCell(0).SetCellValue("试验人:");
ws.GetRow(tEnd + 3).GetCell(0).CellStyle = rightBottTailStyle;
region = new CellRangeAddress(tEnd + 3, tEnd + 3, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 3).GetCell(1).CellStyle =
ws.GetRow(tEnd + 3).GetCell(2).CellStyle = leftBottTailStyle;
ws.GetRow(tEnd + 3).GetCell(1).SetCellValue("");
region = new CellRangeAddress(tEnd + 3, tEnd + 3, 3, 5);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 3).GetCell(3).CellStyle =
ws.GetRow(tEnd + 3).GetCell(4).CellStyle =
ws.GetRow(tEnd + 3).GetCell(5).CellStyle = rightBottTailStyle;
ws.GetRow(tEnd + 3).GetCell(3).SetCellValue("审核人:");
region = new CellRangeAddress(tEnd + 3, tEnd + 3, 6, 10);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 3).GetCell(6).CellStyle =
ws.GetRow(tEnd + 3).GetCell(7).CellStyle =
ws.GetRow(tEnd + 3).GetCell(8).CellStyle =
ws.GetRow(tEnd + 3).GetCell(9).CellStyle =
ws.GetRow(tEnd + 3).GetCell(10).CellStyle = leftBottTailStyle;
ws.GetRow(tEnd + 3).GetCell(6).SetCellValue("");
region = new CellRangeAddress(tEnd + 3, tEnd + 3, 11, 13);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 3).GetCell(11).CellStyle =
ws.GetRow(tEnd + 3).GetCell(12).CellStyle =
ws.GetRow(tEnd + 3).GetCell(13).CellStyle = bottTailStyle;
ws.GetRow(tEnd + 3).GetCell(11).SetCellValue("检测单位:(公章)");
//尾部行4
ws.GetRow(tEnd + 4).GetCell(0).SetCellValue("资格:");
ws.GetRow(tEnd + 4).GetCell(0).CellStyle = rightTopTailStyle;
region = new CellRangeAddress(tEnd + 4, tEnd + 4, 1, 2);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 4).GetCell(1).SetCellValue("");
ws.GetRow(tEnd + 4).GetCell(1).CellStyle =
ws.GetRow(tEnd + 4).GetCell(2).CellStyle = leftTopTailStyle;
region = new CellRangeAddress(tEnd + 4, tEnd + 4, 3, 5);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 4).GetCell(3).SetCellValue("资格:");
ws.GetRow(tEnd + 4).GetCell(3).CellStyle =
ws.GetRow(tEnd + 4).GetCell(4).CellStyle =
ws.GetRow(tEnd + 4).GetCell(5).CellStyle = rightTopTailStyle;
region = new CellRangeAddress(tEnd + 4, tEnd + 4, 6, 10);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 4).GetCell(6).SetCellValue("");
ws.GetRow(tEnd + 4).GetCell(6).CellStyle =
ws.GetRow(tEnd + 4).GetCell(7).CellStyle =
ws.GetRow(tEnd + 4).GetCell(8).CellStyle =
ws.GetRow(tEnd + 4).GetCell(9).CellStyle =
ws.GetRow(tEnd + 4).GetCell(10).CellStyle = leftTopTailStyle;
ws.GetRow(tEnd + 4).GetCell(11).CellStyle = rightTopTailStyle;
ws.GetRow(tEnd + 4).GetCell(11).SetCellValue("报告日期:");
region = new CellRangeAddress(tEnd + 4, tEnd + 4, 12, 13);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 4).GetCell(12).CellStyle =
ws.GetRow(tEnd + 4).GetCell(13).CellStyle = leftTopTailStyle;
ws.GetRow(tEnd + 4).GetCell(12).SetCellValue("");
}
else
{
region = new CellRangeAddress(tEnd + 1, tEnd + 1, 0, 13);
ws.AddMergedRegion(region);
ws.GetRow(tEnd + 1).GetCell(0).SetCellValue(" 检测单位 (公章) ");
ws.GetRow(tEnd + 1).GetCell(0).CellStyle =
ws.GetRow(tEnd + 1).GetCell(1).CellStyle =
ws.GetRow(tEnd + 1).GetCell(2).CellStyle =
ws.GetRow(tEnd + 1).GetCell(3).CellStyle =
ws.GetRow(tEnd + 1).GetCell(4).CellStyle =
ws.GetRow(tEnd + 1).GetCell(5).CellStyle =
ws.GetRow(tEnd + 1).GetCell(6).CellStyle =
ws.GetRow(tEnd + 1).GetCell(7).CellStyle =
ws.GetRow(tEnd + 1).GetCell(8).CellStyle =
ws.GetRow(tEnd + 1).GetCell(9).CellStyle =
ws.GetRow(tEnd + 1).GetCell(10).CellStyle =
ws.GetRow(tEnd + 1).GetCell(11).CellStyle =
ws.GetRow(tEnd + 1).GetCell(12).CellStyle =
ws.GetRow(tEnd + 1).GetCell(13).CellStyle = style;
}
#endregion
rowIndex = tEnd + (i == 1 ? 10 : 5);
}
}
}
}
ws.SetMargin(MarginType.LeftMargin, 0.5);
ws.SetMargin(MarginType.RightMargin, 0.5);
//ws.SetMargin(MarginType.BottomMargin, 1);
//ws.SetMargin(MarginType.TopMargin, 1);
//ws.SetMargin(MarginType.FooterMargin, 0.5);
//ws.SetMargin(MarginType.HeaderMargin, 0.5);
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("项目管理管线单线图附页.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 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 = 21.8f;
for (int j = cStart; j <= cEnd; j++)
{
ws.GetRow(i).CreateCell(j);
ws.GetRow(i).GetCell(j).CellStyle = style;
}
}
//合并行和列
bool three = true;
int dRow = 0;
for (int k = sRows; k <= eRows; k++)
{
three = (dRow == 0 || ((float)dRow % 3) == 0) ? true : false;
if (three)
{
//合并数据
region = new CellRangeAddress(k, k + 2, 0, 1);
ws.AddMergedRegion(region);
region = new CellRangeAddress(k, k + 2, 3, 8);
ws.AddMergedRegion(region);
region = new CellRangeAddress(k, k, 9, 10);
ws.AddMergedRegion(region);
region = new CellRangeAddress(k, k + 2, 11, 12);
ws.AddMergedRegion(region);
}
else
{
region = new CellRangeAddress(k, k, 9, 10);
ws.AddMergedRegion(region);
}
dRow++;
}
return ws;
}
/// <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 ? 34.5f :
i == (sRows + 1) ? 23.3f :
i == (sRows + 2) ? 21.8f :
i == (sRows + 3) ? 12f :
i == (sRows + 4) ? 24f :
i == (sRows + 5) ? 22.5f :
i == (sRows + 6) ? 22.5f :
i == (sRows + 7) ? 24f :
i == (sRows + 8) ? 20.3f :
21.8f;
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>
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
}
}