85 lines
2.8 KiB
C#
85 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.Office.Interop.Excel;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using bsmd.database;
|
|
|
|
namespace ENI2.Excel
|
|
{
|
|
static class ExcelSimpleWriter
|
|
{
|
|
public static void WriteMaerskList(string filename, List<MaerskData> data)
|
|
{
|
|
data.Sort();
|
|
|
|
Application excelApp = new Application();
|
|
excelApp.DisplayAlerts = false;
|
|
excelApp.Visible = false;
|
|
Workbook wb = excelApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);
|
|
|
|
Worksheet ws = wb.Worksheets[1];
|
|
|
|
// Überschriften erste Zeile
|
|
ws.Cells[1, 1] = "ETA";
|
|
ws.Cells[1, 2] = "ETD";
|
|
ws.Cells[1, 3] = "Rotation name";
|
|
ws.Cells[1, 4] = "Vessel code";
|
|
ws.Cells[1, 5] = "Vessel name";
|
|
ws.Cells[1, 6] = "IMO";
|
|
ws.Cells[1, 7] = "Arr voy";
|
|
ws.Cells[1, 8] = "Dep voy";
|
|
ws.Cells[1, 9] = "Terminal name";
|
|
ws.Cells[1, 10] = "Operator code";
|
|
ws.Cells[1, 11] = "Pro arr";
|
|
ws.Cells[1, 12] = "Pro dep";
|
|
ws.Cells[1, 13] = "ID";
|
|
ws.Cells[1, 14] = "Remark";
|
|
|
|
for (int i = 0; i < data.Count; i++)
|
|
{
|
|
MaerskData md = data[i];
|
|
|
|
ws.Cells[i + 2, 1].NumberFormat = "TT/hh:mm";
|
|
ws.Cells[i + 2, 1] = md.ColA;
|
|
ws.Cells[i + 2, 2].NumberFormat = "TT/hh:mm";
|
|
ws.Cells[i + 2, 2] = md.ColB;
|
|
ws.Cells[i + 2, 3] = md.ColC;
|
|
ws.Cells[i + 2, 4] = md.ColD;
|
|
ws.Cells[i + 2, 5] = md.ColE;
|
|
ws.Cells[i + 2, 6] = md.ColF;
|
|
ws.Cells[i + 2, 7] = md.ColG;
|
|
ws.Cells[i + 2, 8] = md.ColH;
|
|
ws.Cells[i + 2, 9] = md.ColI;
|
|
ws.Cells[i + 2, 10] = md.ColJ;
|
|
ws.Cells[i + 2, 11] = md.ColK;
|
|
ws.Cells[i + 2, 12] = md.ColL;
|
|
ws.Cells[i + 2, 13] = md.ColM ;
|
|
// ws.Cells[i + 2, 14] = md.Remark;
|
|
|
|
if((md.MessageCore != null) && (md.MessageCore.Cancelled ?? false))
|
|
{
|
|
ws.Rows[i + 2].Font.Strikethrough = true;
|
|
}
|
|
|
|
}
|
|
|
|
wb.SaveAs(filename, XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing,
|
|
Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing,
|
|
Type.Missing, Type.Missing);
|
|
wb.Saved = true;
|
|
wb.Close(0);
|
|
|
|
Marshal.ReleaseComObject(ws);
|
|
Marshal.ReleaseComObject(wb);
|
|
|
|
excelApp.Quit();
|
|
Marshal.ReleaseComObject(excelApp);
|
|
}
|
|
}
|
|
}
|