如何在PHP Excel中创建列号

As the simple php excel we get the function setCellvalue('A1','product').But i wanted to make this column to change dynamically by placing it in loop.MY code is given below

<?php
/**
 * Created by PhpStorm.
 * User: Anurag
 * Date: 3/9/14
 * Time: 6:09 PM
 */


$Selected_data=$_REQUEST['data'];
/*
echo'<pre>';
print_r($Selected_data);
echo'<pre>';
*/
$Parse_Selected_data=json_decode($Selected_data,TRUE);
/*
echo'<pre>';
print_r($Parse_Selected_data);
echo'<pre>';
*/
$row_count=$Parse_Selected_data[0]['row_count'];

//echo($row_count);

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');

if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
require('Excel/PHPExcel.php');


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
    ->setLastModifiedBy("Maarten Balliauw")
    ->setTitle("Office 2007 XLSX Test Document")
    ->setSubject("Office 2007 XLSX Test Document")
    ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
    ->setKeywords("office 2007 openxml php")
    ->setCategory("Test result file");

/*
 * Add the Items to the Excel sheet*/

//**************** SET THE HEADER ***********//

$objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue(chr(65),'S.NO');

//******************************* SET AUTO COLUMN WIDTH **************//

$objPHPExcel->getActiveSheet(0)->getColumnDimension('A')->setAutoSize(true);
$objPHPExcel->getActiveSheet(0)->getColumnDimension('B')->setAutoSize(true);
$objPHPExcel->getActiveSheet(0)->getColumnDimension('C')->setAutoSize(true);
$objPHPExcel->getActiveSheet(0)->getColumnDimension('D')->setAutoSize(true);
$objPHPExcel->getActiveSheet(0)->getColumnDimension('E')->setAutoSize(true);
$objPHPExcel->getActiveSheet(0)->getColumnDimension('F')->setAutoSize(true);

//**************** SET HE SIZE AND BOLD ****************************//

$objPHPExcel->getActiveSheet(0)->getStyle('A1')->getFont()->setBold(true)->setSize(14);
$objPHPExcel->getActiveSheet(0)->getStyle('B1')->getFont()->setBold(true)->setSize(14);
$objPHPExcel->getActiveSheet(0)->getStyle('C1')->getFont()->setBold(true)->setSize(14);
$objPHPExcel->getActiveSheet(0)->getStyle('D1')->getFont()->setBold(true)->setSize(14);
$objPHPExcel->getActiveSheet(0)->getStyle('E1')->getFont()->setBold(true)->setSize(14);
$objPHPExcel->getActiveSheet(0)->getStyle('F1')->getFont()->setBold(true)->setSize(14);

//***************** Add some data **************//

$objPHPExcel->setActiveSheetIndex(0)
    ->setCellValue('A2', 'Hello')
    ->setCellValue('B2', 'world!')
    ->setCellValue('C2', 'Hello')
    ->setCellValue('D2', 'world!');



// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>

Please let me know how to get it done.

Try this..

//$i = asci value i.e. 65 to any column asci
$cell=chr($i).$num; // u can dynamically change the number also.
$objWorksheet->setCellValue($cell , 'Comments:');

If you have more than A-Z columns you can use this function:

function getCellFromColnum($colNum) {
    return ($colNum < 26 ? chr(65+$colNum) : chr(65+floor($colNum/26)-1) . chr(65+ ($colNum % 26)));
}