Dynamic Column names

Jul 23, 2009 at 6:47 AM

hi all,

am new to php

can u guys tell me to use excel cells based on number rather than string

eg:

$objPHPExcel->getActiveSheet()->setCellValue('B1' ,"Hello");

 

instead of "B1".. i need to give cell(1,2).. (am using dynamic contents based on query return value)

 

Developer
Jul 23, 2009 at 7:02 AM
// 0-based column index
// 1-based row index

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, "Hello");

 

Jul 23, 2009 at 10:00 AM

thanks man,,

 

one more query... wat do i do incase of formula..

i have to create many worksheets.. and thier row count of each sheet  depends on single query output...

we write formula like "=count(A1:A10)"....

can i use one(1) instead of string A in above formula...

this is because.. i have dynamic coulmns and rows in each work sheet based on a single query..

if any queries let me know

 

Jul 23, 2009 at 10:30 AM

also i need code for formatting based on numbers...

hmmm (c4).setwidth(3)  ...i want it as cells(3,4).setwidth(3)...can someone help me

 

Coordinator
Jul 23, 2009 at 5:38 PM

You might find PHPExcel_Cell::stringFromColumnIndex($pColumnIndex) useful. Pass in $pColumnIndex as your numeric column value, get back the column letter. e.g PHPExcel_Cell::stringFromColumnIndex(0) returns A, PHPExcel_Cell::stringFromColumnIndex(25) returns Z, PHPExcel_Cell::stringFromColumnIndex(26) returns AA, etc

PHPExcel_Cell::columnIndexFromString($pColumnString) is the reverse function, so PHPExcel_Cell::columnIndexFromString('IV') would return 256

Jul 24, 2009 at 1:19 PM

thanks man.. i got it.