David Ortega
David Ortega

Reputation: 915

Convert Excel XML 2003 Worksheet file into .XLSX file in C#

I'm implementing a solution where users load .XLS,.XLSX and .CSV files into an ASP MVC application. I'm using Gembox Spreadsheet plugin to read files and so far it works well, but the user requires to load an .XML file with a particular schema. I don't know which Excel version is supposed to be equivalent for this file, but I found this on the XML file and it states its a schema for Excel:

<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">

Which hints me that is and old .XLS document schema, same conclusion I have found after a quick google search, but I don't know which protocol this file is or which standard/library it belongs to. Could anyone shed some light on how exactly to read this? If I open this file with Microsoft Excel it can be read but I don'w know how.

EDIT

Following Sunil's answer I have researched a bit more and this is an Microsoft Excel 2003 XML file, so I tried using Microsoft's Open XML SDK to try reading this file, I found this code:

public static void ConvertExcelXmltoXlsx(Stream fileStream, string filePath, string fileName)
{
    string excelFileName = Path.GetFileNameWithoutExtension(fileName) + ".xslx";
    OpenXmlReader reader = OpenXmlReader.Create(fileStream);
    while (reader.Read())
    {
        if (reader.ElementType == typeof(CellValue))
        {
            reader.GetText();
        }
    }
}

However the file was not recognized, and when I tried opening it with Open SDK Productivity Tool it says the file is corrupt.

Error Open XML Sdk Productivity Tool

But I can open this file with Microsoft Excel without any issues

Excel opens file ok

So far all libraries I have found are for generating this types of files, but not reading and outputting them to a different format. Maybe I'm making the wrong research.

Upvotes: 3

Views: 1445

Answers (1)

Sunil
Sunil

Reputation: 3424

I have worked on a similar document. These files are called Excel XML files.

Look for Carlos Ag Excel Xml Writer on Google. Also search for "Excel XML reader" you will get lot of code samples.

Upvotes: 2

Related Questions