SoFunction
Updated on 2025-03-07

C# method to read Excel and convert it into XML

XmlDocument excelData = new XmlDocument();
DataSet excelTableDataSet = new DataSet();
StreamReader excelContent = new StreamReader(excelFilePath, );
string stringConnectToExcelFile = ("provider=.12.0;Data Source=" + excelFilePath + ";Extended Properties="Excel 12.0;"");
oleConnectionToExcelFile = new (stringConnectToExcelFile);
oleDataAdapterForGetExcelTable = new (("select * from [Sheet 1$]"), oleConnectionToExcelFile);
try
{
    (excelTableDataSet);
}
catch
{
    return null;
}
string excelOutputXml = ();
(excelOutputXml);
(excelOutputXml);
(excelOutputXml);
return excelData;