Excel Data to TreeView C#

2019-07-21 07:47发布

问题:

I am looking to create a windows form that contains a tree view of data that I have in excel. I have the windows form I am just trying to figure out how to export the excel data into that data tree. Any links?

回答1:

If you import Microsoft.Office.Interop.Excel assembly you can access Excel files and use every property and method easily.
Example:

using Excel = Microsoft.Office.Interop.Excel;

public static object GetCellValue(
       string filename, string sheet, int row, int column)
{
    Excel.Application excel = new Excel.Application();
    Excel.Workbook wb = excel.Open(filename);
    Excel.Worksheet sh = wb.Sheets[sheet];
    object ret = sh.Cells[row, column].Value2;
    wb.Close();
    excel.Quit();
}