Is there a C# code to read and display Excel sheets?

mauede

Well-known member
Joined
Sep 1, 2021
Messages
103
Location
Northwood - UK
Programming Experience
Beginner
I have been asked to do something to read and display excel sheets.
If I was using MatLab it would be a piece of cake.
Unluckily there is no MatLab license in the hospital where I work.
I found a posted C# code. I downloaded and unlocked it. Unluckily when I compiler I got a lot of errors.

Does anyone know if there is something that works?
Thank you in advance
 
If you know the machine you are running on has Office, you can use Excel Interop. If there is no guarantee that Excel will be present on the machine, then use 3rd party product that can read Excel files. A lot of groups in my company have had a lot of success with Aspose.

If you are unwilling to pay for a 3rd party product, you could use the OpenXML SDK that comes free from Microsoft. You can open modern Excel files (e.g. Files created with Office 2007 and later with the .xlsx or .xlsm extensions). It has a steep learning curve, though and not something I would wish on anyone.

Stop and consider if those Excel sheets can be exported to .CSV files. Reading in .CSV files is infinitely easier.

That's for the reading part. For display if all you need are basic text and numbers, the WPF DataGrid, or the WinForms DataGridView should work.
 
If you know the machine you are running on has Office, you can use Excel Interop. If there is no guarantee that Excel will be present on the machine, then use 3rd party product that can read Excel files. A lot of groups in my company have had a lot of success with Aspose.

If you are unwilling to pay for a 3rd party product, you could use the OpenXML SDK that comes free from Microsoft. You can open modern Excel files (e.g. Files created with Office 2007 and later with the .xlsx or .xlsm extensions). It has a steep learning curve, though and not something I would wish on anyone.

Stop and consider if those Excel sheets can be exported to .CSV files. Reading in .CSV files is infinitely easier.

That's for the reading part. For display if all you need are basic text and numbers, the WPF DataGrid, or the WinForms DataGridView should work.
Thank you. It is not really my choice to deal with Excel. Anyway, on the following website, there seems to be a C# class to convert an Excel file into a CSV file. Then ... there is still the part that reads the CSV file and displays a table on the screen.
One of the people in the RTTQA department stated there exists a high=level language "VBA" ( I am not sure this is the exact name) that makes the whole task of going from Excel sheets to tables displayed on the screen easy ... I never heard of such a high-level programming language.
 
VBA is short for Visual Basic for Applications. It was basically Visual Basic 6, but meant to run within a scripting host, and most of the Office apps were setup to be scripting hosts.
 
Back
Top Bottom