简体   繁体   English

公式“ =“ Sheet 1”!A1”不适用于PHPExcel中的编写器Excel2007

[英]Formula “=''Sheet 1''!A1” does not work with writer Excel2007 in PHPExcel

I have a problem with writer excel2007 of PHPExcel. 我对PHPExcel的作家excel2007有问题。 The formular get value from another sheet name does not work. 公式从另一个工作表名称获取值不起作用。 The following is my code. 以下是我的代码。

$xfile = new PHPExcel();
$xfile->setActiveSheetIndex(0);
$sheet1 = $xfile->getActiveSheet();
$sheet1->setTitle('Sheet 1');
$sheet1->setCellValue('A1', 100);

$xfile->createSheet();
$sheet2 = $xfile->setActiveSheetIndex(1);
$sheet2->setCellValue('A1', "='Sheet 1'!A1");
$sheet2->setTitle('Sheet 2');

$objWriter = PHPExcel_IOFactory::createWriter($xfile, 'Excel2007');
$objWriter->save('test.xlsx');

$objWriter = PHPExcel_IOFactory::createWriter($xfile, 'Excel5');
$objWriter->save('test.xls');

In above script, I generate 2 files: test.xlsx and test.xls 在上面的脚本中,我生成了2个文件:test.xlsx和test.xls

In file test.xls, value of A1 of Sheet 2 is 100 在文件test.xls中,工作表2的A1的值为100

But in file test.xlsx, value of A1 of Sheet 2 is 0 但是在文件test.xlsx中,工作表2的A1的值为0

=> Right value is 100 =>正确值为100

Is there any way to use this formular in Excel2007? 有什么方法可以在Excel2007中使用此公式?

Note: I open 2 files by Libre Office Calc. 注意:我通过Libre Office Calc打开2个文件。 I am not sure that how is it if I open by MS Excel. 我不确定如果通过MS Excel打开怎么办。

在此处输入图片说明

Your problem is that you are sending the http response headers after you are sending the output to the browser. 您的问题是, 将输出发送到浏览器之后 ,您正在发送http响应标头。 This will result in all manner of problems, such as "headers already set". 这将导致各种问题,例如“标题已设置”。

The same should apply equally whatever Writer you are using.... send the headers before you save the spreadsheet to php://output 无论您使用哪种Writer,都应同样适用。... 将电子表格保存到php://output 之前发送标头

If you send the headers first, then this code works exactly as expected 如果您先发送标头,则此代码将完全按预期工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM