我已经设法使用PHPexcel从oracle数据库生成并下载了一个excel文件,下面是我的编码供参考: -
// Instantiate a new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set the active Excel worksheet to sheet 0
$objPHPExcel->setActiveSheetIndex(0);
// Initialise the Excel row number
$rowCount = 2;
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'ATB')->getStyle('A1')->getFill()->applyFromArray(
array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array('rgb' => 'FFFF00'),
'endcolor' => array('rgb' => 'FFFF00'),
)
);
$objPHPExcel->getActiveSheet()->SetCellValue('B1', 'ATA')->getStyle('B1')->getFill()->applyFromArray(
array(
'type' => PHPExcel_Style_Fill::FILL_SOLID,
'startcolor' => array('rgb' => 'FFFF00'),
'endcolor' => array('rgb' => 'FFFF00')
)
);
// Iterate through each result from the SQL query in turn
// We fetch each database result row into $row in turn
while($objResult = oci_fetch_array($objParse,OCI_ASSOC+OCI_RETURN_NULLS)){
// Set cell An to the "name" column from the database (assuming you have a column called name)
// where n is the Excel row number (ie cell A1 in the first row)
$objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, $objResult["ATB"])->getStyle('A'.$rowCount)->getNumberFormat()->setFormatCode('dd/mm/yyyy hh:mm:ss');
// Set cell Bn to the "age" column from the database (assuming you have a column called age)
// where n is the Excel row number (ie cell A1 in the first row)
$objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, $objResult["ATA"])->getStyle('B'.$rowCount)->getNumberFormat()->setFormatCode('dd/mm/yyyy hh:mm:ss');
// Increment the Excel row counter
$rowCount++;
}
// Instantiate a Writer to create an OfficeOpenXML Excel .xlsx file
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
// Write the Excel file to filename some_excel_file.xlsx in the current directory
$objWriter->save('report_actual.xlsx');
因此,当我打开excel文件时,ATB和ATA的列值格式为dd / mm / yyyy hh:mm:ss。我现在的意图是为ATB汇总所有列,并将总和作为数字。但是现在的问题是在SUM所有ATB结果为0之后,所以我需要双击ATB的每一列,它将开始计算总SUM。仅供参考,我的excel文件如下所示:
| ATB | ATA |
| 22/03/2013 07:00:00 | 21/03/2013 20:20:00 |
| 23/03/2013 17:10:00 | 22/03/2013 04:45:00 |
我注意到当我双击那个特定的列时,在公式栏上的值(ATB 22/03/2013 07:00:00的例子)变得像这样一个22/3/2013 7:00: 00 AM当值变为这样时,总SUM列将自动开始求和。想象一下,如果我需要双击一千行!
所以我想寻求专家的任何建议/帮助/意见。有没有简单的方法来解决所有ATB没有做这个混乱的工作?我更喜欢SUM也可以使用PHPexcel自动计算。
(p / s:我知道excel SUM功能基于1/1/1900 00:00:00)
如果有人可以帮助我,我很高兴。非常感谢。