XLSX-如何摆脱默认名称空间前缀x :? [英] XLSX- how to get rid of the default namespace prefix x:?
本文介绍了XLSX-如何摆脱默认名称空间前缀x :?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用OOXML SDK生成XLSX电子表格,并且需要摆脱x:
名称空间前缀.我该如何实现?
I'm generating XLSX spreadsheet using OOXML SDK, and I need to get rid of x:
namespace prefix. How can I achieve this?
using (SpreadsheetDocument doc = SpreadsheetDocument.Open("template.xlsx", true))
{
//Save the shared string table part
if (doc.WorkbookPart.GetPartsOfType().Count() > 0)
{
SharedStringTablePart shareStringPart =
doc.WorkbookPart.GetPartsOfType().First();
shareStringPart.SharedStringTable.Save();
}
//Save the workbook
doc.WorkbookPart.Workbook.Save();
}
在这里,原始XLSX文件来自Excel 2007,并且没有前缀,但是,在保存操作之后会出现前缀.我该如何避免呢?
Here, the original XLSX file is coming from Excel 2007 and doesn't have the prefix, however, after the save operation the prefix appears. How can I avoid that?
推荐答案
这里是divo链接的样式表的修改版本,该样式表仅剥离单个命名空间并逐字复制其余部分:
Here is a modified version of the stylesheet linked by divo that strips only a single namespace and copies the rest verbatim:
<xsl:stylesheet version="1.0" xmlns:x="namespace-to-strip"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" encoding="UTF-8"/>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="x:*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@x:*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这篇关于XLSX-如何摆脱默认名称空间前缀x :?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文