I wanted to append data in the pre formated excel sheet that is basically header footer in the excel sheet I wanted to append the contents. And will create many files dynamically.
3 Answers
A simple workaround is:
- create a html table with the formatting you need
- add values in php to the table (or generate table with php)
- save file as .xls (filled with content from html table)
- open file (will show formatted table in Excel)
Reason:
- handling XLS files is very complex and many libraries have big limits (only available on windows servers....)
- html table saved as .xls can be opened in Excel.
4 Comments
Mark Baker
html table saved as .xls is basically a valid minimum structure of a XLS file B****cks.... MS Excel has an HTML importer which it can use, which means that it can read this though some versions of MS Excel will complain that you're lying to it; that's not the same as html being a minimum structure of an xls fileYucieyurimoyq
It works well, also for Doc files, clients are using for years without any complains.
Mark Baker
You will start to get complaints as your clients move to more recent versions of MS Excel; because you're creating a file whose format doesn't match that expected by an xls extension..... but to describe
html table saved as .xls is basically a valid minimum structure of a XLS file is totally false, and totally disingenuousYucieyurimoyq
Thanks for the update, i changed the text to be more accurate. In essence it still works fine.
Thanks I have found the way PHPExcel is a good library. In order to get PHPExcel http://www.codeplex.com/PHPExcel working with CodeIgniter, there are a few steps you must take to ensure compatibility with CodeIgniter's naming standards.
1: Class names must match the file names. PHPExcel has a few files(such as PHPExcel/IOFactory.php) that have names like PHPExcel_IOFactory. Change these names by removing the "PHPExcel_" part. These constructors in these files must be public in order for CI to access them.
Comments
$this->load->library('phpexcel');
$this->load->library('PHPExcel/iofactory');
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("title")
->setDescription("description");
// Assign cell values
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'cell value here');
// Save it as an excel 2003 file
$objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save("nameoffile.xls");