PHP使用存储在服务器上的XML文件创建excel以供下载

Gday, basically what I'm doing is creating a XML file with Db info. I'm using PHP to create the XML file and store it on the server. I have to store the XML because its based on a specific period in time. I can't use any outside libraries or classes, I shouldn't need one anyway, most likely code error. So here's the generated XML header and basic structure, it has 6 sheets altogether.

<?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"
 xmlns:html="http://www.w3.org/TR/REC-html40">
<Worksheet ss:Name="Report Page 1">
<Table>
<Row><Cell><Data ss:Type="String">col 1</Data></Cell><Cell><Data ss:Type="String">Col 2</Data></Cell></Row>
</Table>
</Worksheet>

col 1Col 2

Here's the PHP called from a link

<?php
$dir = "reports/xls/";
$filename = 'Summary.xml';
header("Content-type: application/vnd.ms-excel");
header("Content-Length: " . filesize($dir.$filename));
header("Content-Disposition: attachment; filename=$filename");
header("Expires: 0");
header("Cache-Control: private");
header("Pragma: cache");
    $Dfile = file_get_contents($dir.$filename);
    print $Dfile;
?>

All I get is a blank excel file with sheet1 and no data. If I use the same technic but generate the file on the fly the report looks great, all data present. Slightly different PHP headers of course.

header("Content-type: application/vnd.ms-excel");
header("Content-Length: " . strlen($excelxml));
header("Content-Disposition: attachment; filename={$excelxml}.xml");
header("Expires: 0");
header("Cache-Control: private");
header("Pragma: cache");
print $excelxml;

$excelxml is just a string holding the generated data. Any help would be greatly appreciated, I don't think CSV is an option,I don't think it can create multiple worksheets. I commented out the Content-type/Disposition headers to look at the source code and its the same except the code from the XML file on the server has an extra space at the top, above the .

 $dir = "reports/xls/";
 $filename = 'Summary.xml';
 if(!file_exists($dir.$filename)) die("Upload the file");

Or watch Response header via FireBug or another app for loking:

"Content-Length: " . filesize($dir.$filename))

If will retrun 0 - file doesn't exist

I had two PHP blocks in the first file causing a white-space or line-break issue.

try to close <Workbook> tag at the end of xml script