开发者

change one field with PHPExcel

开发者 https://www.devze.com 2023-02-13 19:40 出处:网络
I want to change just one field before set the values with PHPExcel: For example to set 001 before the phone number:

I want to change just one field before set the values with PHPExcel:

For example to set 001 before the phone number:


....

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) {
            $objPHP开发者_开发问答Excel->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();
}




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

or set the number format mask to use the requisite number of digits, which will then give leading zeroes if the number is shorter

0

精彩评论

暂无评论...
验证码 换一张
取 消