2011-05-21 25 views
1

Gday,基本上我正在做的是创建一个带有DB信息的XML文件。我使用PHP来创建XML文件并将其存储在服务器上。 我必须存储XML,因为它基于特定的时间段。 我无法使用任何外部库或类,反正我也不需要它,很可能是代码错误。所以这里是生成的XML标题和基本结构,它共有6页。PHP使用存储在服务器上的XML文件来创建下载的Excel文件

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

山坳1Col 2

下面是一个链接

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

称为PHP我得到的是一个空白的Excel文件Sheet1中,并没有数据。如果我使用相同的技术,但是实时生成文件,报告看起来很棒,所有数据都会显示。当然,略有不同的PHP标题。

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只是一个持有生成数据的字符串。 任何帮助将不胜感激,我不认为CSV是一种选择,我不认为它可以创建多个工作表。 我注释了Content-type/Disposition标题,以查看源代码及其相同的内容,除了服务器上的XML文件中的代码在顶部的上方有一个额外的空间。

回答

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

或通过萤火虫或其他应用中观看响应头为寻找热塑成型:

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

如果将retrun 0 - 文件不存在

+0

这是一件好事添加错误检查,但是这将留待以后。我知道文件存在,我只是不知道为什么Excel电子表格试图下载时是空白的。 – Anthony 2011-05-22 18:17:18

1

我有两个PHP模块中的第一个文件造成一个空白或换行问题。

0

尝试XML脚本的年底前关闭<Workbook>标签

相关问题