I'm using epplus to write in a file an extense quantity of information in an excel template, but then I need to close the ExcelPackage as to be usable with the Excel application. It throws me this exception: "System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC"
private void FillCardsSheet()
{
xlPackage = new ExcelPackage(Template);
wsCards = xlPackage.Workbook.Worksheets[4];
string command = "SELECT * FROM dbo_serial_cards WHERE type <> 'EXT' AND LEFT([device_tag], 2) <> '!!'";
OleDbCommand cmd = new OleDbCommand(command, CON);
OleDbDataReader reader = cmd.ExecuteReader();
int row = 1;
while (reader.Read())
{
row++;
for (int col = 1; col <= 16; col++)
{
wsCards.Cells[row, col].Value = reader.GetValue(col - 1);
}
}
xlPackage.SaveAs(Template);
xlPackage.Dispose();
}