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.
85 lines
3.1 KiB
85 lines
3.1 KiB
using GummingCommon;
|
|
using GummingControl;
|
|
using GummingEntity;
|
|
using NPOI.HSSF.Util;
|
|
using NPOI.SS.UserModel;
|
|
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 SysWarningExport
|
|
{
|
|
public static void Export(ObservableCollection<SysWarningEntity> 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++;
|
|
|
|
ICellStyle s = workbook.CreateCellStyle();
|
|
s.FillForegroundColor = HSSFColor.Red.Index;
|
|
s.FillPattern = FillPattern.SolidForeground;
|
|
int rowIndex = 0;
|
|
foreach (SysWarningEntity row in rows)
|
|
{
|
|
rowIndex++;
|
|
|
|
XSSFRow dataRow = (XSSFRow)sheet.CreateRow(rowIndex);
|
|
columIndex = 0;
|
|
dataRow.CreateCell(columIndex).SetCellValue(row.WarnName);
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|