Php excel import is not working on new server - php

I am using php excel reader to read excel file but while importing
the file on new server it is showing this page is not working.I have also given the 0777 permission to my folder but then also it is not importing
the excel file data.But on my old server this code is working fine.Please find the below code and let me know is there any code mistake or server setting is required to read phpexcel file.
<?php
$file_path = 'clientupload/'.$upload_data["file_name"];
// ----------------------------------------------------
$this->load->library('PHPExcel');
//Here i used microsoft excel 2007
$objReader= PHPExcel_IOFactory::createReader('Excel2007');
//Set to read only
$objReader->setReadDataOnly(true);
//Load excel file
$objexcel=$objReader->load($file_path); // error in this line
// echo "hello";die;
$objWorksheet = $objexcel->getActiveSheet(0);
$highestRow = $objWorksheet->getHighestRow();
?>
It is showing below error:
This page isn’t working
216:xx:xx is currently unable to handle this request.
HTTP ERROR 500

Related

PhpSpreadsheet cannot read specific xls file

The following error
Fatal error: Uncaught PhpOffice\PhpSpreadsheet\Reader\Exception: Parameter pos=-12 is invalid
is given when trying to parse a specific xls file.
Code
$inputFileName = "excel.xls";
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xls');
$spreadsheet = $reader->load($inputFileName);
The file in question: https://filebin.net/sle19tm0kdgduyne/excel.xls?t=u0itbeue
I have tried using all available readers such as Xlsx, Csv etc and even using the old deprecated PHPExcel library. Nothing can parse this specific file, even though it opens fine with excel on windows.
My end goal is converting this xls file to an array, so i can paste the data into a database.
I think you don't need to use createReader().
Here the example of my worked code.
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$spreadsheet = $reader->load('path/to/file.xls');
Hope this can help you.

Copy charts from (.xls or .xlsx) using PHP

I am working on a template excel file for some projects and my goal is to populate it with PHP. I create an excel document with two sheets, one is a table with all of the information that I am going to plot, and the second sheet is just a graph that is based on the table from the previous sheet.
Whenever I use (https://github.com/PHPOffice/PhpSpreadsheet) PHPSpreadsheet (since PHPExcel is deprecated) I am able to read/write/copy/etc the first sheet, but whenever I try to save the sheet without touching the graph sheet at all, nothing happens. I save the file successfully but when I try to open it I get an error stating that Excel found unreadable content in the file and to repair it. I repair it and the second sheet with the graph is empty.
https://github.com/PHPOffice/PhpSpreadsheet/issues/382
This is the closest thing I found to my issue, and I did add the setIncludeChart functions, but nothing seems to work.
I also feel that I have exhausted online searches and am now hoping that there is an alternative to PHPSpreadsheet that will allow me to use a chart in a template (supplied) excel file.
$xls = 'KPI_ReadinessTemplate.xls';
$xlsxTarget = 'NEWX_KPI_ReadinessTemplate.xlsx';
$xlsTarget = 'NEW_KPI_ReadinessTemplate.xls';
$inputFileType = 'Xlsx';
$inputFileName = $xlsx;
$reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
$reader->setIncludeCharts(true);
$spreadsheet = $reader->load($inputFileName);
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->getCell('A1')->setValue('Help me');
$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xlsx');
$writer->setIncludeCharts(true);
$fileData = $writer->save($xlsxTarget);
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xls();
$reader->setIncludeCharts(TRUE);
$workbook = $reader->load($xls);
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xls($workbook);
$writer->setIncludeCharts(TRUE);
$writer->save($xlsTarget);
I am expecting the chart to be copied, in the code from above there is no modification of the file, it should be an exact one-to-one copy of the supplied file but it isn't working at all as it seems the graph gets corrupted and I have to repair the excel the next time I open it.
EDIT: I also installed the archived PHPExcel and tried it using Graph disapear read and write excel file using PHPExcel and I still had the same issue.

issue while reading excel file with large number of cell in codeigniter

I am trying to read excel file in my CodeIgniter application. The function getActiveSheet()->toArray(null,true,true,true); is working fine for an excel file with 14442 x 17 cells, however this function does not works for an excel file with 17590 x 17 cells. In this second case, browser ends-up with a blank page and I am not getting any error. So please tell what can be the issue?
Code:
$objPHPExcel = PHPExcel_IOFactory::load($file_path);
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
Probably out of memory. It is a common issue with large excel files.
If you only need to read the data you can use something like
$objReader = PHPExcel_IOFactory::createReaderForFile($file);
$objReader->setReadDataOnly(true);

Warning when the user Opens the written xls file using PHP Excel

The file you're trying to open [fileName] is in different format than
specified by the file extension
I get that message whenever I open the xls files I've written using PHPExcel .. Is there anyway to get rid of that warning
,, the used code
<?php
require_once ('C:\wamp\www\phpexcel sample\Classes\PHPExcel\IOFactory.php');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator("7asobate")->setDescription("PHPExcel tryout");
$objPHPExcel->setActiveSheetIndex(0)->setTitle("7asobate worksheet")->setCellValue('A1' , 'someValue1')
->setCellValue('A2' , 'someValue2');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel , 'Excel2007');
$objWriter->save('F:\myFile.xls');
?>

Excel 97-2003 file incompatible after PHPExcel reads and writes

I have an excel file that has been created and saved as an Excel 97-2003 file. I am using the following code to read and then write using PHPExcel.
$objReader = new \PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load(storage_path() . "/exports/file.xls");
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'Test Message');
$objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter-> save(storage_path() . "/exports/file.xls");
I'm using SamApp ExcelSMS Android app that will then read the file. The only problem is that the file is now incompatible when overwritten with new content. Also, the file size decreases from 18KB to 5KB.
Any help on this is greatly appreciated.

Categories