1

Can an excel file be manipulated with PHP? Can I insert certain value in certain cell?

RageZ
  • 26,800
  • 12
  • 67
  • 76
Yogesh
  • 363
  • 3
  • 9
  • 22

1 Answers1

9

See: http://phpexcel.codeplex.com/

That has all the functions you could ever need.

Sample:

4.5.1. Setting a cell value by coordinate Setting a cell value by coordinate can be done using the worksheet’s setCellValue method.

$objReader = new PHPExcel_Reader_Excel2007();
$objPHPExcel = $objReader->load("05featuredemo.xlsx");    
$objPHPExcel->getActiveSheet()->setCellValue('B8', 'Some value');
Derk Arts
  • 3,432
  • 2
  • 18
  • 36
  • Thank you very much! is it free? – Yogesh Dec 22 '11 at 10:31
  • Yes very free. Open Source has that great trait :) – Derk Arts Dec 22 '11 at 10:32
  • 1
    @Yogesh check their website and you'll know :). A small sidenote: depending on the level of manipulation you need, PHPEXcel might be too much or the perfect one; it's pretty big so if you just want to read, or to write to, there are other lighter alternatives (for example, a simple CSV file will be opened without problems in Excel). Check for ex. this [SO answer](http://stackoverflow.com/questions/563670/reading-an-excel-file-in-php) for these alternatives – Damien Pirsy Dec 22 '11 at 10:32
  • Will it iclude logo PHPExcel? when I will be using or we can remove it? – Yogesh Dec 22 '11 at 10:40
  • @Yogesh read their website! no watermark, anyway; oh, and read the APi docs, ok? ;) – Damien Pirsy Dec 22 '11 at 10:42
  • @Yogesh - PHPExcel is open-source, meaning you can actually look at the code yourself if you want to.... it's completely free to use as you wish (no restrictions for usage under a LGPL2 license), and free of charge (unless you want to donate anything to the developers as a "thank you" for their work), and isn't crippled in any way (no time limitations, or restrictions for filesize, or nasty logos appearing in your files) – Mark Baker Dec 22 '11 at 10:59
  • @Damien Pirsy - Just for future reference, http://stackoverflow.com/questions/3930975/alternative-for-php-excel is a better link for alternatives for reading/writing actual Excel files, rathe rthan the CSV options.... I try to keep that list of libraries up-to-date – Mark Baker Dec 22 '11 at 11:03
  • I deleted my comment as to not confuse people. – Derk Arts Dec 22 '11 at 11:31