Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Excel XML-Spreadsheet into xlsx

i have got a XML-Excel file (SpreadsheetML format):

<?xml version="1.0" encoding="utf-8"?>
<?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">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
 <Company>My Company</Company>
 </DocumentProperties>
 <Styles>
 <Style ss:ID="Default" ss:Name="Normal">
 <Alignment ss:Vertical="Bottom"/>
 <Borders/>
 <Font/>
 <Interior/>
 <NumberFormat/>
 <Protection/>
 </Style>
 <Style ss:ID="stTxt">
<Font ss:FontName="Arial" ss:Size="8"/>
<Alignment ss:Horizontal="Left"/>
<NumberFormat ss:Format="@"/>
 </Style>
<Style ss:ID="stTopHeadline">
<Font ss:FontName="Arial" ss:Size="8" />
<Alignment ss:Horizontal="Left"/>
<NumberFormat ss:Format="@"/>
 </Style>
...

Now i need to convert those files into XLSX-Files with C#. Is there a way with Open Xml or other libraries to convert it into Excel 2010 XLSX format?

like image 548
Saftpresse99 Avatar asked Jul 04 '26 01:07

Saftpresse99


2 Answers

What you got is called the Flat OPC format. Here is an article about converting it to the regular Open XML format.

like image 63
Marek Dzikiewicz Avatar answered Jul 05 '26 15:07

Marek Dzikiewicz


Here is an easy example how to convert it with Python and an installed Excel. Prerequisite: Microsoft Excel must be installed on the computer!

import os
from win32com.client import Dispatch

def convert_xls_to_xlsx(oldName:str, newName:str):
    oldName = os.path.abspath(oldName)
    newName = os.path.abspath(newName)
    xlApp = Dispatch("Excel.Application")
    wb = xlApp.Workbooks.Open(oldName)
    wb.SaveAs(newName,51)
    wb.Close(True)
like image 39
Mano Meter Avatar answered Jul 05 '26 16:07

Mano Meter