1

我正在尝试以 XML 格式输出 XLS 文件。

这是 Excel 2003 呈现的数据应该是什么样子(可以保存为 xls 文件):

<? 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'>
    <Worksheet ss:Name='Connections'>
        <Table>
            <Row>
                <Cell><ss:Data ss:Type='String' xmlns="http://www.w3.org/TR/REC-html40"><B>Test</B></Data></Cell>
                <Cell><ss:Data ss:Type='String' xmlns="http://www.w3.org/TR/REC-html40"><B>Test 2</B></Data></Cell>
            </Row>
            <Row>
                <Cell><ss:Data ss:Type='String'>Data</Data></Cell>
                <Cell><ss:Data ss:Type='String'>More data</Data></Cell>
            </Row>
        </Table>
    </Worksheet>
</Workbook>

我目前得到的是:

<?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:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40">
    <Worksheet ss:Name="Test">
        <Table>
            <Row>
                <Cell><ss:Data xmlns="http://www.w3.org/TR/REC-html40" ss:Type="string"><B>Test</B></ss:Data></Cell>
                <Cell><ss:Data xmlns="http://www.w3.org/TR/REC-html40" ss:Type="string"><B>Test 2</B></ss:Data></Cell>
            </Row>
            <Row>
                <Cell><ss:data ss:type="string">Data</ss:Data></Cell>
                <Cell><ss:data ss:type="string">More data</ss:Data></Cell>
            </Row>
        </Table>
    </Worksheet>
</Workbook>

哪个 Excel 无法解析。它在其日志文件中抛出以下四个错误:

XML ERROR in Table
REASON: Bad Value
FILE:   test.xls
GROUP:  Cell
TAG:    Data
ATTRIB: Type
VALUE:  string

我认为主要问题是<ss:Data>我创建的标签DomDocument::CreateElement('ss:Data')应该用 关闭</Data>,而 DomDocument 正在输出</ss:Data>。我不能使用CreateElementNS(),因为没有命名空间(我认为 - 我对 XML 的基础知识并不十分熟悉)并且 usingCreateElementNS('','ss:Data')会导致脚本在安装 XDebug 且 error_reporting 设置为E_ALL & E_STRICT.

4

1 回答 1

1
ss:Type='String'

不是

ss:Type='string'

类型区分大小写

于 2010-10-13T15:18:13.473 回答