Skriv i excel ark med epplus
Hej folkens.Jeg sidder og er ved at lave et lille program der kan lave en alarmliste til en Siemens PLC. Det betyder at for hver komponent jeg har i mit projekt, skal jeg oprette mellem 2 og 5 alarm linjer i et excel-ark. Fx skal en motor generere Følgende alarmer:
1 Error Trip 0 1A01A-B01M01.status 0 0 0 POS 1A01A-B01M01 - SSW - -
2 Error Alarm 0 1A01A-B01M01.status 1 0 0 POS 1A01A-B01M01 - TH - -
3 Error Alarm 0 1A01A-B01M01.status 2 0 0 POS 1A01A-B01M01 - PIC - -
4 Error Alarm 0 1A01A-B01M01.status 3 0 0 POS 1A01A-B01M01 - SSW - -
for at lave det, ser min kode således ud:
foreach (HIComponent motor in MotorList)
{
ws.Cells[i, 1].Value = i;
ws.Cells[i, 2].Value = "Error";
ws.Cells[i, 3].Value = "Trip";
ws.Cells[i, 5].Value = 0;
ws.Cells[i, 6].Value = motor.Tag + ".status";
ws.Cells[i, 7].Value = 0;
ws.Cells[i, 12].Value = 0;
ws.Cells[i, 13].Value = 0;
ws.Cells[i, 14].Value = "POS " + motor.Tag + " - SSW - " + motor.Desc;
i++;
ws.Cells[i, 1].Value = i;
ws.Cells[i, 2].Value = "Error";
ws.Cells[i, 3].Value = "Alarm";
ws.Cells[i, 5].Value = 0;
ws.Cells[i, 6].Value = motor.Tag + ".status";
ws.Cells[i, 7].Value = 1;
ws.Cells[i, 12].Value = 0;
ws.Cells[i, 13].Value = 0;
ws.Cells[i, 14].Value = "POS " + motor.Tag + " - TH - " + motor.Desc;
i++;
ws.Cells[i, 1].Value = i;
ws.Cells[i, 2].Value = "Error";
ws.Cells[i, 3].Value = "Alarm";
ws.Cells[i, 5].Value = 0;
ws.Cells[i, 6].Value = motor.Tag + ".status";
ws.Cells[i, 7].Value = 2;
ws.Cells[i, 12].Value = 0;
ws.Cells[i, 13].Value = 0;
ws.Cells[i, 14].Value = "POS " + motor.Tag + " - PIC - " + motor.Desc;
i++;
ws.Cells[i, 1].Value = i;
ws.Cells[i, 2].Value = "Error";
ws.Cells[i, 3].Value = "Alarm";
ws.Cells[i, 5].Value = 0;
ws.Cells[i, 6].Value = motor.Tag + ".status";
ws.Cells[i, 7].Value = 3;
ws.Cells[i, 12].Value = 0;
ws.Cells[i, 13].Value = 0;
ws.Cells[i, 14].Value = "POS " + motor.Tag + " - SSW - " + motor.Desc;
i++;
}
Kan dette ikke gøres smartere?
hvis i undre jer, så indeholder motor.desc pt kun en "-".