Reading Excel File
c# code Browse excel file from folder and clicking on the button it should get details of specified column to the listbox in windows forms?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Arul Manivannan48 reputationPosted Mar 19, 2013, 1:14 AM EDT
1. Fetch the excel data and populate it into datatable.
2. remove the unwanted columns from the datatable.
3. assign this datatable as datasource to that listbox. For fetching data from excel file. Please see http://www.dotnetfunda.com/codes/code972-read-a-excel-file-with-sheet-wise-into-dataset-using-csharp.aspx
Arul Manivannnan
Donald Green2 reputationPosted May 14, 2013, 11:06 PM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted May 15, 2013, 12:30 AM EDT
Please refer below link it might help you.
http://www.c-sharpcorner.com/uploadfile/mgold/howtooepnandreadanexcelspreadsheetinalistviewin.net11282005034134am/howtooepnandreadanexcelspreadsheetinalistviewin.net.aspx
http://www.dotnetspider.com/resources/5791-Open-Read-File-Win-Forms.aspx
Garry Gibson20 reputationPosted Oct 3, 2014, 1:29 AM EDT
Hi Manjunatha here is another way that you can try:
// Open excel file which was selected from "openDialog" control. var file = ExcelFile.Load(this.openDialog.FileName); // Select required worksheet. var sheet = file.Worksheets.ActiveWorksheet; // Retrieve required cells. var requiredCells = sheet.Cells.GetSubrangeRelative( 0, ExcelColumnCollection.ColumnNameToIndex(this.txtColumnName.Text), 1, sheet.Rows.Count - 1); // Show cells data in "listBox" control. foreach (var cell in requiredCells) if (cell != null && cell.Value != null && !string.IsNullOrEmpty(cell.Value.ToString())) this.listBox.Items.Add(cell.GetFormattedValue()); The code uses a .NET component which works on excel workbooks and as you can see you have a direct approach how to retrieve the required values. Note that you can use the same approach for reading both XLS and XLSX files (older and newer excels) in .NET without applying any changes to code.