Basicly reading an Excel sheet is the reverse from writing it. You could use an OpenFileDialog to locate the Excel sheet, and then call a function like below.
private void ImportExcel(string filename)
{
Microsoft.Office.Interop.Excel.Application xla = new Microsoft.Office.Interop.Excel.Application();
xla.Visible = true;
Microsoft.Office.Interop.Excel.Workbook wb = xla.Workbooks.Open(filename);
Microsoft.Office.Interop.Excel.Worksheet ws = wb.Worksheets[1];
int numberOfColumns = GetNumberOfColumns(ws);
int numberOfRows = GetNumberOfRows(ws);
for (int r = 1; r <= numberOfRows; r++)
{
ListViewItem item = listView_playlist.Items.Add(ws.Cells[r, 1].Value);
for (int c = 1; c <= numberOfColumns; c++)
{
item.SubItems.Add(ws.Cells[r, c].Value.ToString());
}
}
xla.Quit();
xla = null;
}
private int GetNumberOfRows(Microsoft.Office.Interop.Excel.Worksheet ws)
{
int numberOfRows = 1;
while (ws.Cells[1, numberOfRows].Value != null)
{
numberOfRows += 1;
}
numberOfRows -= 1;
return numberOfRows;
}
private int GetNumberOfColumns(Microsoft.Office.Interop.Excel.Worksheet ws)
{
int numberOfColumns = 1;
while (ws.Cells[1, numberOfColumns].Value != null)
{
numberOfColumns += 1;
}
numberOfColumns -= 1;
return numberOfColumns;
}
The code Loads the Excel workbook. I assume the data is on the first worksheet. Next the number of columns and rows are determined. Loop them and add items to your ListView. ListView are not my strongest point (I didn't manage to show the subitems), so you might need to change a little in the code to add the data to the ListView.
By the way when I studied your code I might have discovered a bug. First you write your item to ws.Cells[i, j] and when you loop the subitems you write the first subitem to the same cell (without j is being incremented). If the item and the first subitem contain the same data (that's what I assumed in the example), then there is no problem otherwise you might loose data.