2025-12-31 09:43:35 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Windows.Forms;
|
2025-12-31 17:26:27 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
using NPOI.SS.UserModel;
|
|
|
|
|
|
using NPOI.XSSF.UserModel;
|
|
|
|
|
|
using NPOI.SS.Util;
|
|
|
|
|
|
using NPOIBorderStyle = NPOI.SS.UserModel.BorderStyle;
|
|
|
|
|
|
using NPOIHorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
|
2025-12-31 09:43:35 +08:00
|
|
|
|
|
|
|
|
|
|
namespace WindowsFormsApp6
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class MainForm : Form
|
2025-12-31 17:26:27 +08:00
|
|
|
|
{
|
|
|
|
|
|
private Form1 form1Instance;
|
|
|
|
|
|
private Form2 form2Instance;
|
|
|
|
|
|
private Form3 form3Instance;
|
|
|
|
|
|
private System.Windows.Forms.Timer clockTimer;
|
2025-12-31 09:43:35 +08:00
|
|
|
|
|
|
|
|
|
|
public MainForm()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2025-12-31 17:26:27 +08:00
|
|
|
|
InitializeClockTimer();
|
|
|
|
|
|
InitializeTabControl();
|
|
|
|
|
|
InitializeEmbeddedForms();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void InitializeClockTimer()
|
|
|
|
|
|
{
|
|
|
|
|
|
clockTimer = new System.Windows.Forms.Timer();
|
|
|
|
|
|
clockTimer.Interval = 1000;
|
|
|
|
|
|
clockTimer.Tick += (s, e) => label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
clockTimer.Start();
|
|
|
|
|
|
}
|
2025-12-31 09:43:35 +08:00
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void InitializeTabControl()
|
|
|
|
|
|
{
|
|
|
|
|
|
tabControl1.SelectedIndexChanged += TabControl1_SelectedIndexChanged;
|
|
|
|
|
|
}
|
2025-12-31 09:43:35 +08:00
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateTitleForCurrentTab();
|
2025-12-31 17:41:01 +08:00
|
|
|
|
|
|
|
|
|
|
// 根据选中的 Tab 显示/隐藏切换布局按钮
|
|
|
|
|
|
// 只有在 Form3 (Tab 2, index=2) 时显示切换按钮
|
|
|
|
|
|
buttonToggleLayout.Visible = (tabControl1.SelectedIndex == 2);
|
|
|
|
|
|
|
|
|
|
|
|
// 更新切换按钮的文本
|
|
|
|
|
|
if (tabControl1.SelectedIndex == 2 && form3Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
UpdateToggleButtonText();
|
|
|
|
|
|
}
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void UpdateTitleForCurrentTab()
|
2025-12-31 09:43:35 +08:00
|
|
|
|
{
|
2025-12-31 17:26:27 +08:00
|
|
|
|
switch (tabControl1.SelectedIndex)
|
2025-12-31 09:43:35 +08:00
|
|
|
|
{
|
2025-12-31 17:26:27 +08:00
|
|
|
|
case 0:
|
|
|
|
|
|
label1.Text = " 液体吸收时间测试报告";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
label1.Text = " 液体吸收量测试报告";
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
label1.Text = " 液体芯吸速率测试报告";
|
|
|
|
|
|
break;
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void InitializeEmbeddedForms()
|
2025-12-31 09:43:35 +08:00
|
|
|
|
{
|
2025-12-31 17:26:27 +08:00
|
|
|
|
form1Instance = new Form1();
|
|
|
|
|
|
form1Instance.TopLevel = false;
|
|
|
|
|
|
form1Instance.FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
|
form1Instance.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
|
|
Panel panel1 = new Panel();
|
|
|
|
|
|
panel1.Dock = DockStyle.Fill;
|
|
|
|
|
|
panel1.Controls.Add(form1Instance.Controls["tableLayoutPanel1"].Controls["panel3"]);
|
|
|
|
|
|
tabPage1.Controls.Add(panel1);
|
|
|
|
|
|
form1Instance.Show();
|
|
|
|
|
|
|
|
|
|
|
|
form2Instance = new Form2();
|
|
|
|
|
|
form2Instance.TopLevel = false;
|
|
|
|
|
|
form2Instance.FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
|
form2Instance.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
|
|
Panel panel2 = new Panel();
|
|
|
|
|
|
panel2.Dock = DockStyle.Fill;
|
|
|
|
|
|
panel2.Controls.Add(form2Instance.Controls["tableLayoutPanel1"].Controls["panel3"]);
|
|
|
|
|
|
tabPage2.Controls.Add(panel2);
|
|
|
|
|
|
form2Instance.Show();
|
|
|
|
|
|
|
|
|
|
|
|
form3Instance = new Form3();
|
|
|
|
|
|
form3Instance.TopLevel = false;
|
|
|
|
|
|
form3Instance.FormBorderStyle = FormBorderStyle.None;
|
|
|
|
|
|
form3Instance.Dock = DockStyle.Fill;
|
|
|
|
|
|
|
|
|
|
|
|
Panel panel3 = new Panel();
|
|
|
|
|
|
panel3.Dock = DockStyle.Fill;
|
|
|
|
|
|
panel3.Controls.Add(form3Instance.Controls["tableLayoutPanel1"].Controls["panel3"]);
|
|
|
|
|
|
tabPage3.Controls.Add(panel3);
|
|
|
|
|
|
form3Instance.Show();
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void buttonPrint_Click(object sender, EventArgs e)
|
2025-12-31 09:43:35 +08:00
|
|
|
|
{
|
2025-12-31 17:26:27 +08:00
|
|
|
|
MessageBox.Show("打印功能开发中", "提示");
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void buttonExport_Click(object sender, EventArgs e)
|
2025-12-31 09:43:35 +08:00
|
|
|
|
{
|
2025-12-31 17:26:27 +08:00
|
|
|
|
SaveFileDialog saveFileDialog = new SaveFileDialog
|
|
|
|
|
|
{
|
|
|
|
|
|
Filter = "Excel 文件 (*.xlsx)|*.xlsx",
|
|
|
|
|
|
FileName = $"测试报告_{DateTime.Now:yyyyMMdd_HHmmss}",
|
|
|
|
|
|
Title = "导出整合报告"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
ExportIntegratedReport(saveFileDialog.FileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
switch (tabControl1.SelectedIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
case 0:
|
|
|
|
|
|
form1Instance.GenerateMockData();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
form2Instance.GenerateMockData();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
form3Instance.GenerateMockData();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:41:01 +08:00
|
|
|
|
private void buttonToggleLayout_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (form3Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 调用 Form3 的公共切换方法
|
|
|
|
|
|
form3Instance.ToggleTableLayout();
|
|
|
|
|
|
|
|
|
|
|
|
// 更新按钮文本
|
|
|
|
|
|
UpdateToggleButtonText();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新切换按钮的文本
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdateToggleButtonText()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (form3Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 使用公共方法获取布局状态
|
|
|
|
|
|
bool isVertical = form3Instance.IsVerticalLayout();
|
|
|
|
|
|
buttonToggleLayout.Text = isVertical ? "🔄 横向布局" : "🔄 纵向布局";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 17:26:27 +08:00
|
|
|
|
private void ExportIntegratedReport(string filePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
IWorkbook workbook = new XSSFWorkbook();
|
2025-12-31 18:36:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建单个整合的工作表
|
|
|
|
|
|
CreateIntegratedSheet(workbook);
|
2025-12-31 17:26:27 +08:00
|
|
|
|
|
|
|
|
|
|
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
|
|
|
|
|
|
{
|
|
|
|
|
|
workbook.Write(fs);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MessageBox.Show($"导出成功:{filePath}", "成功");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show($"导出失败:{ex.Message}", "错误");
|
|
|
|
|
|
}
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
private void CreateIntegratedSheet(IWorkbook workbook)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ISheet sheet = workbook.CreateSheet("吸收性测试报告");
|
2025-12-31 17:54:34 +08:00
|
|
|
|
var styles = CreateReportStyles(workbook);
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 获取三个表单的数据
|
|
|
|
|
|
var sampleCountField1 = form1Instance.GetType()
|
2025-12-31 17:54:34 +08:00
|
|
|
|
.GetField("currentSampleCount", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
2025-12-31 18:36:52 +08:00
|
|
|
|
int sampleCount = sampleCountField1 != null ? (int)sampleCountField1.GetValue(form1Instance) : 5;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
var dataTableField1 = form1Instance.GetType()
|
2025-12-31 17:54:34 +08:00
|
|
|
|
.GetField("sampleDataTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
2025-12-31 18:36:52 +08:00
|
|
|
|
DataTable dataTable1 = dataTableField1?.GetValue(form1Instance) as DataTable;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
var dataTableField2 = form2Instance.GetType()
|
|
|
|
|
|
.GetField("sampleDataTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
|
|
|
|
|
DataTable dataTable2 = dataTableField2?.GetValue(form2Instance) as DataTable;
|
|
|
|
|
|
|
|
|
|
|
|
var dataTableField3 = form3Instance.GetType()
|
|
|
|
|
|
.GetField("sampleDataTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
|
|
|
|
|
|
DataTable dataTable3 = dataTableField3?.GetValue(form3Instance) as DataTable;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
|
|
|
|
|
int currentRow = 0;
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 1. 创建总标题
|
2025-12-31 17:54:34 +08:00
|
|
|
|
IRow titleRow = sheet.CreateRow(currentRow++);
|
2025-12-31 18:36:52 +08:00
|
|
|
|
titleRow.Height = 800;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
ICell titleCell = titleRow.CreateCell(0);
|
2025-12-31 18:36:52 +08:00
|
|
|
|
titleCell.SetCellValue("吸收性测试报告");
|
2025-12-31 17:54:34 +08:00
|
|
|
|
titleCell.CellStyle = styles.titleStyle;
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 为合并区域的所有单元格设置样式(总标题不需要边框,但为了一致性也设置)
|
|
|
|
|
|
for (int i = 1; i <= sampleCount + 5; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
titleRow.CreateCell(i).CellStyle = styles.titleStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(0, 0, 0, sampleCount + 5));
|
|
|
|
|
|
|
|
|
|
|
|
currentRow++; // 空行
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 创建信息输入区域
|
|
|
|
|
|
CreateInfoSection(sheet, ref currentRow, sampleCount, styles);
|
|
|
|
|
|
|
|
|
|
|
|
currentRow++; // 空行
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 创建液体吸收时间部分
|
|
|
|
|
|
CreateForm1Section(sheet, ref currentRow, sampleCount, dataTable1, styles);
|
|
|
|
|
|
|
|
|
|
|
|
currentRow++; // 空行
|
|
|
|
|
|
|
|
|
|
|
|
// 4. 创建液体吸收量部分
|
|
|
|
|
|
CreateForm2Section(sheet, ref currentRow, sampleCount, dataTable2, styles);
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
|
|
|
|
|
currentRow++; // 空行
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 5. 创建液体芯吸速率部分
|
|
|
|
|
|
CreateForm3Section(sheet, ref currentRow, sampleCount, dataTable3, styles);
|
|
|
|
|
|
|
|
|
|
|
|
// 设置列宽
|
|
|
|
|
|
sheet.SetColumnWidth(0, 20 * 256);
|
|
|
|
|
|
for (int i = 1; i <= sampleCount * 3; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
sheet.SetColumnWidth(i, 12 * 256);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CreateInfoSection(ISheet sheet, ref int currentRow, int sampleCount,
|
|
|
|
|
|
(ICellStyle titleStyle, ICellStyle headerStyle, ICellStyle dataStyle, ICellStyle yellowStyle) styles)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 第一行信息
|
|
|
|
|
|
IRow infoRow1 = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
infoRow1.Height = 400;
|
|
|
|
|
|
|
|
|
|
|
|
// 样品名称
|
|
|
|
|
|
ICell cell1 = infoRow1.CreateCell(0);
|
|
|
|
|
|
cell1.SetCellValue("样品名称:");
|
|
|
|
|
|
cell1.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell2 = infoRow1.CreateCell(1);
|
|
|
|
|
|
cell2.SetCellValue("手动录入");
|
|
|
|
|
|
cell2.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
infoRow1.CreateCell(2).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 1, 2));
|
|
|
|
|
|
|
|
|
|
|
|
// 物料编码
|
|
|
|
|
|
ICell cell3 = infoRow1.CreateCell(3);
|
|
|
|
|
|
cell3.SetCellValue("物料编码:");
|
|
|
|
|
|
cell3.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell4 = infoRow1.CreateCell(4);
|
|
|
|
|
|
cell4.SetCellValue("手动录入");
|
|
|
|
|
|
cell4.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
infoRow1.CreateCell(5).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 4, 5));
|
|
|
|
|
|
|
|
|
|
|
|
// 批号
|
|
|
|
|
|
ICell cell5 = infoRow1.CreateCell(6);
|
|
|
|
|
|
cell5.SetCellValue("批号:");
|
|
|
|
|
|
cell5.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell6 = infoRow1.CreateCell(7);
|
|
|
|
|
|
cell6.SetCellValue("手动录入");
|
|
|
|
|
|
cell6.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
|
|
|
|
|
|
// 操作人员
|
|
|
|
|
|
ICell cell7 = infoRow1.CreateCell(8);
|
|
|
|
|
|
cell7.SetCellValue("操作人员:");
|
|
|
|
|
|
cell7.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell8 = infoRow1.CreateCell(9);
|
|
|
|
|
|
cell8.SetCellValue("手动录入");
|
|
|
|
|
|
cell8.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
|
|
|
|
|
|
// 第二行信息
|
|
|
|
|
|
IRow infoRow2 = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
infoRow2.Height = 400;
|
|
|
|
|
|
|
|
|
|
|
|
// 测试时间
|
|
|
|
|
|
ICell cell21 = infoRow2.CreateCell(0);
|
|
|
|
|
|
cell21.SetCellValue("测试时间:");
|
|
|
|
|
|
cell21.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell22 = infoRow2.CreateCell(1);
|
|
|
|
|
|
cell22.SetCellValue("系统检测时间");
|
|
|
|
|
|
cell22.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
infoRow2.CreateCell(2).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 1, 2));
|
|
|
|
|
|
|
|
|
|
|
|
// 仪器
|
|
|
|
|
|
ICell cell23 = infoRow2.CreateCell(3);
|
|
|
|
|
|
cell23.SetCellValue("仪器:");
|
|
|
|
|
|
cell23.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell24 = infoRow2.CreateCell(4);
|
|
|
|
|
|
cell24.SetCellValue("厂家仪器名称");
|
|
|
|
|
|
cell24.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
infoRow2.CreateCell(5).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 4, 5));
|
|
|
|
|
|
|
|
|
|
|
|
// 设备编号
|
|
|
|
|
|
ICell cell25 = infoRow2.CreateCell(6);
|
|
|
|
|
|
cell25.SetCellValue("设备编号:");
|
|
|
|
|
|
cell25.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell26 = infoRow2.CreateCell(7);
|
|
|
|
|
|
cell26.SetCellValue("手动录入");
|
|
|
|
|
|
cell26.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
|
|
|
|
|
|
// 数据文件
|
|
|
|
|
|
ICell cell27 = infoRow2.CreateCell(8);
|
|
|
|
|
|
cell27.SetCellValue("数据文件:");
|
|
|
|
|
|
cell27.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell cell28 = infoRow2.CreateCell(9);
|
|
|
|
|
|
cell28.SetCellValue("(报告保存路径)");
|
|
|
|
|
|
cell28.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void CreateForm1Section(ISheet sheet, ref int currentRow, int sampleCount, DataTable dataTable,
|
|
|
|
|
|
(ICellStyle titleStyle, ICellStyle headerStyle, ICellStyle dataStyle, ICellStyle yellowStyle) styles)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 子标题
|
|
|
|
|
|
IRow subtitleRow = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
subtitleRow.Height = 500;
|
|
|
|
|
|
ICell subtitleCell = subtitleRow.CreateCell(0);
|
|
|
|
|
|
subtitleCell.SetCellValue("液体吸收时间");
|
|
|
|
|
|
subtitleCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
subtitleRow.CreateCell(i).CellStyle = styles.headerStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 0, sampleCount));
|
|
|
|
|
|
|
|
|
|
|
|
// 表头
|
2025-12-31 17:54:34 +08:00
|
|
|
|
IRow headerRow = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
headerRow.Height = 400;
|
|
|
|
|
|
ICell seqCell = headerRow.CreateCell(0);
|
|
|
|
|
|
seqCell.SetCellValue("序号");
|
|
|
|
|
|
seqCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
ICell cell = headerRow.CreateCell(i);
|
|
|
|
|
|
cell.SetCellValue($"试样{i}");
|
|
|
|
|
|
cell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell noteCell = headerRow.CreateCell(sampleCount + 1);
|
|
|
|
|
|
noteCell.SetCellValue("根据样品个数进行选填");
|
|
|
|
|
|
noteCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
|
|
|
|
|
|
// 数据行
|
|
|
|
|
|
if (dataTable != null && dataTable.Rows.Count > 0)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
foreach (DataRow dataRow in dataTable.Rows)
|
|
|
|
|
|
{
|
|
|
|
|
|
string rowName = dataRow["序号"]?.ToString() ?? "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(rowName)) continue;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
IRow row = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
row.Height = 380;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell nameCell = row.CreateCell(0);
|
|
|
|
|
|
nameCell.SetCellValue(rowName);
|
|
|
|
|
|
nameCell.CellStyle = styles.dataStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = row.CreateCell(i);
|
|
|
|
|
|
if (dataTable.Columns.Contains($"试样{i}") && dataRow[$"试样{i}"] != DBNull.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (double.TryParse(dataRow[$"试样{i}"].ToString(), out double value))
|
|
|
|
|
|
{
|
|
|
|
|
|
cell.SetCellValue(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cell.SetCellValue("系统读数");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
cell.SetCellValue("系统读数");
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
cell.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果是平均时间行,添加"系统计算"
|
|
|
|
|
|
if (rowName.Contains("平均"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ICell calcCell = row.CreateCell(sampleCount + 1);
|
|
|
|
|
|
calcCell.SetCellValue("系统计算");
|
|
|
|
|
|
calcCell.CellStyle = styles.yellowStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
}
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
private void CreateForm2Section(ISheet sheet, ref int currentRow, int sampleCount, DataTable dataTable,
|
|
|
|
|
|
(ICellStyle titleStyle, ICellStyle headerStyle, ICellStyle dataStyle, ICellStyle yellowStyle) styles)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 子标题
|
|
|
|
|
|
IRow subtitleRow = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
subtitleRow.Height = 500;
|
|
|
|
|
|
ICell subtitleCell = subtitleRow.CreateCell(0);
|
|
|
|
|
|
subtitleCell.SetCellValue("液体吸收量");
|
|
|
|
|
|
subtitleCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
for (int i = 1; i <= sampleCount + 3; i++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
subtitleRow.CreateCell(i).CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 0, sampleCount + 3));
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 第一行表头(浸润时间、系统读数等)
|
|
|
|
|
|
IRow headerRow1 = sheet.CreateRow(currentRow);
|
|
|
|
|
|
headerRow1.Height = 400;
|
|
|
|
|
|
ICell seqCell1 = headerRow1.CreateCell(0);
|
|
|
|
|
|
seqCell1.SetCellValue("序号");
|
|
|
|
|
|
seqCell1.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell timeCell = headerRow1.CreateCell(1);
|
|
|
|
|
|
timeCell.SetCellValue("浸润时间");
|
|
|
|
|
|
timeCell.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell readCell = headerRow1.CreateCell(2);
|
|
|
|
|
|
readCell.SetCellValue("系统读数");
|
|
|
|
|
|
readCell.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell hangCell = headerRow1.CreateCell(3);
|
|
|
|
|
|
hangCell.SetCellValue("悬挂时间");
|
|
|
|
|
|
hangCell.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell readCell2 = headerRow1.CreateCell(4);
|
|
|
|
|
|
readCell2.SetCellValue("系统读数");
|
|
|
|
|
|
readCell2.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell speedCell = headerRow1.CreateCell(5);
|
|
|
|
|
|
speedCell.SetCellValue("运行速度");
|
|
|
|
|
|
speedCell.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell readCell3 = headerRow1.CreateCell(6);
|
|
|
|
|
|
readCell3.SetCellValue("系统读数");
|
|
|
|
|
|
readCell3.CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell noteCell1 = headerRow1.CreateCell(sampleCount + 1);
|
|
|
|
|
|
noteCell1.SetCellValue("根据样品个数进行选填");
|
|
|
|
|
|
noteCell1.CellStyle = styles.headerStyle;
|
|
|
|
|
|
|
|
|
|
|
|
currentRow++;
|
|
|
|
|
|
|
|
|
|
|
|
// 第二行表头(试样1-5)
|
|
|
|
|
|
IRow headerRow2 = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
headerRow2.Height = 400;
|
|
|
|
|
|
|
|
|
|
|
|
// 序号列在第二行也需要创建并设置样式(用于合并)
|
|
|
|
|
|
headerRow2.CreateCell(0).CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
|
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = headerRow2.CreateCell(i);
|
2025-12-31 17:54:34 +08:00
|
|
|
|
cell.SetCellValue($"试样{i}");
|
|
|
|
|
|
cell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
|
|
|
|
|
|
// 合并序号列(跨两行)
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 2, currentRow - 1, 0, 0));
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 数据行
|
|
|
|
|
|
if (dataTable != null && dataTable.Rows.Count > 0)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
foreach (DataRow dataRow in dataTable.Rows)
|
|
|
|
|
|
{
|
|
|
|
|
|
string rowName = dataRow["序号"]?.ToString() ?? "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(rowName)) continue;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
IRow row = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
row.Height = 380;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell nameCell = row.CreateCell(0);
|
|
|
|
|
|
nameCell.SetCellValue(rowName);
|
|
|
|
|
|
nameCell.CellStyle = styles.dataStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = row.CreateCell(i);
|
|
|
|
|
|
if (dataTable.Columns.Contains($"试样{i}") && dataRow[$"试样{i}"] != DBNull.Value)
|
|
|
|
|
|
{
|
|
|
|
|
|
object value = dataRow[$"试样{i}"];
|
|
|
|
|
|
if (value != null && double.TryParse(value.ToString(), out double numValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
cell.SetCellValue(numValue);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
cell.SetCellValue("系统读数");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
cell.SetCellValue("系统读数");
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
cell.CellStyle = styles.yellowStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 添加平均值和最大值行的说明
|
|
|
|
|
|
if (dataTable != null && dataTable.Rows.Count > 0)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 查找平均值行
|
|
|
|
|
|
for (int i = 0; i < dataTable.Rows.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string rowName = dataTable.Rows[i]["序号"]?.ToString() ?? "";
|
|
|
|
|
|
if (rowName.Contains("平均"))
|
|
|
|
|
|
{
|
|
|
|
|
|
int avgRowIndex = currentRow - (dataTable.Rows.Count - i);
|
|
|
|
|
|
IRow avgExcelRow = sheet.GetRow(avgRowIndex);
|
|
|
|
|
|
if (avgExcelRow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ICell calcCell = avgExcelRow.CreateCell(sampleCount + 1);
|
|
|
|
|
|
calcCell.SetCellValue("系统根据多少组试样,计算多少组的标准偏差");
|
|
|
|
|
|
calcCell.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
avgExcelRow.CreateCell(sampleCount + 2).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
avgExcelRow.CreateCell(sampleCount + 3).CellStyle = styles.yellowStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(avgRowIndex, avgRowIndex, sampleCount + 1, sampleCount + 3));
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查找最大值行
|
|
|
|
|
|
for (int i = 0; i < dataTable.Rows.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
string rowName = dataTable.Rows[i]["序号"]?.ToString() ?? "";
|
|
|
|
|
|
if (rowName.Contains("最大"))
|
|
|
|
|
|
{
|
|
|
|
|
|
int maxRowIndex = currentRow - (dataTable.Rows.Count - i);
|
|
|
|
|
|
IRow maxExcelRow = sheet.GetRow(maxRowIndex);
|
|
|
|
|
|
if (maxExcelRow != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ICell calcCell = maxExcelRow.CreateCell(sampleCount + 1);
|
|
|
|
|
|
calcCell.SetCellValue("系统计算");
|
|
|
|
|
|
calcCell.CellStyle = styles.yellowStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
private void CreateForm3Section(ISheet sheet, ref int currentRow, int sampleCount, DataTable dataTable,
|
|
|
|
|
|
(ICellStyle titleStyle, ICellStyle headerStyle, ICellStyle dataStyle, ICellStyle yellowStyle) styles)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 子标题
|
|
|
|
|
|
IRow subtitleRow = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
subtitleRow.Height = 500;
|
|
|
|
|
|
ICell subtitleCell = subtitleRow.CreateCell(0);
|
|
|
|
|
|
subtitleCell.SetCellValue("液体芯吸速率");
|
|
|
|
|
|
subtitleCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
for (int i = 1; i <= sampleCount * 3; i++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
subtitleRow.CreateCell(i).CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow - 1, 0, sampleCount * 3));
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 第一行表头(纵向/横向)
|
|
|
|
|
|
IRow headerRow1 = sheet.CreateRow(currentRow);
|
|
|
|
|
|
headerRow1.Height = 400;
|
|
|
|
|
|
ICell seqCell1 = headerRow1.CreateCell(0);
|
|
|
|
|
|
seqCell1.SetCellValue("序号");
|
|
|
|
|
|
seqCell1.CellStyle = styles.headerStyle;
|
|
|
|
|
|
|
|
|
|
|
|
ICell dirCell = headerRow1.CreateCell(1);
|
|
|
|
|
|
dirCell.SetCellValue("纵向/横向(选择按钮)");
|
|
|
|
|
|
dirCell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
for (int i = 2; i <= sampleCount * 3; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
headerRow1.CreateCell(i).CellStyle = styles.headerStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow, currentRow, 1, sampleCount * 3));
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
currentRow++;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 第二行表头(试样1-N,每个3列)
|
|
|
|
|
|
IRow headerRow2 = sheet.CreateRow(currentRow);
|
|
|
|
|
|
headerRow2.Height = 400;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 序号列在第二行也需要创建并设置样式(用于合并)
|
|
|
|
|
|
headerRow2.CreateCell(0).CellStyle = styles.headerStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
|
|
|
|
|
int colIndex = 1;
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
|
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = headerRow2.CreateCell(colIndex);
|
2025-12-31 17:54:34 +08:00
|
|
|
|
cell.SetCellValue($"试样{i}");
|
|
|
|
|
|
cell.CellStyle = styles.headerStyle;
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 为合并区域的所有单元格设置样式
|
|
|
|
|
|
headerRow2.CreateCell(colIndex + 1).CellStyle = styles.headerStyle;
|
|
|
|
|
|
headerRow2.CreateCell(colIndex + 2).CellStyle = styles.headerStyle;
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow, currentRow, colIndex, colIndex + 2));
|
2025-12-31 17:54:34 +08:00
|
|
|
|
colIndex += 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 合并序号列(跨两行)
|
|
|
|
|
|
sheet.AddMergedRegion(new CellRangeAddress(currentRow - 1, currentRow, 0, 0));
|
|
|
|
|
|
|
|
|
|
|
|
currentRow++;
|
|
|
|
|
|
|
|
|
|
|
|
// 第三行表头(1、2、3)
|
|
|
|
|
|
IRow headerRow3 = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
headerRow3.Height = 400;
|
|
|
|
|
|
|
2025-12-31 17:54:34 +08:00
|
|
|
|
colIndex = 1;
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int j = 1; j <= 3; j++)
|
|
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = headerRow3.CreateCell(colIndex++);
|
2025-12-31 17:54:34 +08:00
|
|
|
|
cell.SetCellValue(j.ToString());
|
|
|
|
|
|
cell.CellStyle = styles.headerStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
// 数据行
|
|
|
|
|
|
if (dataTable != null && dataTable.Rows.Count > 0)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
foreach (DataRow dataRow in dataTable.Rows)
|
|
|
|
|
|
{
|
|
|
|
|
|
string rowName = dataRow["序号"]?.ToString() ?? "";
|
|
|
|
|
|
if (string.IsNullOrEmpty(rowName)) continue;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
IRow row = sheet.CreateRow(currentRow++);
|
|
|
|
|
|
row.Height = 380;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell nameCell = row.CreateCell(0);
|
|
|
|
|
|
nameCell.SetCellValue(rowName);
|
|
|
|
|
|
nameCell.CellStyle = styles.dataStyle;
|
|
|
|
|
|
|
|
|
|
|
|
colIndex = 1;
|
|
|
|
|
|
for (int i = 1; i <= sampleCount; i++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
for (int j = 1; j <= 3; j++)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
ICell cell = row.CreateCell(colIndex++);
|
|
|
|
|
|
string columnName = $"试样{i}_{j}";
|
|
|
|
|
|
|
|
|
|
|
|
if (dataTable.Columns.Contains(columnName) && dataRow[columnName] != DBNull.Value)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
if (double.TryParse(dataRow[columnName].ToString(), out double value))
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
if (Math.Abs(value) >= 0.001)
|
|
|
|
|
|
{
|
|
|
|
|
|
cell.SetCellValue(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 所有空数据都显示为空白
|
|
|
|
|
|
cell.SetCellValue("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 所有空数据都显示为空白
|
|
|
|
|
|
cell.SetCellValue("");
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-31 18:36:52 +08:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// 所有空数据都显示为空白
|
|
|
|
|
|
cell.SetCellValue("");
|
|
|
|
|
|
}
|
|
|
|
|
|
cell.CellStyle = styles.yellowStyle;
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-31 18:36:52 +08:00
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
2025-12-31 17:54:34 +08:00
|
|
|
|
{
|
2025-12-31 18:36:52 +08:00
|
|
|
|
clockTimer?.Stop();
|
|
|
|
|
|
clockTimer?.Dispose();
|
|
|
|
|
|
Application.Exit();
|
2025-12-31 17:54:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private (ICellStyle titleStyle, ICellStyle headerStyle, ICellStyle dataStyle, ICellStyle yellowStyle)
|
|
|
|
|
|
CreateReportStyles(IWorkbook workbook)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 标题样式
|
|
|
|
|
|
ICellStyle titleStyle = workbook.CreateCellStyle();
|
|
|
|
|
|
IFont titleFont = workbook.CreateFont();
|
|
|
|
|
|
titleFont.FontHeightInPoints = 16;
|
|
|
|
|
|
titleFont.IsBold = true;
|
|
|
|
|
|
titleStyle.SetFont(titleFont);
|
|
|
|
|
|
titleStyle.Alignment = NPOIHorizontalAlignment.Center;
|
|
|
|
|
|
titleStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
|
|
|
|
|
|
|
|
|
// 表头样式(灰色背景)
|
|
|
|
|
|
ICellStyle headerStyle = workbook.CreateCellStyle();
|
|
|
|
|
|
headerStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Grey25Percent.Index;
|
|
|
|
|
|
headerStyle.FillPattern = FillPattern.SolidForeground;
|
|
|
|
|
|
SetBorders(headerStyle);
|
|
|
|
|
|
IFont headerFont = workbook.CreateFont();
|
|
|
|
|
|
headerFont.IsBold = true;
|
|
|
|
|
|
headerStyle.SetFont(headerFont);
|
|
|
|
|
|
headerStyle.Alignment = NPOIHorizontalAlignment.Center;
|
|
|
|
|
|
headerStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
|
|
|
|
|
|
|
|
|
// 数据样式(白色背景)
|
|
|
|
|
|
ICellStyle dataStyle = workbook.CreateCellStyle();
|
|
|
|
|
|
SetBorders(dataStyle);
|
|
|
|
|
|
dataStyle.Alignment = NPOIHorizontalAlignment.Center;
|
|
|
|
|
|
dataStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
|
|
|
|
|
|
|
|
|
// 黄色背景样式
|
|
|
|
|
|
ICellStyle yellowStyle = workbook.CreateCellStyle();
|
|
|
|
|
|
yellowStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.LightYellow.Index;
|
|
|
|
|
|
yellowStyle.FillPattern = FillPattern.SolidForeground;
|
|
|
|
|
|
SetBorders(yellowStyle);
|
|
|
|
|
|
yellowStyle.Alignment = NPOIHorizontalAlignment.Center;
|
|
|
|
|
|
yellowStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
|
|
|
|
|
|
|
|
|
|
return (titleStyle, headerStyle, dataStyle, yellowStyle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetBorders(ICellStyle style)
|
|
|
|
|
|
{
|
|
|
|
|
|
style.BorderBottom = NPOIBorderStyle.Thin;
|
|
|
|
|
|
style.BorderTop = NPOIBorderStyle.Thin;
|
|
|
|
|
|
style.BorderLeft = NPOIBorderStyle.Thin;
|
|
|
|
|
|
style.BorderRight = NPOIBorderStyle.Thin;
|
|
|
|
|
|
}
|
2025-12-31 09:43:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|