Reading Excel files
We can read and write to Microsoft Excel files using the Open XML SDK
. It provides the tools for us to work with not only Excel files but also Word and PowerPoint files. To use the Open XML SDK
, we need to add the DocumentFormat.OpenXml NuGet
package to our project.
Modern Excel files with the XLSX file extension are made up of a compressed collection of XML files. To view the individual files, change the file extension from XLSX to ZIP and view the files using a .zip
viewer. You can also extract the files.
When using the Open XML SDK
, the Excel document is represented with the SpreadsheetDocument
class. This is the hierarchy of the elements in the class:
workbook
– the root element of the documentsheets
– the container for the sheetssheet
– the pointer to the sheet definition fileworksheet
– the sheet definition that contains the sheet datasheetData
– the datarow
–...