0

我想在使用 PHPExcel 设置值之前只更改一个字段:
例如001在电话号码之前设置:


....

if ($result = $DB->execute($sql) or die(mysql_error())) {
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getActiveSheet()->setTitle('List');
    $rowNumber = 1;
    while ($row = mysql_fetch_row($result)) {
        $col = 'A';
        foreach ($row as $cell) {
            $objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber, .'001 '.$row['phone']);
            $objPHPExcel->getActiveSheet()->setCellValue($col . $rowNumber, $cell);
            $col++;
        }
        $rowNumber++;
    }
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="myFile.xls"');
    header('Cache-Control: max-age=0');
    $objWriter->save('php://output');
    exit();
}



4

1 回答 1

1
$objPHPExcel->getActiveSheet()
            ->setCellValueExplicit($col.$rowNumber, .'001 '.$row['phone'], PHPExcel_Cell_DataType::TYPE_STRING);

或设置数字格式掩码以使用必要的位数,如果数字较短,则会给出前导零

于 2011-02-26T11:51:58.143 回答