Strange error creating Excel files with Spreadsheet_Excel_Writer

Here is the code. Not so much.

<?php
include("Spreadsheet/Excel/Writer.php");

$xls = new Spreadsheet_Excel_Writer();

$sheet = $xls->addWorksheet('At a Glance');

$colNames = array('Foo', 'Bar');
$sheet->writeRow(0, 0, $colNames, $colHeadingFormat);

for($i=1; $i<=10; $i++)
{
    $row = array( "foo $i", "bar $i");

    $sheet->writeRow($rowNumber++, 0, $row);
}

header ("Expires: " . gmdate("D,d M Y H:i:s") . " GMT");
header ("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
$xls->send("test.xls");
$xls->close();
?>

The problem is that I get the following error when I actually open the file using Excel:

File error:  data may have been lost.

Even a stranger is the fact that, despite the error, the file seems beautiful. Any data I ever write is.

Any ideas on how to get rid of this error?


Edit

I modified the sample code to better illustrate the problem. I do not think that the first sample was a legitimate test.

+3
source share
4 answers

The code in the question has an error that causes the error.

This line writes a bunch of column names to row 0

$sheet->writeRow(0, 0, $colNames, $colHeadingFormat);

Then we have a loop that should write out rows of values.

for($i=1; $i<=10; $i++)
{
    $row = array( "foo $i", "bar $i");

    $sheet->writeRow($rowNumber++, 0, $row);
}

, $rowNumber , 0 .

, , Excel Writer.

, Excel, , , .

, Google Groups. . Micah, .


<?php
include("Spreadsheet/Excel/Writer.php");

$xls = new Spreadsheet_Excel_Writer();

$rowNumber = 0;
$sheet = $xls->addWorksheet('At a Glance');

$colNames = array('Foo', 'Bar');
$sheet->writeRow($rowNumber, 0, $colNames, $colHeadingFormat);

for($i=1; $i<=10; $i++)
{
    $rowNumber++;
    $row = array( "foo $i", "bar $i");

    $sheet->writeRow($rowNumber, 0, $row);
}

header ("Expires: " . gmdate("D,d M Y H:i:s") . " GMT");
header ("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
$xls->send("test.xls");
$xls->close();
?>
+6

, , $rowNumber 0.

, Excel 2 A1 B1, (0, 0 0, 1).

Office Service Pack 3. , SP3 , Excel " ", .

, .: -)

. Perl Spreadsheet:: WriteExcel ( PHP), .

+4

, , , - Foo, .

3,584 ; Excel 2002

+1

0 (A0) PHPExcel. Excel 1- (A1), , " ".

$this->m_excel->getActiveSheet()->SetCellValue($chr[$col].$row, $data));

$row 0

0

Source: https://habr.com/ru/post/1698816/


All Articles