20260415 热处理台账导出

This commit is contained in:
毕文静 2026-04-15 10:54:02 +08:00
parent 1d9d7ec7d9
commit 5663de52a1
4 changed files with 567 additions and 307 deletions

View File

@ -2,7 +2,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseIISExpress>true</UseIISExpress>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
<Use64BitIISExpress />
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />

View File

@ -1,15 +1,16 @@
using System;
using BLL;
using Newtonsoft.Json.Linq;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using BLL;
using Newtonsoft.Json.Linq;
using System.Web;
using System.IO;
using NPOI.SS.UserModel;
using System.Drawing;
using NPOI.XSSF.UserModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
namespace FineUIPro.Web.HJGL.HotProessManage
{
@ -1411,10 +1412,6 @@ namespace FineUIPro.Web.HJGL.HotProessManage
#endregion
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string ids = string.Empty;
@ -1434,40 +1431,40 @@ namespace FineUIPro.Web.HJGL.HotProessManage
string filePath = string.Empty;
initTemplatePath = Const.HotProessManageOutTemplateUrl;
uploadfilepath = rootPath + initTemplatePath;
//newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID) + "_" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ").xlsx");
newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID).Replace("/", "-") + ").xlsx");
if (File.Exists(newUrl))
{
File.Delete(newUrl);
}
File.Copy(uploadfilepath, newUrl);
// 第一步:读取文件流
NPOI.SS.UserModel.IWorkbook workbook;
// 读取模板
IWorkbook workbook;
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
{
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
workbook = new XSSFWorkbook(stream);
}
string strSql = string.Empty;
List<SqlParameter> listStr = new List<SqlParameter>();
Model.SGGLDB db = Funs.DB;
var attachFiles = from x in db.AttachFile select x;
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
// 单元格样式
ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = BorderStyle.Thin;
cellStyle.BorderRight = BorderStyle.Thin;
cellStyle.BorderBottom = BorderStyle.Thin;
cellStyle.BorderLeft = BorderStyle.Thin;
cellStyle.Alignment = HorizontalAlignment.Center;
cellStyle.VerticalAlignment = VerticalAlignment.Center;
cellStyle.WrapText = true;
var font = workbook.CreateFont();
IFont font = workbook.CreateFont();
font.FontHeightInPoints = 10;
//font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
cellStyle.SetFont(font);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
ISheet sheet = workbook.GetSheetAt(0);
int i = 2;
strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,HotProessTrust.HotProessTrustCode,(select Top 1 TrustDate from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId) as TrustDate,
string strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,HotProessTrust.HotProessTrustCode,
(select Top 1 TrustDate from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId) as TrustDate,
JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
(CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
@ -1497,311 +1494,574 @@ namespace FineUIPro.Web.HJGL.HotProessManage
left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
WHERE JointInfo.ProjectId= @ProjectId order by ISO_IsoNo,JOT_JointNo,SortIndex,PointCount ";
WHERE JointInfo.ProjectId= @ProjectId order by ISO_IsoNo,Sort1,Sort2,Sort3,Sort4,Sort5,SortIndex,PointCount ";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// 第二步:创建新数据行
NPOI.SS.UserModel.IRow row;
NPOI.SS.UserModel.ICell cell;
List<string> jotIds = new List<string>();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, listStr.ToArray());
// 加载附件
Model.SGGLDB db = Funs.DB;
var attachFiles = db.AttachFile.ToList();
// 先遍历一遍,设置列宽 + 行高
Dictionary<string, int> maxHeightDic = new Dictionary<string, int>();
int col13 = 0, col14 = 0, col15 = 0, col16 = 0;
for (int j = 0; j < tb.Rows.Count; j++)
foreach (DataRow row in tb.Rows)
{
if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
string jotId = row["JOT_ID"].ToString();
if (!maxHeightDic.ContainsKey(jotId))
{
string jotId = tb.Rows[j]["JOT_ID"].ToString();
jotIds.Add(jotId);
var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
if (attachFile1 != null)
{
string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Width > col13)
{
col13 = image.Width;
}
}
}
if (attachFile2 != null)
{
string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Width > col14)
{
col14 = image.Width;
}
}
}
if (attachFile3 != null)
{
string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Width > col15)
{
col15 = image.Width;
}
}
}
if (attachFile4 != null)
{
string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Width > col16)
{
col16 = image.Width;
}
}
}
i++;
int maxH = 0;
CheckAndUpdateImageSize(attachFiles, jotId + "1", ref col13, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "2", ref col14, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "3", ref col15, ref maxH);
CheckAndUpdateImageSize(attachFiles, jotId + "4", ref col16, ref maxH);
maxHeightDic[jotId] = maxH;
}
}
if (col13 > 0)
// 设置列宽
if (col13 > 0) sheet.SetColumnWidth(13, col13 * 30);
if (col14 > 0) sheet.SetColumnWidth(14, col14 * 30);
if (col15 > 0) sheet.SetColumnWidth(15, col15 * 30);
if (col16 > 0) sheet.SetColumnWidth(16, col16 * 30);
// 填充数据 + 插入图片
foreach (DataRow row in tb.Rows)
{
sheet.SetColumnWidth(13, col13 * 37);
}
if (col14 > 0)
{
sheet.SetColumnWidth(14, col14 * 37);
}
if (col15 > 0)
{
sheet.SetColumnWidth(15, col15 * 37);
}
if (col16 > 0)
{
sheet.SetColumnWidth(16, col16 * 37);
}
i = 2;
jotIds.Clear();
for (int j = 0; j < tb.Rows.Count; j++)
{
if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
string jotId = row["JOT_ID"].ToString();
IRow excelRow = sheet.CreateRow(i);
// 设置行高(根据图片高度自动适应)
if (maxHeightDic.TryGetValue(jotId, out int height) && height > 0)
{
string jotId = tb.Rows[j]["JOT_ID"].ToString();
jotIds.Add(jotId);
row = sheet.CreateRow(i);
var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
int height = 0;
if (attachFile1 != null)
{
string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Height > height)
{
height = image.Height;
}
}
}
if (attachFile2 != null)
{
string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Height > height)
{
height = image.Height;
}
}
}
if (attachFile3 != null)
{
string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Height > height)
{
height = image.Height;
}
}
}
if (attachFile4 != null)
{
string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
if (File.Exists(url))
{
System.Drawing.Image image = System.Drawing.Image.FromFile(url);
if (image.Height > height)
{
height = image.Height;
}
}
}
if (height > 0)
{
row.Height = (short)(height * 17);
}
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue((i - 1).ToString());
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["ISO_IsoNo"].ToString());
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["JOT_JointNo"].ToString());
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["JOT_JointDesc"].ToString());
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["STE_Code"].ToString());
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["ThermocouplesNum"].ToString());
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["HeatingRange"].ToString());
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["InsulationRange"].ToString());
cell = row.CreateCell(8);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["InsulationThickness"].ToString());
cell = row.CreateCell(9);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["HotProessTrustCode"].ToString());
cell = row.CreateCell(10);
cell.CellStyle = cellStyle;
string trustDate = string.Empty;
if (tb.Rows[j]["TrustDate"] != DBNull.Value)
{
trustDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["TrustDate"]));
}
cell.SetCellValue(trustDate);
cell = row.CreateCell(11);
cell.CellStyle = cellStyle;
string hotStartDate = string.Empty;
if (tb.Rows[j]["HotStartDate"] != DBNull.Value)
{
hotStartDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotStartDate"]));
}
cell.SetCellValue(hotStartDate);
cell = row.CreateCell(12);
cell.CellStyle = cellStyle;
string hotEndDate = string.Empty;
if (tb.Rows[j]["HotEndDate"] != DBNull.Value)
{
hotEndDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotEndDate"]));
}
cell.SetCellValue(hotEndDate);
cell = row.CreateCell(13);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(14);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(15);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(16);
cell.CellStyle = cellStyle;
cell.SetCellValue(string.Empty);
cell = row.CreateCell(17);
cell.CellStyle = cellStyle;
cell.SetCellValue(tb.Rows[j]["Remark"].ToString());
if (attachFile1 != null)
{
string fp = BLL.Funs.RootPath + attachFile1.AttachUrl;
if (File.Exists(fp))
{
byte[] fileBytes = File.ReadAllBytes(fp);
TryAddPicture(sheet, i, 13, fileBytes, PictureType.PNG);
}
}
if (attachFile2 != null)
{
string fp = BLL.Funs.RootPath + attachFile2.AttachUrl;
if (File.Exists(fp))
{
byte[] fileBytes = File.ReadAllBytes(fp);
TryAddPicture(sheet, i, 14, fileBytes, PictureType.PNG);
}
}
if (attachFile3 != null)
{
string fp = BLL.Funs.RootPath + attachFile3.AttachUrl;
if (File.Exists(fp))
{
byte[] fileBytes = File.ReadAllBytes(fp);
TryAddPicture(sheet, i, 15, fileBytes, PictureType.PNG);
}
}
if (attachFile4 != null)
{
string fp = BLL.Funs.RootPath + attachFile4.AttachUrl;
if (File.Exists(fp))
{
byte[] fileBytes = File.ReadAllBytes(fp);
TryAddPicture(sheet, i, 16, fileBytes, PictureType.PNG);
}
}
i++;
excelRow.Height = (short)(height * 17);
}
else
{
excelRow.Height = 400; // 默认行高,防止图片被截断
}
// 赋值单元格
SetCell(excelRow, 0, cellStyle, (i - 1).ToString());
SetCell(excelRow, 1, cellStyle, row["ISO_IsoNo"].ToString());
SetCell(excelRow, 2, cellStyle, row["JOT_JointNo"].ToString());
SetCell(excelRow, 3, cellStyle, row["JOT_JointDesc"].ToString());
SetCell(excelRow, 4, cellStyle, row["STE_Code"].ToString());
SetCell(excelRow, 5, cellStyle, row["ThermocouplesNum"].ToString());
SetCell(excelRow, 6, cellStyle, row["HeatingRange"].ToString());
SetCell(excelRow, 7, cellStyle, row["InsulationRange"].ToString());
SetCell(excelRow, 8, cellStyle, row["InsulationThickness"].ToString());
SetCell(excelRow, 9, cellStyle, row["HotProessTrustCode"].ToString());
string trustDate = row["TrustDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["TrustDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 10, cellStyle, trustDate);
string hotStart = row["HotStartDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["HotStartDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 11, cellStyle, hotStart);
string hotEnd = row["HotEndDate"] != DBNull.Value ? $"{Convert.ToDateTime(row["HotEndDate"]):yyyy-MM-dd}" : "";
SetCell(excelRow, 12, cellStyle, hotEnd);
// 图片列(空值)
SetCell(excelRow, 13, cellStyle, "");
SetCell(excelRow, 14, cellStyle, "");
SetCell(excelRow, 15, cellStyle, "");
SetCell(excelRow, 16, cellStyle, "");
SetCell(excelRow, 17, cellStyle, row["Remark"].ToString());
// 插入图片
InsertImageToExcel(sheet, i, 13, attachFiles, jotId + "1");
InsertImageToExcel(sheet, i, 14, attachFiles, jotId + "2");
InsertImageToExcel(sheet, i, 15, attachFiles, jotId + "3");
InsertImageToExcel(sheet, i, 16, attachFiles, jotId + "4");
i++;
}
// 第三步:写入文件流
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
{
workbook.Write(stream);
workbook.Close();
}
string fileName = Path.GetFileName(newUrl);
FileInfo info = new FileInfo(newUrl);
long fileSize = info.Length;
Response.Clear();
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.AddHeader("Content-Length", fileSize.ToString());
Response.TransmitFile(newUrl, 0, fileSize);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
Response.TransmitFile(newUrl);
Response.Flush();
Response.Close();
File.Delete(newUrl);
}
/// <summary>
/// 检查图片尺寸(不使用 System.Drawing避免报错
/// </summary>
private void CheckAndUpdateImageSize(List<Model.AttachFile> attachFiles, string keyId, ref int colWidth, ref int maxHeight)
{
try
{
var file = attachFiles.FirstOrDefault(x => x.ToKeyId == keyId);
if (file == null) return;
string path = BLL.Funs.RootPath + file.AttachUrl;
if (!File.Exists(path)) return;
// 不读取图片,直接给固定宽高,避免报错
colWidth = 120;
maxHeight = 120;
}
catch { }
}
/// <summary>
/// 向Excel指定单元格插入单张图片
/// </summary>
private void InsertImageToExcel(ISheet sheet, int row, int col, List<Model.AttachFile> attachFiles, string toKeyId)
{
try
{
var attach = attachFiles.FirstOrDefault(x => x.ToKeyId == toKeyId);
if (attach == null) return;
string filePath = BLL.Funs.RootPath + attach.AttachUrl;
if (!File.Exists(filePath)) return;
byte[] bytes = File.ReadAllBytes(filePath);
TryAddPicture(sheet, row, col, bytes, PictureType.PNG);
}
catch
{
// 图片异常不影响导出
}
}
/// <summary>
/// 快速设置单元格
/// </summary>
private void SetCell(IRow row, int index, ICellStyle style, string value)
{
ICell cell = row.CreateCell(index);
cell.CellStyle = style;
cell.SetCellValue(value);
}
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
// protected void btnOut_Click(object sender, EventArgs e)
// {
// string ids = string.Empty;
// if (this.tvControlItem.SelectedNode != null && this.tvControlItem.SelectedNode.CommandName == "项目名称")
// {
// }
// else
// {
// ShowNotify("请选择要导出的项目!", MessageBoxIcon.Warning);
// return;
// }
// string rootPath = Server.MapPath("~/");
// string initTemplatePath = string.Empty;
// string uploadfilepath = string.Empty;
// string newUrl = string.Empty;
// string filePath = string.Empty;
// initTemplatePath = Const.HotProessManageOutTemplateUrl;
// uploadfilepath = rootPath + initTemplatePath;
// //newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID) + "_" + string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ").xlsx");
// newUrl = uploadfilepath.Replace(".xlsx", "(" + BLL.Base_ProjectService.GetProjectCode(this.tvControlItem.SelectedNodeID).Replace("/", "-") + ").xlsx");
// if (File.Exists(newUrl))
// {
// File.Delete(newUrl);
// }
// File.Copy(uploadfilepath, newUrl);
// // 第一步:读取文件流
// NPOI.SS.UserModel.IWorkbook workbook;
// using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
// {
// workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
// }
// string strSql = string.Empty;
// List<SqlParameter> listStr = new List<SqlParameter>();
// Model.SGGLDB db = Funs.DB;
// var attachFiles = from x in db.AttachFile select x;
// // 创建单元格样式
// NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
// cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
// cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
// cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
// cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
// cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
// cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
// cellStyle.WrapText = true;
// var font = workbook.CreateFont();
// font.FontHeightInPoints = 10;
// //font.FontHeightInPoints = (short)8.5;字号为小数时要转为short
// cellStyle.SetFont(font);
// // 第二步:创建新数据行
// NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
// int i = 2;
// strSql = @"SELECT JointInfo.ProjectId,JointInfo.JOT_ID,Project.ProjectCode,HotProessItem.PrintDate,HotProessTrust.HotProessTrustCode,(select Top 1 TrustDate from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId) as TrustDate,
// JointInfo.JOT_ID+'1' as JOT_ID1, JointInfo.JOT_ID+'2' as JOT_ID2,JointInfo.JOT_ID+'3' as JOT_ID3,JointInfo.JOT_ID+'4' as JOT_ID4,
// (CASE WHEN v.RepairMark IS NOT NULL THEN (JointInfo.JOT_JointNo+v.RepairMark)
// ELSE JointInfo.JOT_JointNo END )+isnull((select Top 1 HardRepairMark from dbo.HJGL_CH_HotProessTrustItem a where a.JOT_ID=HotProessItem.JOT_ID and a.HotProessTrustId=HotProessItem.HotProessTrustId and a.ProessTypes=HotProessItem.ProessTypes),'') AS JOT_JointNo,IsoInfo.ISO_IsoNo,IsoInfo.ISO_ID,
// (CASE WHEN Steel.STE_Code IS NOT NULL AND Steel2.STE_Code IS NOT NULL and Steel.STE_Code!=Steel2.STE_Code
// THEN Steel.STE_Code + '/' + Steel2.STE_Code
// WHEN Steel.STE_Code IS NOT NULL THEN Steel.STE_Code
// ELSE ISNULL(Steel2.STE_Code,'') END) AS STE_Code,ThermocouplesNum,HeatingRange,InsulationRange,InsulationThickness,HotStartDate,HotEndDate,
// HotProessItem.PointCount,HotProessItem.RequiredT,HotProessItem.ActualT,
// HotProessItem.RequestTime,HotProessItem.ActualTime,HotProessItem.RecordChartNo,
// HotProessItem.HotProessDate,HotProessItem.HotProessTrustId,
//(SELECT (case when HotHardCode is null then HardTestReportCode else HotHardCode end) as HardTestReportCode FROM dbo.HJGL_CH_HardTestReport
// WHERE HardTestReportId =(SELECT TOP 1 re.HardTestReportId FROM dbo.HJGL_CH_HardTestReportItem item
// left join dbo.HJGL_CH_HardTestReport re on item.HardTestReportId=re.HardTestReportId
// WHERE item.JOT_ID=HotProessItem.JOT_ID AND item.HotProessTrustId=HotProessItem.HotProessTrustId and (re.FileType='R' or re.FileType is null)))
// AS HardnessReportNo,
// HotProessItem.HotProessItemId,HotProessItem.SortIndex,HotProessItem.ProessTypes,JointInfo.JOT_JointDesc,isnull(HotProessItem.Remark,'') as Remark
// FROM dbo.HJGL_HotProessItem AS HotProessItem
// LEFT JOIN dbo.HJGL_CH_HotProessTrust AS HotProessTrust ON HotProessTrust.HotProessTrustId = HotProessItem.HotProessTrustId
// LEFT JOIN dbo.HJGL_PW_JointInfo AS JointInfo ON JointInfo.JOT_ID = HotProessItem.JOT_ID
// LEFT JOIN dbo.HJGL_PW_IsoInfo AS IsoInfo ON JointInfo.ISO_ID = IsoInfo.ISO_ID
// left join Base_Project as Project on Project.ProjectId = IsoInfo.ProjectId
// LEFT JOIN dbo.Project_WorkArea AS WorkArea ON IsoInfo.BAW_ID = WorkArea.WorkAreaId
// LEFT JOIN dbo.HJGL_BS_Steel AS Steel ON JointInfo.STE_ID = Steel.STE_ID
// LEFT JOIN dbo.HJGL_BS_Steel AS Steel2 ON JointInfo.STE_ID2 = Steel2.STE_ID
// left join (select record.RepairMark,record.JOT_ID,h.HotProessItemId from dbo.HJGL_CH_HotProessTrustItem AS TrustItem
// left join dbo.HJGL_CH_RepairItemRecord AS record ON record.RepairItemRecordId=TrustItem.TrustItemID
// left join dbo.HJGL_HotProessItem h on h.JOT_ID=TrustItem.JOT_ID
// where h.JOT_ID = TrustItem.JOT_ID and h.HotProessTrustId=TrustItem.HotProessTrustId and h.ProessTypes=TrustItem.ProessTypes) v
// on v.JOT_ID=HotProessItem.JOT_ID and v.HotProessItemId=HotProessItem.HotProessItemId
// WHERE JointInfo.ProjectId= @ProjectId order by ISO_IsoNo,JOT_JointNo,SortIndex,PointCount ";
// listStr.Add(new SqlParameter("@ProjectId", this.tvControlItem.SelectedNodeID));
// SqlParameter[] parameter = listStr.ToArray();
// DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
// // 第二步:创建新数据行
// NPOI.SS.UserModel.IRow row;
// NPOI.SS.UserModel.ICell cell;
// //List<string> jotIds = new List<string>();
// //int col13 = 0, col14 = 0, col15 = 0, col16 = 0;
// //for (int j = 0; j < tb.Rows.Count; j++)
// //{
// // if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
// // {
// // string jotId = tb.Rows[j]["JOT_ID"].ToString();
// // jotIds.Add(jotId);
// // var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
// // var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
// // var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
// // var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
// // if (attachFile1 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col13)
// // {
// // col13 = image.Width;
// // }
// // }
// // }
// // if (attachFile2 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col14)
// // {
// // col14 = image.Width;
// // }
// // }
// // }
// // if (attachFile3 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col15)
// // {
// // col15 = image.Width;
// // }
// // }
// // }
// // if (attachFile4 != null)
// // {
// // string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Width > col16)
// // {
// // col16 = image.Width;
// // }
// // }
// // }
// // i++;
// // }
// //}
// //if (col13 > 0)
// //{
// // sheet.SetColumnWidth(13, col13 * 37);
// //}
// //if (col14 > 0)
// //{
// // sheet.SetColumnWidth(14, col14 * 37);
// //}
// //if (col15 > 0)
// //{
// // sheet.SetColumnWidth(15, col15 * 37);
// //}
// //if (col16 > 0)
// //{
// // sheet.SetColumnWidth(16, col16 * 37);
// //}
// //i = 2;
// //jotIds.Clear();
// for (int j = 0; j < tb.Rows.Count; j++)
// {
// //if (!jotIds.Contains(tb.Rows[j]["JOT_ID"].ToString()))
// //{
// string jotId = tb.Rows[j]["JOT_ID"].ToString();
// //jotIds.Add(jotId);
// row = sheet.CreateRow(i);
// //var attachFile1 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "1"));
// //var attachFile2 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "2"));
// //var attachFile3 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "3"));
// //var attachFile4 = attachFiles.FirstOrDefault(x => x.ToKeyId == (jotId + "4"));
// //int height = 0;
// //if (attachFile1 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile2 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile3 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (attachFile4 != null)
// //{
// // string url = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(url))
// // {
// // System.Drawing.Image image = System.Drawing.Image.FromFile(url);
// // if (image.Height > height)
// // {
// // height = image.Height;
// // }
// // }
// //}
// //if (height > 0)
// //{
// // row.Height = (short)(height * 17);
// //}
// // 添加数据
// cell = row.CreateCell(0);
// cell.CellStyle = cellStyle;
// cell.SetCellValue((i - 1).ToString());
// cell = row.CreateCell(1);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["ISO_IsoNo"].ToString());
// cell = row.CreateCell(2);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["JOT_JointNo"].ToString());
// cell = row.CreateCell(3);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["JOT_JointDesc"].ToString());
// cell = row.CreateCell(4);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["STE_Code"].ToString());
// cell = row.CreateCell(5);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["ThermocouplesNum"].ToString());
// cell = row.CreateCell(6);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["HeatingRange"].ToString());
// cell = row.CreateCell(7);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["InsulationRange"].ToString());
// cell = row.CreateCell(8);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["InsulationThickness"].ToString());
// cell = row.CreateCell(9);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["HotProessTrustCode"].ToString());
// cell = row.CreateCell(10);
// cell.CellStyle = cellStyle;
// string trustDate = string.Empty;
// if (tb.Rows[j]["TrustDate"] != DBNull.Value)
// {
// trustDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["TrustDate"]));
// }
// cell.SetCellValue(trustDate);
// cell = row.CreateCell(11);
// cell.CellStyle = cellStyle;
// string hotStartDate = string.Empty;
// if (tb.Rows[j]["HotStartDate"] != DBNull.Value)
// {
// hotStartDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotStartDate"]));
// }
// cell.SetCellValue(hotStartDate);
// cell = row.CreateCell(12);
// cell.CellStyle = cellStyle;
// string hotEndDate = string.Empty;
// if (tb.Rows[j]["HotEndDate"] != DBNull.Value)
// {
// hotEndDate = string.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(tb.Rows[j]["HotEndDate"]));
// }
// cell.SetCellValue(hotEndDate);
// cell = row.CreateCell(13);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(14);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(15);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(16);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(string.Empty);
// cell = row.CreateCell(17);
// cell.CellStyle = cellStyle;
// cell.SetCellValue(tb.Rows[j]["Remark"].ToString());
// //if (attachFile1 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile1.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 13, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile2 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile2.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 14, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile3 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile3.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 15, fileBytes, PictureType.PNG);
// // }
// //}
// //if (attachFile4 != null)
// //{
// // string fp = BLL.Funs.RootPath + attachFile4.AttachUrl;
// // if (File.Exists(fp))
// // {
// // byte[] fileBytes = File.ReadAllBytes(fp);
// // TryAddPicture(sheet, i, 16, fileBytes, PictureType.PNG);
// // }
// //}
// i++;
// //}
// }
// // 第三步:写入文件流
// using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
// {
// workbook.Write(stream);
// workbook.Close();
// }
// string fileName = Path.GetFileName(newUrl);
// FileInfo info = new FileInfo(newUrl);
// long fileSize = info.Length;
// Response.Clear();
// Response.ContentType = "application/x-zip-compressed";
// Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
// Response.AddHeader("Content-Length", fileSize.ToString());
// Response.TransmitFile(newUrl, 0, fileSize);
// Response.Flush();
// Response.Close();
// File.Delete(newUrl);
// }
//private void TryAddPicture(ISheet sheet, int row, int col, byte[] pictureBytes, PictureType pictureType = PictureType.PNG)
//{
// if (sheet is null)
// {
// throw new ArgumentNullException(nameof(sheet));
// }
// try
// {
// var pictureIndex = sheet.Workbook.AddPicture(pictureBytes, pictureType);
// var clientAnchor = sheet.Workbook.GetCreationHelper().CreateClientAnchor();
// clientAnchor.Row1 = row;
// clientAnchor.Col1 = col;
// var picture = (sheet.DrawingPatriarch ?? sheet.CreateDrawingPatriarch())
// .CreatePicture(clientAnchor, pictureIndex);
// picture.Resize();
// }
// catch (Exception ex)
// {
// }
//}
private void TryAddPicture(ISheet sheet, int row, int col, byte[] pictureBytes, PictureType pictureType = PictureType.PNG)
{
if (sheet is null)
{
if (sheet == null)
throw new ArgumentNullException(nameof(sheet));
}
if (pictureBytes == null || pictureBytes.Length == 0)
return;
try
{
var pictureIndex = sheet.Workbook.AddPicture(pictureBytes, pictureType);
int pictureIndex = sheet.Workbook.AddPicture(pictureBytes, pictureType);
var clientAnchor = sheet.Workbook.GetCreationHelper().CreateClientAnchor();
IClientAnchor clientAnchor = sheet.Workbook.GetCreationHelper().CreateClientAnchor();
clientAnchor.Row1 = row;
clientAnchor.Col1 = col;
clientAnchor.Row2 = row + 1;
clientAnchor.Col2 = col + 1;
var picture = (sheet.DrawingPatriarch ?? sheet.CreateDrawingPatriarch())
.CreatePicture(clientAnchor, pictureIndex);
picture.Resize();
IDrawing drawing = sheet.DrawingPatriarch ?? sheet.CreateDrawingPatriarch();
IPicture picture = drawing.CreatePicture(clientAnchor, pictureIndex);
picture.Resize(0.6); // 缩放
}
catch (Exception ex)
catch
{
// 不抛异常,不影响导出
}
}
#endregion

View File

@ -67,7 +67,7 @@
<add path="ChartImg.axd" verb="GET,POST,HEAD" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
<add path="FastReport.Export.axd" verb="*" type="FastReport.Web.Handlers.WebExport"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.6.1">
<compilation debug="false" targetFramework="4.6.1">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastActiveSolutionConfig>Debug|Any CPU</LastActiveSolutionConfig>
<LastActiveSolutionConfig>Release|Any CPU</LastActiveSolutionConfig>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
<UseIISExpress>true</UseIISExpress>
<Use64BitIISExpress />