PHPExcel to html gives empty cells - php

Im Using the PHPExcel library to convert a uploaded .xlsx file to a html page.
The code works but the html page also has alot of empty cells in it. what can i do so PHPExcel wil not create these?
the convert
$inputFileName = $upload_dir;
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save($basename.".html");
the result

Related

phpexcel - using it with excel template and chart goes missing php

Can anyone let me know if there are any other library choices available for me where I can do what I wanted.. that is open the excel template file (.xlsx or even .xlsm) in php and populate the cells and keep all the charts, pivot table, even macros, forms, buttons, etc. intact. All the php will do is just populate the cells with new data from database. In other words, using the same terminology that you have used.. please point me to the library for which I can use to "edit" workbook files.
When i try the below code.. the chart itself goes missing from the resulting file. After trying various ways.. still failed.
Thank you so much again.
<?php
date_default_timezone_set('Europe/London');
require_once 'excel/PHPExcel/IOFactory.php';
require_once 'excel/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load('WorkingFile_Daily.xlsx');
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('B11', 4)
->setCellValue('B12', 5)
->setCellValue('B13', 6)
->setCellValue('B14', 7);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('WorkingFile_Daily New.xlsx');
?>

PHPExcel - comment background become black in excel

I'm using PHPExcel to load and save *.xslx file in PHP.
I load a normal excel file and save it into another file using PHPExcel then all the comments become black comments.
Do you have any idea what it could be?
Thanks
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load($loadfilename);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');//Excel2007
$objWriter->save($savefilename);
Here is the result of excel comment

Load a Excel file with images using PHPExcel

I'm currently working on a project that needs to display excel files (xls, xlsx, csv) on the browser. So far, I have tried and used the PHPExcel library and was able to display the excel file (code below)
$opendoc = $userDoc;
$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load($opendoc);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->writeAllSheets();
$objw->save('php://output');
The problem I'm encountering is that this code does not support the displaying images (charts , graph , etc) inside an excel file. Any ideas? Thanks in advance!
Errr..... yes it does. Have you read the documentation or looked at the examples? Images are supported directly, and (unless you tell PHPExcel to load data only) should always be loaded.
For charts and graphs, you specifically have to tell PHPExcel to load them when reading a file, and tell PHPExcel to save them when Writing. (Example)
$opendoc = $userDoc;
$objReader = new PHPExcel_Reader_Excel2007();
$objReader->setIncludeCharts(TRUE);
$objPHPExcel = $objReader->load($opendoc);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objw = $objWriter;
$objw->setIncludeCharts(TRUE);
$objw->writeAllSheets();
$objw->save('php://output');

PHPexcel How to show multiple sheets data in browser

<?php
require_once("PHPExcel/Classes/PHPExcel.php");
require_once("PHPExcel/Classes/PHPExcel/Writer/Excel2007.php");
require_once("PHPExcel/Classes/PHPExcel/IOFactory.php");
$objPHPExcel = new PHPExcel();
$inputFileName = 'R1.xlsx';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objPHPExcel->setActiveSheetIndex(0);
$objWriter->save('php://output');
This is my code its good to get excel Sheet1 output from R1.xlsx file to browser. But R1.xlsx contain more than one sheets how to show them by link or vertically to show sheet2 and sheet3 data?
Thanks
PS.
I tried
$objPHPExcel->setActiveSheetIndex(X); by changing X value
By default, the HTML Writer will only generate output for a single worksheet
You can specify which sheet to write by calling
$objWriter->setSheetIndex(2);
specifying the individual sheet that you want to output
But you can also tell it to generate an output for all sheets instead using
$objWriter->writeAllSheets();
before the save
You can use a for loop, in each loop, output the content of each table.

PHPExcel getHighestDataRow() is not working with .xlsx file

I am trying to get the last row that contains data in an excel workbook.
I've used the function getHighestDataRow() like other advices I got from the internet. But it only work for .xls file.
When I save the file to .xlsx format, the function return the wrong value
Below is my code:
$inputFileType = PHPExcel_IOFactory::identify($file);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objReader->setLoadSheetsOnly(0);
$objPHPExcel = $objReader->load($file);
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestDataRow();
$highestColumn = $sheet->getHighestDataColumn();
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
I've been looking for this problem for hours but still can't find the answer.
The getHighestDataRow() method doesn't care whether the PHPExcel object with its worksheets was loaded from a file, or created using new.... if loaded from a file, it doesn't know whether an xls file or an xlsx file was used to create the PHPExcel object... so you're wrong about this. The call works on the cell collection, not on the file or file type in any way.
Nor is the code that you've posted using $sheet->getHighestDataRow() it's using $sheet->getHighestRow()

Categories