doufen3563 2010-10-13 14:44
浏览 68
已采纳

PHP使用DOM输出XLS

I'm trying to output an XLS file in the XML format.

This is what the data should look like for Excel 2003 to render (can be saved as an xls file):

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

What I'm currently getting is this:

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

Which Excel can't parse. It throws four of these errors in its log file:

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

I think that the main problem is that the <ss:Data> tags which I'm creating with DomDocument::CreateElement('ss:Data') should be closed with </Data>, whereas DomDocument is outputting </ss:Data>. I can't use CreateElementNS(), because there isn't a namespace (I think — I'm not really familiar with XML past the basics) and using CreateElementNS('','ss:Data') causes the script to die with absolutely no errors with XDebug installed and error_reporting set to E_ALL & E_STRICT.

  • 写回答

1条回答 默认 最新

  • duanlipeng4136 2010-10-13 15:18
    关注
    ss:Type='String'
    

    not

    ss:Type='string'
    

    the type is case-sensitive

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch