PHP PEAR Spreadsheet_Excel_Writer发送一个空文件

时间:2022-02-08 20:08:38

Has anyone used Pear: Spreadsheet_Excel_Writer?

有没有人用过Pear:Spreadsheet_Excel_Writer?

The Formatting Tutorial lists a script similar to what I'm working with: (trimmed down)

格式化教程列出了一个类似于我正在使用的脚本:(修剪)

<?php
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer();

$worksheet =& $workbook->addWorksheet();
$worksheet->write(0, 0, "Quarterly Profits for Dotcom.Com");

$workbook->send('test.xls');
$workbook->close();
?>

What I think I understand so far about it...
$workbook->send('test.xls'); sets the headers up for Excel file transfer. Now, no errors seem to come up, but the file downloaded is entirely empty (even in a hex editor).

到目前为止我认为我对它的了解... $ workbook-> send('test.xls');设置标题以进行Excel文件传输。现在,似乎没有出现任何错误,但下载的文件完全是空的(即使在十六进制编辑器中)。

So...
Where (in what class/method) is the $workbook binary supposed to be written? Or, am I misunderstanding it all?

那么......应该写的$ workbook二进制文件在哪里(在什么类/方法中)?或者,我是否误解了这一切?

Note: I honestly don't know what version of Spreadsheet_Excel_Writer is being used; the sources don't include such useful information.
I can tell you the copyright is 2002-2003; so, anywhere from version 0.1 to 0.6.

注意:老实说,我不知道正在使用什么版本的Spreadsheet_Excel_Writer;来源不包括这些有用的信息。我可以告诉你版权是2002-2003;所以,从版本0.1到0.6。

[Edit] Sorry, thought I'd mentioned this somewhere.. This is someone else's script that I've been assigned to fix.

[编辑]对不起,以为我在某个地方提到过这个...这是别人的脚本我已经被分配来修复。

5 个解决方案

#1


3  

Here is some sample code:

以下是一些示例代码:

<?php
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer('test.xls');
$worksheet =& $workbook->addWorksheet('My first worksheet');
if (PEAR::isError($worksheet)) {
    die($worksheet->getMessage());
}
$workbook->close();
?>

I think for starters, give your worksheet a name and try to write a file directly (without send()).

我认为首先,给你的工作表一个名字,并尝试直接写一个文件(没有send())。

Also, make sure with all methods you call, test the response with PEAR::isError().

另外,请确保调用所有方法,使用PEAR :: isError()测试响应。

#2


1  

It is not very clear, but I think that the send command only creates the headers with the correct content type and file name. You have to send the data afterwards, with something lik

它不是很清楚,但我认为send命令只创建具有正确内容类型和文件名的标头。您必须在事后发送数据

$tmpDocument = '/path/to/tmp/file.xls';
$workbook = new Spreadsheet_Excel_Writer($tmpDocument);   

/* Code to generate the XLS file */

/ *生成XLS文件的代码* /

$workbook->close();
$workbook->send('Report.xls');
readfile($tmpDocument);

#3


0  

send() sends cache-control headers and content type headers, but not content. The content is sendt, as I understand from the code, when $workbook->close() is called.

send()发送缓存控制标头和内容类型标头,但不发送内容。根据我的代码,当调用$ workbook-> close()时,内容是sendt。

#4


0  

Use this to download the worksheet in your Browser

使用此选项可在浏览器中下载工作表

$workbook = new Spreadsheet_Excel_Writer(); // <-- leave parantheses empty
$workbook->send($DownloadFileName);
// Your fancy spreadsheet generating code
$workbook->close();

and this to write it to a file.

并将其写入文件。

$workbook = new Spreadsheet_Excel_Writer($SaveFileName);
// Your fancy spreadsheet generating code
$workbook->close();

#5


0  

You need to name your worksheet at $worksheet =& $workbook->addWorksheet();.
Check the code below:

您需要在$ worksheet =&$ workbook-> addWorksheet();中命名工作表。检查以下代码:

require_once 'Spreadsheet/Excel/Writer.php';

//Create a workbook
$workbook = new Spreadsheet_Excel_Writer(); //() must be empty or your downloaded file will be corrupt.

// Create a worksheet 
$worksheet =& $workbook->addWorksheet('test'); <-- You forgot to name your worksheet in your code, yours is "addWorksheet()"

// The actual data 
$worksheet->write(0, 0, 'Name'); 
$worksheet->write(0, 1, 'Age'); 
$worksheet->write(1, 0, 'John Smith'); 
$worksheet->write(1, 1, 30);
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31); $worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);

// send HTTP headers 
$workbook->send('prueba.xls');

// Let's send the file
$workbook->close();

#1


3  

Here is some sample code:

以下是一些示例代码:

<?php
require_once 'Spreadsheet/Excel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer('test.xls');
$worksheet =& $workbook->addWorksheet('My first worksheet');
if (PEAR::isError($worksheet)) {
    die($worksheet->getMessage());
}
$workbook->close();
?>

I think for starters, give your worksheet a name and try to write a file directly (without send()).

我认为首先,给你的工作表一个名字,并尝试直接写一个文件(没有send())。

Also, make sure with all methods you call, test the response with PEAR::isError().

另外,请确保调用所有方法,使用PEAR :: isError()测试响应。

#2


1  

It is not very clear, but I think that the send command only creates the headers with the correct content type and file name. You have to send the data afterwards, with something lik

它不是很清楚,但我认为send命令只创建具有正确内容类型和文件名的标头。您必须在事后发送数据

$tmpDocument = '/path/to/tmp/file.xls';
$workbook = new Spreadsheet_Excel_Writer($tmpDocument);   

/* Code to generate the XLS file */

/ *生成XLS文件的代码* /

$workbook->close();
$workbook->send('Report.xls');
readfile($tmpDocument);

#3


0  

send() sends cache-control headers and content type headers, but not content. The content is sendt, as I understand from the code, when $workbook->close() is called.

send()发送缓存控制标头和内容类型标头,但不发送内容。根据我的代码,当调用$ workbook-> close()时,内容是sendt。

#4


0  

Use this to download the worksheet in your Browser

使用此选项可在浏览器中下载工作表

$workbook = new Spreadsheet_Excel_Writer(); // <-- leave parantheses empty
$workbook->send($DownloadFileName);
// Your fancy spreadsheet generating code
$workbook->close();

and this to write it to a file.

并将其写入文件。

$workbook = new Spreadsheet_Excel_Writer($SaveFileName);
// Your fancy spreadsheet generating code
$workbook->close();

#5


0  

You need to name your worksheet at $worksheet =& $workbook->addWorksheet();.
Check the code below:

您需要在$ worksheet =&$ workbook-> addWorksheet();中命名工作表。检查以下代码:

require_once 'Spreadsheet/Excel/Writer.php';

//Create a workbook
$workbook = new Spreadsheet_Excel_Writer(); //() must be empty or your downloaded file will be corrupt.

// Create a worksheet 
$worksheet =& $workbook->addWorksheet('test'); <-- You forgot to name your worksheet in your code, yours is "addWorksheet()"

// The actual data 
$worksheet->write(0, 0, 'Name'); 
$worksheet->write(0, 1, 'Age'); 
$worksheet->write(1, 0, 'John Smith'); 
$worksheet->write(1, 1, 30);
$worksheet->write(2, 0, 'Johann Schmidt');
$worksheet->write(2, 1, 31); $worksheet->write(3, 0, 'Juan Herrera');
$worksheet->write(3, 1, 32);

// send HTTP headers 
$workbook->send('prueba.xls');

// Let's send the file
$workbook->close();