Hola comunidad

Topics: Developer Forum, User Forum
Nov 7, 2012 at 5:50 PM
Edited Nov 7, 2012 at 7:17 PM

I desarrolando a web application to export an entire table with fields to excel, but I am using PHPExcel Prints vertically fields, and I want to be in As Is mysql horizontally ... Someone please help what has worked?
mysql

 

cell 1 cell 2 cell 3 cell 4
field 1 Field 2 Field 3 Field 4
field 5 Field 6 Field 7 Field 8

 

PhpExcel generates

Cell 1 Cell 2
field 1 Field 5
Field 2 Field 6
field 3 Field 7
Field 4 Field 8

help :-:

Some code:

$contador=0;$qry=mysql_query("select * from expedientesprestados") ; $count=mysql_num_rows($qry);
while($row=mysql_fetch_array($qry)){
$objPHPExcel->getActiveSheet()->setCellValue(entradaColumna($contador)."1",$row[0]);

$contador++;
}

Nov 7, 2012 at 5:51 PM

wat denk je zelf? gebruik anders een van de voorbeelden gast!

Nov 7, 2012 at 5:54 PM

 gebruik anders een van de voorbeelden gast???

helpen

Nov 7, 2012 at 6:45 PM

What I tried to illustrate is that you would most probably receive a lot more help if you pose your question in english (as most readers can actually understand that). If you check the rest of the discussions, you will see the language used here is english, and not spanish.

Nov 7, 2012 at 7:54 PM

 

I desarrolando a web application to export an entire table with fields to excel, but I am using PHPExcel Prints vertically fields, and I want to be in As Is mysql horizontally ... Someone please help what has worked? 
mysql

 

cell 1 cell 2 cell 3 cell 4
field 1 Field 2 Field 3 Field 4
field 5 Field 6 Field 7 Field 8

 

PhpExcel generates

Cell 1 Cell 2
field 1 Field 5
Field 2 Field 6
field 3 Field 7
Field 4 Field 8

help :-:

Some code:

$contador=0;$qry=mysql_query("select * from expedientesprestados") ; $count=mysql_num_rows($qry);
while($row=mysql_fetch_array($qry)){
$objPHPExcel->getActiveSheet()->setCellValue(entradaColumna($contador)."1",$row[0]);

$contador++;
}

Nov 9, 2012 at 12:39 PM

You need really to have a MySQL record on several lines ?
Your sample are not clear : you write always the first field ($row[0]), the Excel row are fixed, too (1), but perhaps you have a line for each field ?
What is the entradaColumna function ? A helper function to translate a numeric column to a string column (be carreful 27 isnt column "\") ?
But the parameter is a row.

It's more easy to use setCellValueByColumnAndRow : you can use numeric parameters, easy to increment ('A'+1 work... until 'Z').
$contador=1; //Columns are zero-based, rows are one-based... Often:-)
while($row=mysql_fetch_array($qry)){
    $NumCol=0;
    foreach($row as $aField)[
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($NumCol++, $contador,$aField);
    }
    $contador++;
}
If you need to have several lines by record, add a test in the foreach loop, to reset $NumCol and increment $contador.
You can adapt this code to use Cell coordinate ("A1") but your entradaColumna need a column value, not a row. Don't reinvent the wheel : Mark has write some functions to convert from/to numeric/alphabetic.

Nov 9, 2012 at 4:05 PM

could you provide me a link of the function to convert the alphabetical mark ... thanks for I use this function:

function entradaColumna($col_ent){

$hdc = array(0 => "A", 1 => "B", 2 => "C", 3 => "D", 4 => "E", 5 => "F", 6 => "G", 7 => "H",  8 => "I", 9 => "J", 10 => "K", 11 => "L", 12 => "M", 13 => "N", 14 => "O", 15 => "P", 16 => "Q", 17 => "R", 18 => "S", 19 => "T", 20 => "U", 21 => "V", 22 => "W", 23 => "X", 24 => "Y", 25 => "Z" );return ($col_ent < 26) ? $hdc[$col_ent] : $hdc[(int)($col_ent/26)-1].$hdc[($col_ent % 26)];

}

thanks

Nov 10, 2012 at 2:30 PM
These features are included in PHPExcel, they are static methods of the PHPEXcel_Cell class:

PHPExcel_Cell::columnIndexFromString([string $pString = 'A'])
return: column index (base 1)
PHPExcel_Cell::stringFromColumnIndex([int $pColumnIndex = 0])
The column index is 0-based.

In the documentation of the API, you can find them in the PHPExcel_Cell package, class PHPExcel_Cell.
I flew over your function at first glance, it is not false, but does not support the columns of Excel 2007 +, which limit 16384 (XFD), columns in three letters.
Note: In my sentence, "Mark" is Mark Baker, the remarkable PHPExcel Coordinator.