错误的文本格式phpExcel

时间:2017-05-29 15:37:41

标签: php mysql excel phpexcel

我正在创建一个php脚本,用于查询远程SQL数据库并通过PHPExcel在excel上导出结果。 在我的数据库中,我有一列名为“syllabus”的varchars,其值为enter image description here。 如果我在HTML上创建一个简单的表格,文本是正确的enter image description here 但是,如果我导出到excel,则返回给我:enter image description here 该列被格式化为文本,如果我手动插入数据,它的工作没有问题。 这是脚本:`errno)die($ mysqli-> error);

require_once '/home/ecdlmalignani/ecdl.malignani.org/Classes/PHPExcel.php';

$phpExcel = new PHPExcel;

// Load an existing spreadsheet
$phpExcel = PHPExcel_IOFactory::load('/home/ecdlmalignani/ecdl.malignani.org/template.xlsx');

if(isset($_GET['sessione']))
{
    $sql  = "SELECT skill_card.`ID_skillCard`, utenti.cognome, utenti.nome, DATE_FORMAT(utenti.data_nascita, '%d/%m/%Y') AS date, moduli.descrizione_modulo, moduli.syllabus\n"
            . "FROM `skill_card` INNER JOIN utenti ON skill_card.`cod_fiscale` = utenti.cod_fiscale\n"
            . "INNER JOIN esami ON esami.skill_card = skill_card.`ID_skillCard`\n"
            . "INNER JOIN moduli ON moduli.ID_modulo = esami.ID_modulo\n"
            . "WHERE esami.ID_sessione=".$_GET['sessione']." AND esami.pagato = 'SI' AND esami.stato = 'ISCRITTO'";
    $res = $mysqli->query($sql);
    $row_increment = 0;
    while ($row = $res->fetch_array(MYSQLI_BOTH))
    {
        for($column_increment = 0; $column_increment < 5; $column_increment++)
        {
            $cell = chr(65+$column_increment) . chr(50+$row_increment);
            $phpExcel->getActiveSheet()->setCellValue($cell, $row[$column_increment]);
        }
        $phpExcel->getActiveSheet()->setCellValue('F'.chr(50+$row_increment), $row['syllabus']);
        $phpExcel->getActiveSheet()->setCellValue('G'.chr(50+$row_increment),'it');
        $phpExcel->getActiveSheet()->setCellValue('H'.chr(50+$row_increment),'ATLAS');
        $row_increment++;
    }
}

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="iscrizioni.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
$objWriter->setPreCalculateFormulas();
$objWriter->save('php://output');

0 个答案:

没有答案