Chào anh Long và mọi người, em đang làm 1 phần mềm quản lý quán cafe bằng WPF+MVVM, em làm đến phần xuất excel, em có tham khảo trên howkteam và làm thử, khi em chạy thì báo lỗi như thế này:

Đoạn code của em là:
string filePath = "";
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Excel 2016 | *.xls";
if (dialog.ShowDialog() == true)
{
filePath = dialog.FileName;
}
if (string.IsNullOrEmpty(filePath))
{
MessageBox.Show("Đường dẫn báo cáo không hợp lệ");
return;
}
try
{
using (ExcelPackage x = new ExcelPackage())
{
x.Workbook.Properties.Author = "Nhóm sinh viên trường Đại Học Công Nghiệp Thực Phẩm TPHCM";
x.Workbook.Properties.Title = "Phiếu nhập kho";
x.Workbook.Worksheets.Add("Kteam sheet");
ExcelWorksheet ws = x.Workbook.Worksheets[1];
ws.Name = "Phiếu nhập kho";
ws.Cells.Style.Font.Size = 14;
ws.Cells.Style.Font.Name = "Times New Roman";
string[] arrColumnHeader = {
"STT",
"Tên thức ăn",
"Tên nhà cung cấp",
"Ngày nhập",
"Số lượng",
"Giá nhập",
"Thành tiền nhập",
"Giá xuất",
"Trạng thái nhập",
"Nhân viên nhập kho"
};
var countColHeader = arrColumnHeader.Count();
ws.Cells[1, 1].Value = "Thống kê thông tin User Kteam";
ws.Cells[1, 1, 1, countColHeader].Merge = true;
ws.Cells[1, 1, 1, countColHeader].Style.Font.Bold = true;
ws.Cells[1, 1, 1, countColHeader].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
int colIndex = 1;
int rowIndex = 2;
foreach (var item in arrColumnHeader)
{
var cell = ws.Cells[rowIndex, colIndex];
var fill = cell.Style.Fill;
fill.PatternType = ExcelFillStyle.Solid;
fill.BackgroundColor.SetColor(System.Drawing.Color.LightBlue);
var border = cell.Style.Border;
border.Bottom.Style =
border.Top.Style =
border.Left.Style =
border.Right.Style = ExcelBorderStyle.Thin;
cell.Value = item;
colIndex++;
}
foreach (var item in List)
{
colIndex = 1;
rowIndex++;
ws.Cells[rowIndex, colIndex++].Value =item.Id;
ws.Cells[rowIndex, colIndex++].Value = item.Food.Name;
ws.Cells[rowIndex, colIndex++].Value = item.Suplier.DisplayName;
ws.Cells[rowIndex, colIndex++].Value = item.Count;
ws.Cells[rowIndex, colIndex++].Value = item.InputPrice;
ws.Cells[rowIndex, colIndex++].Value = item.TotalInputPrice;
ws.Cells[rowIndex, colIndex++].Value = item.OutputPrice;
ws.Cells[rowIndex, colIndex++].Value = item.Status;
ws.Cells[rowIndex, colIndex++].Value = item.Employee.Name;
ws.Cells[rowIndex, colIndex++].Value = Convert.ToDateTime(item.Input.DateInput.ToString());
}
Byte[] bin = x.GetAsByteArray();
File.WriteAllBytes(filePath, bin);
}
MessageBox.Show("Xuất excel thành công!");
}
catch (Exception EE)
{
MessageBox.Show("Có lỗi khi lưu file!"+"\n"+EE.ToString());
}
Em không hiểu lỗi này là lỗi này. Mong anh Long và mọi người có thể giúp đỡ em. Em cảm ơn