This commit is contained in:
@@ -103,9 +103,9 @@ namespace 建材不燃性试验炉
|
||||
_testTimer.Tick += TestTimer_Tick;
|
||||
|
||||
//初始化平衡判断定时器
|
||||
_balanceTimer = new DispatcherTimer();
|
||||
_balanceTimer.Interval = TimeSpan.FromSeconds(1);
|
||||
_balanceTimer.Tick += BalanceTimer_Tick;
|
||||
//_balanceTimer = new DispatcherTimer();
|
||||
//_balanceTimer.Interval = TimeSpan.FromSeconds(1);
|
||||
//_balanceTimer.Tick += BalanceTimer_Tick;
|
||||
}
|
||||
|
||||
private void InitializeControls()
|
||||
@@ -203,63 +203,63 @@ namespace 建材不燃性试验炉
|
||||
}
|
||||
}
|
||||
|
||||
private void BalanceTimer_Tick(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 1. 计时递增
|
||||
_balanceElapsedSeconds++;
|
||||
txtBalanceTimeElapsed.Text = $"{_balanceElapsedSeconds}秒";
|
||||
//private void BalanceTimer_Tick(object sender, EventArgs e)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// // 1. 计时递增
|
||||
// _balanceElapsedSeconds++;
|
||||
// txtBalanceTimeElapsed.Text = $"{_balanceElapsedSeconds}秒";
|
||||
|
||||
|
||||
// 2. 采集当前炉壁温度
|
||||
double currentTemp = GetCurrentFurnaceTemp();
|
||||
_tempDataList.Add(currentTemp);
|
||||
// // 2. 采集当前炉壁温度
|
||||
// double currentTemp = GetCurrentFurnaceTemp();
|
||||
// _tempDataList.Add(currentTemp);
|
||||
|
||||
// 4. 计算最大值、最小值、平均值
|
||||
_maxTemp = double.MinValue;
|
||||
_minTemp = double.MaxValue;
|
||||
double sumTemp = 0;
|
||||
// // 4. 计算最大值、最小值、平均值
|
||||
// _maxTemp = double.MinValue;
|
||||
// _minTemp = double.MaxValue;
|
||||
// double sumTemp = 0;
|
||||
|
||||
foreach (var temp in _tempDataList)
|
||||
{
|
||||
if (temp > _maxTemp) _maxTemp = temp;
|
||||
if (temp < _minTemp) _minTemp = temp;
|
||||
sumTemp += temp;
|
||||
}
|
||||
// foreach (var temp in _tempDataList)
|
||||
// {
|
||||
// if (temp > _maxTemp) _maxTemp = temp;
|
||||
// if (temp < _minTemp) _minTemp = temp;
|
||||
// sumTemp += temp;
|
||||
// }
|
||||
|
||||
_avgTemp = sumTemp / _tempDataList.Count;
|
||||
double currentMaxDiff = _maxTemp - _avgTemp; // 最大值与平均值的温差
|
||||
double tempRange = _maxTemp - _minTemp; // 温度波动范围
|
||||
// _avgTemp = sumTemp / _tempDataList.Count;
|
||||
// double currentMaxDiff = _maxTemp - _avgTemp; // 最大值与平均值的温差
|
||||
// double tempRange = _maxTemp - _minTemp; // 温度波动范围
|
||||
|
||||
|
||||
txtBalanceCondition.Text = $"平衡条件: 最大温差≤{_maxTempDiffThreshold}°C 且 温度波动≤±{_tempRangeThreshold}°C (当前: {tempRange:F1}°C)";
|
||||
// txtBalanceCondition.Text = $"平衡条件: 最大温差≤{_maxTempDiffThreshold}°C 且 温度波动≤±{_tempRangeThreshold}°C (当前: {tempRange:F1}°C)";
|
||||
|
||||
// 6. 判断是否达到平衡条件(计时结束后)
|
||||
if (_balanceElapsedSeconds >= _balanceTotalSeconds)
|
||||
{
|
||||
_balanceTimer.Stop(); // 停止定时器
|
||||
_isBalanceChecking = false;
|
||||
// // 6. 判断是否达到平衡条件(计时结束后)
|
||||
// if (_balanceElapsedSeconds >= _balanceTotalSeconds)
|
||||
// {
|
||||
// _balanceTimer.Stop(); // 停止定时器
|
||||
// _isBalanceChecking = false;
|
||||
|
||||
bool isBalanced = currentMaxDiff <= _maxTempDiffThreshold && tempRange <= _tempRangeThreshold * 2;
|
||||
// bool isBalanced = currentMaxDiff <= _maxTempDiffThreshold && tempRange <= _tempRangeThreshold * 2;
|
||||
|
||||
// 更新平衡状态显示
|
||||
if (isBalanced)
|
||||
{
|
||||
balanceStatusBorder.Background = new SolidColorBrush(Colors.Green);
|
||||
txtBalanceResult.Text = "已平衡";
|
||||
txtBalanceStatus.Text = $"温度平衡状态: 达到平衡(最大温差{currentMaxDiff:F1}°C,温度波动{tempRange:F1}°C)";
|
||||
UpdateStatusBar("温度平衡判断完成:炉温已稳定");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"温度平衡判断出错:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
_balanceTimer.Stop();
|
||||
_isBalanceChecking = false;
|
||||
}
|
||||
}
|
||||
// // 更新平衡状态显示
|
||||
// if (isBalanced)
|
||||
// {
|
||||
// balanceStatusBorder.Background = new SolidColorBrush(Colors.Green);
|
||||
// txtBalanceResult.Text = "已平衡";
|
||||
// txtBalanceStatus.Text = $"温度平衡状态: 达到平衡(最大温差{currentMaxDiff:F1}°C,温度波动{tempRange:F1}°C)";
|
||||
// UpdateStatusBar("温度平衡判断完成:炉温已稳定");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// MessageBox.Show($"温度平衡判断出错:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
// _balanceTimer.Stop();
|
||||
// _isBalanceChecking = false;
|
||||
// }
|
||||
//}
|
||||
|
||||
// 获取当前炉壁温度
|
||||
private double GetCurrentFurnaceTemp()
|
||||
@@ -635,17 +635,6 @@ namespace 建材不燃性试验炉
|
||||
#endregion
|
||||
|
||||
#region 温度监控相关
|
||||
//private void UpdateSimulatedTemperatures()
|
||||
//{
|
||||
|
||||
// // 试验中的温度模拟
|
||||
// double furnaceWallTemp = 750 + (_random.NextDouble() * 10 - 5); // 750±5°C
|
||||
// double sampleCenterTemp = 500 + (_random.NextDouble() * 50 - 25); // 500±25°C
|
||||
// double sampleSurfaceTemp = 600 + (_random.NextDouble() * 40 - 20); // 600±20°C
|
||||
|
||||
// UpdateTemperatureDisplay(furnaceWallTemp, sampleCenterTemp, sampleSurfaceTemp);
|
||||
|
||||
//}
|
||||
|
||||
private void UpdateSimulatedTemperatures()
|
||||
{
|
||||
@@ -1492,16 +1481,16 @@ namespace 建材不燃性试验炉
|
||||
txtBalanceResult.Text = "判断中";
|
||||
|
||||
// 更新目标温度显示(如果存在)
|
||||
if (txtTestTemp != null)
|
||||
{
|
||||
txtTestTemp.Text = "750"; // 标准目标温度
|
||||
}
|
||||
//if (txtTestTemp != null)
|
||||
//{
|
||||
// txtTestTemp.Text = "750"; // 标准目标温度
|
||||
//}
|
||||
}
|
||||
|
||||
private void StartBalanceCheck()
|
||||
{
|
||||
// 停止现有定时器
|
||||
_balanceTimer?.Stop();
|
||||
//_balanceTimer?.Stop();
|
||||
|
||||
// 创建新的平衡判断定时器(每秒检查一次)
|
||||
_balanceTimer = new DispatcherTimer();
|
||||
|
||||
@@ -87,22 +87,22 @@
|
||||
<DataGridTextColumn Header="试样编号" Binding="{Binding SampleCode}" Width="80"/>
|
||||
<DataGridTextColumn Header="试样名称" Binding="{Binding SampleName}" Width="100"/>
|
||||
<DataGridTextColumn Header="试样规格" Binding="{Binding SampleSpec}" Width="80"/>
|
||||
<DataGridTextColumn Header="初始温度(℃)" Binding="{Binding InitialTemp, StringFormat=\{0:F1\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="最高温度(℃)" Binding="{Binding MaxTemp, StringFormat=\{0:F1\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="最终温度(℃)" Binding="{Binding FinalTemp, StringFormat=\{0:F1\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="温升(℃)" Binding="{Binding TempRise, StringFormat=\{0:F1\}}" Width="80"/>
|
||||
<DataGridTextColumn Header="中心最高温(℃)" Binding="{Binding CenterMaxTemp, StringFormat=\{0:F1\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="中心最终温(℃)" Binding="{Binding CenterFinalTemp, StringFormat=\{0:F1\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="表面最高温(℃)" Binding="{Binding SurfaceMaxTemp, StringFormat=\{0:F1\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="表面最终温(℃)" Binding="{Binding SurfaceFinalTemp, StringFormat=\{0:F1\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="初始质量(g)" Binding="{Binding InitialWeight, StringFormat=\{0:F2\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="结束质量(g)" Binding="{Binding FinalWeight, StringFormat=\{0:F2\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="质量损失(%)" Binding="{Binding LossPercent, StringFormat=\{0:F2\}}" Width="90"/>
|
||||
<DataGridTextColumn Header="火焰时间(s)" Binding="{Binding FlameDuration}" Width="90"/>
|
||||
<DataGridTextColumn Header="炉内初始温(℃)" Binding="{Binding InitialTemp, StringFormat=\{0:F1\}}" Width="115"/>
|
||||
<DataGridTextColumn Header="炉内最高温(℃)" Binding="{Binding MaxTemp, StringFormat=\{0:F1\}}" Width="115"/>
|
||||
<DataGridTextColumn Header="炉内最终温(℃)" Binding="{Binding FinalTemp, StringFormat=\{0:F1\}}" Width="115"/>
|
||||
<DataGridTextColumn Header="温升(℃)" Binding="{Binding TempRise, StringFormat=\{0:F1\}}" Width="72"/>
|
||||
<DataGridTextColumn Header="试样中心最高温(℃)" Binding="{Binding CenterMaxTemp, StringFormat=\{0:F1\}}" Width="142"/>
|
||||
<DataGridTextColumn Header="试样中心最终温(℃)" Binding="{Binding CenterFinalTemp, StringFormat=\{0:F1\}}" Width="142"/>
|
||||
<DataGridTextColumn Header="试样表面最高温(℃)" Binding="{Binding SurfaceMaxTemp, StringFormat=\{0:F1\}}" Width="142"/>
|
||||
<DataGridTextColumn Header="试样表面最终温(℃)" Binding="{Binding SurfaceFinalTemp, StringFormat=\{0:F1\}}" Width="142"/>
|
||||
<DataGridTextColumn Header="初始质量(g)" Binding="{Binding InitialWeight, StringFormat=\{0:F2\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="结束质量(g)" Binding="{Binding FinalWeight, StringFormat=\{0:F2\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="质量损失(%)" Binding="{Binding LossPercent, StringFormat=\{0:F2\}}" Width="100"/>
|
||||
<DataGridTextColumn Header="火焰时间(s)" Binding="{Binding FlameDuration}" Width="100"/>
|
||||
<DataGridTextColumn Header="试验日期" Binding="{Binding TestDate}" Width="100"/>
|
||||
<DataGridTextColumn Header="持续时间" Binding="{Binding TestDuration}" Width="80"/>
|
||||
<DataGridTextColumn Header="平衡状态" Binding="{Binding BalanceStatus}" Width="80"/>
|
||||
<DataGridTextColumn Header="备注" Binding="{Binding Remarks}" Width="150"/>
|
||||
<DataGridTextColumn Header="平衡状态" Binding="{Binding BalanceStatus}" Width="100"/>
|
||||
<DataGridTextColumn Header="备注" Binding="{Binding Remarks}" Width="130"/>
|
||||
</DataGrid.Columns>
|
||||
|
||||
<DataGrid.CellStyle>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using jiancaiburanxing.data;
|
||||
using ClosedXML.Excel;
|
||||
using jiancaiburanxing.data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -165,37 +166,212 @@ namespace jiancaiburanxing
|
||||
|
||||
|
||||
// 导出到Excel(简化版本)
|
||||
private void ExportToExcel(string filePath)
|
||||
{
|
||||
using (var writer = new StreamWriter(filePath, false, Encoding.UTF8))
|
||||
{
|
||||
// 写入标题
|
||||
writer.WriteLine("建材不燃性试验数据报表");
|
||||
writer.WriteLine($"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
writer.WriteLine("符合标准: GB/T 5464-2010");
|
||||
writer.WriteLine();
|
||||
//private void ExportToExcel(string filePath)
|
||||
//{
|
||||
// using (var writer = new StreamWriter(filePath, false, Encoding.UTF8))
|
||||
// {
|
||||
// // 写入标题
|
||||
// writer.WriteLine("建材不燃性试验数据报表");
|
||||
// writer.WriteLine($"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}");
|
||||
// writer.WriteLine("符合标准: GB/T 5464-2010");
|
||||
// writer.WriteLine();
|
||||
|
||||
// 写入表头
|
||||
writer.WriteLine("试样编号,试样名称,试样规格,炉内初始温度(℃),炉内最高温度(℃),炉内最终温度(℃),温升(℃)," +
|
||||
"试样中心最高温度(℃),试样中心最终温度(℃),试样表面最高温度(℃),试样表面最终温度(℃)," +
|
||||
"试样初始质量(g),试样结束质量(g),质量损失(%),火焰持续时间(s),试验日期,试验持续时间,平衡状态,备注");
|
||||
// // 写入表头
|
||||
// writer.WriteLine("试样编号,试样名称,试样规格,炉内初始温度(℃),炉内最高温度(℃),炉内最终温度(℃),温升(℃)," +
|
||||
// "试样中心最高温度(℃),试样中心最终温度(℃),试样表面最高温度(℃),试样表面最终温度(℃)," +
|
||||
// "试样初始质量(g),试样结束质量(g),质量损失(%),火焰持续时间(s),试验日期,试验持续时间,平衡状态,备注");
|
||||
|
||||
// 写入数据
|
||||
foreach (var item in _testData)
|
||||
{
|
||||
writer.WriteLine($"{item.SampleCode},{item.SampleName},{item.SampleSpec}," +
|
||||
$"{item.InitialTemp:F1},{item.MaxTemp:F1},{item.FinalTemp:F1},{item.TempRise:F1}," +
|
||||
$"{item.CenterMaxTemp:F1},{item.CenterFinalTemp:F1},{item.SurfaceMaxTemp:F1},{item.SurfaceFinalTemp:F1}," +
|
||||
$"{item.InitialWeight:F2},{item.FinalWeight:F2},{item.LossPercent:F2}," +
|
||||
$"{item.FlameDuration},{item.TestDate},{item.TestDuration},{item.BalanceStatus},{item.Remarks}");
|
||||
}
|
||||
}
|
||||
}
|
||||
// // 写入数据
|
||||
// foreach (var item in _testData)
|
||||
// {
|
||||
// writer.WriteLine($"{item.SampleCode},{item.SampleName},{item.SampleSpec}," +
|
||||
// $"{item.InitialTemp:F1},{item.MaxTemp:F1},{item.FinalTemp:F1},{item.TempRise:F1}," +
|
||||
// $"{item.CenterMaxTemp:F1},{item.CenterFinalTemp:F1},{item.SurfaceMaxTemp:F1},{item.SurfaceFinalTemp:F1}," +
|
||||
// $"{item.InitialWeight:F2},{item.FinalWeight:F2},{item.LossPercent:F2}," +
|
||||
// $"{item.FlameDuration},{item.TestDate},{item.TestDuration},{item.BalanceStatus},{item.Remarks}");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
// 添加新的试验数据(由主窗口调用)
|
||||
|
||||
private void ExportToExcel(string filePath)
|
||||
{
|
||||
using (var workbook = new XLWorkbook())
|
||||
{
|
||||
// 创建一个工作表
|
||||
var worksheet = workbook.Worksheets.Add("不燃性试验报告");
|
||||
|
||||
// 设置整体样式
|
||||
worksheet.Style.Font.FontName = "微软雅黑";
|
||||
worksheet.Style.Font.FontSize = 10;
|
||||
|
||||
// 1. 标题行
|
||||
var titleRow1 = worksheet.Cell(1, 1);
|
||||
titleRow1.Value = "建材不燃性试验数据报表";
|
||||
titleRow1.Style.Font.FontSize = 16;
|
||||
titleRow1.Style.Font.Bold = true;
|
||||
titleRow1.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
titleRow1.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
worksheet.Range(1, 1, 1, 19).Merge(); // 合并单元格,19列(增加4个温度字段)
|
||||
|
||||
var titleRow2 = worksheet.Cell(2, 1);
|
||||
titleRow2.Value = $"生成时间: {DateTime.Now:yyyy-MM-dd HH:mm:ss}";
|
||||
titleRow2.Style.Font.FontSize = 11;
|
||||
titleRow2.Style.Font.Italic = true;
|
||||
worksheet.Range(2, 1, 2, 19).Merge();
|
||||
|
||||
var titleRow3 = worksheet.Cell(3, 1);
|
||||
titleRow3.Value = "符合标准: GB/T 5464-2010";
|
||||
titleRow3.Style.Font.FontSize = 11;
|
||||
worksheet.Range(3, 1, 3, 19).Merge();
|
||||
|
||||
// 空行
|
||||
worksheet.Row(4).Height = 10;
|
||||
|
||||
// 2. 表头(共19列)
|
||||
var headers = new string[]
|
||||
{
|
||||
"试样编号", "试样名称", "试样规格",
|
||||
"炉内初始温度(℃)", "炉内最高温度(℃)", "炉内最终温度(℃)", "温升(℃)",
|
||||
"试样中心最高温(℃)", "试样中心最终温(℃)", // 新增字段
|
||||
"试样表面最高温(℃)", "试样表面最终温(℃)", // 新增字段
|
||||
"试样初始质量(g)", "试样结束质量(g)", "质量损失(%)",
|
||||
"火焰持续时间(s)", "试验日期", "试验持续时间", "平衡状态", "备注"
|
||||
};
|
||||
|
||||
int rowIndex = 5;
|
||||
for (int i = 0; i < headers.Length; i++)
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, i + 1);
|
||||
cell.Value = headers[i];
|
||||
cell.Style.Font.Bold = true;
|
||||
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
cell.Style.Fill.BackgroundColor = XLColor.LightGray;
|
||||
cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 设置列宽(根据内容调整)
|
||||
switch (i)
|
||||
{
|
||||
case 0: worksheet.Column(i + 1).Width = 12; break; // 试样编号
|
||||
case 1: worksheet.Column(i + 1).Width = 15; break; // 试样名称
|
||||
case 2: worksheet.Column(i + 1).Width = 10; break; // 试样规格
|
||||
case 3: worksheet.Column(i + 1).Width = 15; break; // 炉内初始温度
|
||||
case 4: worksheet.Column(i + 1).Width = 15; break; // 炉内最高温度
|
||||
case 5: worksheet.Column(i + 1).Width = 15; break; // 炉内最终温度
|
||||
case 6: worksheet.Column(i + 1).Width = 12; break; // 温升
|
||||
case 7: worksheet.Column(i + 1).Width = 15; break; // 试样中心最高温度
|
||||
case 8: worksheet.Column(i + 1).Width = 15; break; // 试样中心最终温度
|
||||
case 9: worksheet.Column(i + 1).Width = 15; break; // 试样表面最高温度
|
||||
case 10: worksheet.Column(i + 1).Width = 15; break; // 试样表面最终温度
|
||||
case 11: worksheet.Column(i + 1).Width = 15; break; // 试样初始质量
|
||||
case 12: worksheet.Column(i + 1).Width = 15; break; // 试样结束质量
|
||||
case 13: worksheet.Column(i + 1).Width = 12; break; // 质量损失
|
||||
case 14: worksheet.Column(i + 1).Width = 15; break; // 火焰持续时间
|
||||
case 15: worksheet.Column(i + 1).Width = 12; break; // 试验日期
|
||||
case 16: worksheet.Column(i + 1).Width = 12; break; // 试验持续时间
|
||||
case 17: worksheet.Column(i + 1).Width = 12; break; // 平衡状态
|
||||
case 18: worksheet.Column(i + 1).Width = 20; break; // 备注
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 数据行
|
||||
rowIndex++;
|
||||
foreach (var item in _testData)
|
||||
{
|
||||
worksheet.Cell(rowIndex, 1).Value = item.SampleCode;
|
||||
worksheet.Cell(rowIndex, 2).Value = item.SampleName;
|
||||
worksheet.Cell(rowIndex, 3).Value = item.SampleSpec;
|
||||
worksheet.Cell(rowIndex, 4).Value = item.InitialTemp;
|
||||
worksheet.Cell(rowIndex, 5).Value = item.MaxTemp;
|
||||
worksheet.Cell(rowIndex, 6).Value = item.FinalTemp;
|
||||
worksheet.Cell(rowIndex, 7).Value = item.TempRise;
|
||||
|
||||
// 新增的4个温度字段
|
||||
worksheet.Cell(rowIndex, 8).Value = item.CenterMaxTemp;
|
||||
worksheet.Cell(rowIndex, 9).Value = item.CenterFinalTemp;
|
||||
worksheet.Cell(rowIndex, 10).Value = item.SurfaceMaxTemp;
|
||||
worksheet.Cell(rowIndex, 11).Value = item.SurfaceFinalTemp;
|
||||
|
||||
worksheet.Cell(rowIndex, 12).Value = item.InitialWeight;
|
||||
worksheet.Cell(rowIndex, 13).Value = item.FinalWeight;
|
||||
worksheet.Cell(rowIndex, 14).Value = item.LossPercent;
|
||||
worksheet.Cell(rowIndex, 15).Value = item.FlameDuration;
|
||||
worksheet.Cell(rowIndex, 16).Value = item.TestDate;
|
||||
worksheet.Cell(rowIndex, 17).Value = item.TestDuration;
|
||||
worksheet.Cell(rowIndex, 18).Value = item.BalanceStatus;
|
||||
worksheet.Cell(rowIndex, 19).Value = item.Remarks;
|
||||
|
||||
// 设置数据行样式
|
||||
for (int col = 1; col <= 19; col++)
|
||||
{
|
||||
var cell = worksheet.Cell(rowIndex, col);
|
||||
cell.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
|
||||
cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
|
||||
cell.Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
|
||||
cell.Style.Border.OutsideBorderColor = XLColor.Gray;
|
||||
|
||||
// 数值格式(温度和质量列保留一位小数)
|
||||
if ((col >= 4 && col <= 11) || col == 14) // 所有温度列 + 质量损失
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.0";
|
||||
}
|
||||
else if (col == 12 || col == 13) // 质量列
|
||||
{
|
||||
cell.Style.NumberFormat.Format = "0.00";
|
||||
}
|
||||
}
|
||||
|
||||
// 隔行变色
|
||||
if (rowIndex % 2 == 0)
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
worksheet.Range(rowIndex, 1, rowIndex, 19).Style
|
||||
.Fill.BackgroundColor = XLColor.LightSkyBlue;
|
||||
}
|
||||
|
||||
rowIndex++;
|
||||
}
|
||||
|
||||
// 4. 自动调整行高
|
||||
worksheet.Rows(5, rowIndex - 1).AdjustToContents();
|
||||
|
||||
// 5. 添加边框
|
||||
var dataRange = worksheet.Range(5, 1, rowIndex - 1, 19);
|
||||
dataRange.Style.Border.InsideBorder = XLBorderStyleValues.Thin;
|
||||
dataRange.Style.Border.InsideBorderColor = XLColor.Gray;
|
||||
dataRange.Style.Border.OutsideBorder = XLBorderStyleValues.Medium;
|
||||
dataRange.Style.Border.OutsideBorderColor = XLColor.Black;
|
||||
|
||||
// 6. 添加分组标识(可选)
|
||||
// 温度相关列设置不同背景色
|
||||
//var tempHeaderRange = worksheet.Range(5, 4, 5, 11);
|
||||
//tempHeaderRange.Style.Fill.BackgroundColor = XLColor.LightGreen;
|
||||
|
||||
//var weightHeaderRange = worksheet.Range(5, 12, 5, 14);
|
||||
//weightHeaderRange.Style.Fill.BackgroundColor = XLColor.LightYellow;
|
||||
|
||||
// 7. 添加页脚
|
||||
//var footerRow = worksheet.Cell(rowIndex + 2, 1);
|
||||
//footerRow.Value = "备注:本报表自动生成,数据仅供参考";
|
||||
//footerRow.Style.Font.FontSize = 9;
|
||||
//footerRow.Style.Font.FontColor = XLColor.Gray;
|
||||
//footerRow.Style.Font.Italic = true;
|
||||
//worksheet.Range(rowIndex + 2, 1, rowIndex + 2, 19).Merge();
|
||||
|
||||
// 8. 保存文件
|
||||
workbook.SaveAs(filePath);
|
||||
}
|
||||
}
|
||||
public void AddTestReportData(TestReportData data)
|
||||
{
|
||||
Dispatcher.Invoke(() =>
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ClosedXML" Version="0.105.0" />
|
||||
<PackageReference Include="DevExpress.Wpf.Core" Version="22.2.*-*" />
|
||||
<PackageReference Include="devexpress.wpf.layoutcontrol" Version="22.2.3" />
|
||||
<PackageReference Include="DevExpress.Wpf.Themes.All" Version="22.2.*-*" />
|
||||
|
||||
Reference in New Issue
Block a user