0

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.

1
  • So have you looked for any of the myriad of PHP libraries such as PHPExcel that will help you to do this? Commented Jun 24, 2014 at 15:22

3 Answers 3

1

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.
Sign up to request clarification or add additional context in comments.

4 Comments

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 file
It works well, also for Doc files, clients are using for years without any complains.
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 disingenuous
Thanks for the update, i changed the text to be more accurate. In essence it still works fine.
0

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

0
$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");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.