96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
using OfficeOpenXml;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace friction
|
|
{
|
|
public class Report
|
|
{
|
|
public string FilePath { set; get; }
|
|
public string MaterialSpring { set; get; }
|
|
public string MaterialTable { set; get; }
|
|
public DataTable AnalysisData { set; get; }
|
|
public Bitmap RadarChart { set; get; }
|
|
public Bitmap TrendChartByHumidity { set; get; }
|
|
public Bitmap TrendChartByTemperature { set; get; }
|
|
public Bitmap TrendChartByForce { set; get; }
|
|
public Bitmap TrendChartByVelocity { set; get; }
|
|
|
|
public void Export()
|
|
{
|
|
using (ExcelPackage package = new ExcelPackage())
|
|
{
|
|
if (package.Workbook.Worksheets.Count < 1)
|
|
package.Workbook.Worksheets.Add("Report");
|
|
|
|
ExcelWorksheet Sheet = package.Workbook.Worksheets[1];
|
|
|
|
int iRow = 2;
|
|
int iCol = 2;
|
|
|
|
Sheet.Cells[iRow, iCol].Value = "Material Spring: " + MaterialSpring;
|
|
Sheet.Cells[iRow, iCol].Style.Font.Bold = true;
|
|
|
|
iRow += 1;
|
|
foreach(DataColumn column in AnalysisData.Columns)
|
|
{
|
|
Sheet.Cells[iRow, iCol].Value = column.ColumnName;
|
|
iCol++;
|
|
}
|
|
iRow++;
|
|
iCol = 2;
|
|
|
|
int iTableRowStart = iRow-1;
|
|
int iTableColStart = iCol;
|
|
foreach(DataRow row in AnalysisData.Rows)
|
|
{
|
|
iCol = 2;
|
|
for (int i = 0; i < AnalysisData.Columns.Count; i++)
|
|
{
|
|
Sheet.Cells[iRow, iCol].Value = row[i];
|
|
iCol++;
|
|
}
|
|
|
|
iRow++;
|
|
}
|
|
|
|
Sheet.Cells[iTableRowStart, iTableColStart, iTableRowStart, iCol-1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
|
|
Sheet.Cells[iTableRowStart, iTableColStart, iRow-1, iTableColStart].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thin);
|
|
Sheet.Cells[iTableRowStart, iTableColStart, iRow-1, iCol-1].Style.Border.BorderAround(OfficeOpenXml.Style.ExcelBorderStyle.Thick);
|
|
Sheet.Cells[iTableRowStart, iTableColStart, iRow - 1, iCol - 1].AutoFitColumns();
|
|
|
|
iRow += 2;
|
|
iCol = 2;
|
|
|
|
var picRadarChart = Sheet.Drawings.AddPicture("Radar Chart", RadarChart);
|
|
picRadarChart.SetPosition(iRow, 0, iCol-1, 0);
|
|
iRow += 30;
|
|
|
|
//var picTrendChartHumidity = Sheet.Drawings.AddPicture("Trend Chart by Humidity", TrendChartByHumidity);
|
|
//picTrendChartHumidity.SetPosition(iRow, 0, iCol, 0);
|
|
//iRow += 30;
|
|
|
|
//var picTrendChartTemperature = Sheet.Drawings.AddPicture("Trend Chart by Temperature", TrendChartByTemperature);
|
|
//picTrendChartTemperature.SetPosition(iRow, 0, iCol, 0);
|
|
//iRow += 30;
|
|
|
|
//var picTrendChartForce = Sheet.Drawings.AddPicture("Trend Chart by Force", TrendChartByForce);
|
|
//picTrendChartForce.SetPosition(iRow, 0, iCol, 0);
|
|
//iRow += 30;
|
|
|
|
//var picTrendChartVelocity = Sheet.Drawings.AddPicture("Trend Chart by Velocity", TrendChartByVelocity);
|
|
//picTrendChartVelocity.SetPosition(iRow, 0, iCol, 0);
|
|
//iRow += 30;
|
|
|
|
package.SaveAs(new FileInfo(FilePath));
|
|
}
|
|
}
|
|
}
|
|
}
|