1

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 Answer 1

1
ss:Type='String'

not

ss:Type='string'

the type is case-sensitive

Sign up to request clarification or add additional context in comments.

1 Comment

Complex question, simple answer. Great!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.