PHPExcel cannot open saved file

I am trying to open an existing excel file, modify some cells and save it. I am using Excel2007 to read and write.

The input file has a size of about 1 MB and has several formulas, protected data and hidden rows and columns and sheets, which I do not change.

I can load the data and read and write to it some values ​​that I check with various var_dumps in the code.

The problem is its conservation. It generates some fatal errors in timeouts, and also, if it writes a file, the file size is inflated to 9.2 MB, and it is normal if I can open it.

a piece of code - nothing unusual.

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($inputFile);

$objPHPExcel->setActiveSheetIndex(2);
$activeSheet = $objPHPExcel->getActiveSheet();

$currCell = $activeSheet->getCell("O3");
$cellValidation = $currCell->getDataValidation("O3");
$values = array();
if ($cellValidation->getShowDropDown() == true)
{
    $values = $cellValidation->getFormula1();
    $valArray = explode(",", $values);
    $currCell->setValue($valArray[0]);
}

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter -> setPreCalculateFormulas(false);
$objWriter->save($outputFile);

I use MS Excel 2010 to open the resulting file, but it just takes forever and did not open it even once.

, , , .

.

+4
2

php://outputDocs:

$objWriter->save('php://output');

AS-IS .

headersDocs, , , ( ):

// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');

// It will be called file.xls
header('Content-Disposition: attachment; filename="file.xls"');

// Write file to the browser
$objWriter->save('php://output');

, . Excel : mime Excel.

, -

// Save Excel 2007 file
#echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
// We'll be outputting an excel file
header('Content-type: application/vnd.ms-excel');
// It will be called file.xls
header('Content-Disposition: attachment; filename="file.xlsx"');
$objWriter->save('php://output');

, :

ob_end_clean();

.

!

0

"", , MS Excel , , PHPExcel OfficeOpenXML.

, MS Excel . , . , , PHPExcel , . , - , .

, MS Excel , ( /), , , . , PHPExcel , , , .


, , MS Excel 2010, , debug

0

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


All Articles