Click here to Skip to main content
15,798,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I want to export data excel to listview. How can I do? and I use visual studio 2015 , c#

What I have tried:

Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(textBox1.Text);//
Microsoft.Office.Interop.Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Microsoft.Office.Interop.Excel.Range xlRange = xlWorksheet.UsedRange;

int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;

for (int i = 0; i <= rowCount; i++)
{

//for (int j = 1; j <= colCount; j++)
//{


try
{


ListViewItem lvitem = new ListViewItem();
lvitem.Text = xlRange.Cells[i, 1].Value2.ToString();
lvitem.SubItems.Add(xlRange.Cells[i, 2].Value2.ToString());
lvitem.SubItems.Add(xlRange.Cells[i, 3].Value2.ToString());
listView_playlist.Items.Add(lvitem);

}
Posted
Updated 29-Nov-16 4:50am

1 solution

First, you will need to How to read an Excel file using C#[^]
Then, loop to populate the cell data to C# ListView Control[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900