@don bradman , you could try the following code to export excel data to a listview using epplus properly.
Code:
private void Form1_Load(object sender, EventArgs e)
{
string filename = "D:\\test1.xlsx";
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
using (ExcelPackage package = new ExcelPackage(new System.IO.FileInfo(filename), false))
{
ExcelWorksheet mainSheet = package.Workbook.Worksheets.First();
listView1.Columns.Add("Party");
listView1.Columns.Add("Bill No.");
listView1.Columns.Add("Bill Date");
listView1.Columns.Add("Amount");
listView1.Columns.Add("Due Date");
listView1.View = View.Details;
for (int row = 2; row <= mainSheet.Dimension.End.Row; row++)
{
ListViewItem itm = new ListViewItem();
for (int col = 2; col < 6; col++)
{
if(DateTime.Parse(mainSheet.Cells[row, 5].Text) >= DateTime.Today && DateTime.Parse(mainSheet.Cells[row, 5].Text) <= DateTime.Today.AddDays(10))
{
itm.Text =mainSheet.Cells[row, 1].Text;
itm.SubItems.Add(mainSheet.Cells[row, col].Text);
}
}
if(itm.SubItems.Count>1)
{
listView1.Items.Add(itm);
}
}
}
}
Result:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.