T
T
Taaffita2016-07-27 15:50:05
PHP
Taaffita, 2016-07-27 15:50:05

Problem saving .xlsx file via PHPExcel?

the bottom line is that in the script I load the file, change 3 values ​​​​and save it to a new file.
BUT, firstly, it saves for a terribly long time, and secondly, a file that weighed 22KB becomes 2509KB.
here is a sample code:
$inputFileName = __DIR__.'\\files\\sample.xlsx';
try {
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
}catch(Exception $Exception){
echo $Exception;
}
echo "File upload";
// Set the active sheet index
$objPHPExcel->setActiveSheetIndex(0);
// Get the active sheet
$sheet = $objPHPExcel->getActiveSheet();
$sheet->setTitle("New");
$sheet -> setCellValue('A6','2Nikita');
$sheet -> setCellValue('B6','2Hello');
$sheet -> setCellValue('C6', 'World2');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
try{
$objWriter->save(__DIR__.'\\files\\Test4.xlsx' );
}catch(Exception $Exception){
echo $Exception;
}
echo "file saved";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel O, 2016-07-27
@gans5131

  1. Change xlsx extension to zip
  2. Unzip.
  3. Find the xml file with the data and replace the necessary values ​​(there one file is responsible for storing data, and the other for arranging this data in cells)
  4. Zip the file and rename the file extension back to xlsx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question