5

我有一个 XML-Excel 文件(SpreadsheetML 格式):

<?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>
...

现在我需要使用 C# 将这些文件转换为 XLSX 文件。有没有办法使用 Open Xml 或其他库将其转换为 Excel 2010 XLSX 格式?

4

2 回答 2

0

你得到的是所谓的平面 OPC 格式。是一篇关于将其转换为常规 Open XML 格式的文章。

于 2017-01-15T10:19:49.337 回答
-1

这是一个简单的示例,如何使用 Python 和已安装的 Excel 进行转换。先决条件:必须在计算机上安装 Microsoft Excel!

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)
于 2019-06-25T18:30:08.717 回答