PHPExcel:无法将索引号和最后一列值设置为 "Date"

PHPExcel: Can't set index number & last column value as "Date"

我是过去两天学习 PHPExcel 的新手,我正在为表单输入数据生成一份报告。我在 excel 报告中动态生成了列,但无法将第一列设置为索引,将最后一列设置为日期。 我的代码是:

// setting column names begin
$col = 1;
$row = 0;

$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $row, "Index   No.");

foreach ($formInfo['fields'] as $fields) {
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row,   $fields['grid-name']);
$col++;
}
$objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, 'Date & Time of Input');

// setting column names ends!

提前感谢您的回复。

你的成就最大。我刚刚更新了你的代码。现在它将按照您的意愿工作。

// Initializing last col variable
$endcolval = 0;
// Storing the value to First Column
$objPHPExcel->setActiveSheetIndex(0)
                          ->setCellValueByColumnAndRow(0, 1, "Index");
// Storing the rest of the values from array to the respect indexes
foreach ($formInfo['fields'] as $col=>$fields)
{
    $objPHPExcel->setActiveSheetIndex(0)
                          ->setCellValueByColumnAndRow($col+1, 1, $fields['grid-name']);
    // Using the above function you can able dynamically store the values to the cell.
    // setCellValueByColumnAndRow(Column_Number, Row_Number, Value_To_Save);
    $endcolval = $col+1;// Getting the last column number
}
// Assigning the Date to the Last Column.
$objPHPExcel->setActiveSheetIndex(0)
                          ->setCellValueByColumnAndRow($endcolval+1, 1, "Date");