You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
4.3 KiB

using GummingCommon;
using GummingControl;
using GummingEntity;
using NPOI.HSSF.UserModel;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SQLite;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GummingBusiness
{
public class SysLogExport
{
public static void Export(ObservableCollection<SysLogEntity> rows, string targetFile)
{
try
{
XSSFWorkbook workbook = new XSSFWorkbook();
int headRowIndex = 0;
ISheet sheet = workbook.CreateSheet("日志");
XSSFRow headerRowd = (XSSFRow)sheet.CreateRow(headRowIndex);
ICellStyle headStyle = workbook.CreateCellStyle();
headStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
IFont font = workbook.CreateFont();
font.FontHeightInPoints = 10;
font.Boldweight = 700;
headStyle.SetFont(font);
int columIndex = 0;
headerRowd.CreateCell(columIndex).SetCellValue("日志编号");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("作业配方");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("日志类型");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("片数");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("完成状态");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("日志详情");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("开始时间");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
headerRowd.CreateCell(columIndex).SetCellValue("结束时间");
headerRowd.GetCell(columIndex).CellStyle = headStyle;
columIndex++;
ICellStyle s = workbook.CreateCellStyle();
s.FillForegroundColor = HSSFColor.Red.Index;
s.FillPattern = FillPattern.SolidForeground;
int rowIndex = 0;
foreach (SysLogEntity row in rows)
{
rowIndex++;
XSSFRow dataRow = (XSSFRow)sheet.CreateRow(rowIndex);
columIndex = 0;
dataRow.CreateCell(columIndex).SetCellValue(row.LogCode);
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.LogName);
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.LogType);
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.Pieces.ToString());
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.LogStatus);
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.LogDetail);
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.StartTime.ToString("yyyy-MM-dd"));
columIndex++;
dataRow.CreateCell(columIndex).SetCellValue(row.EndTime.ToString("yyyy-MM-dd"));
columIndex++;
}
FileStream fs = new FileStream(targetFile, FileMode.OpenOrCreate, FileAccess.Write);
workbook.Write(fs);
fs.Close();
}
catch (Exception ex)
{
throw new Exception("导出:" + targetFile + "失败:" + ex.Message);
}
}
}
}