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
Related
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');
?>
I need to add the images from a windows folder to the excel sheet such that each image is placed in front of the row entry containing the name of the file.
Something like this- (the name of the file is same as the id column entry in that row)
What kind of code/language could i use to do this?
I also have this database in Mysql, is it possible to include images in excel using php.
Thanks a lot
Let's suppose you are including your phpExcel library in your project ,
include 'PHPExcel.php';
// you create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Yassine CHABLI");
$objPHPExcel->getProperties()->setLastModifiedBy("Yassine CHABLI");
$objPHPExcel->getProperties()->setTitle("make whatever you want");
$objPHPExcel->getProperties()->setSubject("whatever you want");
$objPHPExcel->getProperties()->setDescription("including images test (example)");
// Add some data
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setTitle('image example');
$Image = imagecreatefromjpeg('yassine.jpg');
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('image');
$objDrawing->setDescription('image');
$objDrawing->setImageResource($Image);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('A1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
For more information , visit the link bellow:
https://packagist.org/packages/phpoffice/phpexcel
notice: That will create an “xlsx” formatted file because it uses
2007 excel classes. if you want “xls” format just try with 2005 class
and do not forget to change the file format to “xls” while using 2005.
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');
<?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.
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