Ejemplo n.º 1
0
    }
    return iconv('gb2312', 'utf-8', $str);
}
//从数据库输出数据处理方式
//从数据库读取数据如:
$con = mysql_connect("localhost", "root", "123456");
mysql_select_db('test', $con);
//$db = new Mysql($dbconfig);
$result = mysql_query('SELECT * FROM  user');
$user_info = array();
while ($row = mysql_fetch_array($result)) {
    $user_info[] = $row;
}
//print_r($user_info);
$count = count($user_info);
for ($i = 2; $i <= $count + 1; $i++) {
    $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, convertUTF8($user_info[$i - 2][0]));
    $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, convertUTF8($user_info[$i - 2][1]));
    $objPHPExcel->getActiveSheet()->setCellValue('C' . $i, convertUTF8($user_info[$i - 2][2]));
    // $objPHPExcel->getActiveSheet()->setCellValue('D' . $i, convertUTF8($user_info[$i-2][4]));
    // $objPHPExcel->getActiveSheet()->setCellValue('E' . $i, convertUTF8(date("Y-m-d", $row[$i-2][5])));
    // $objPHPExcel->getActiveSheet()->setCellValue('F' . $i, convertUTF8($user_info[$i-2][6]));
    // $objPHPExcel->getActiveSheet()->setCellValue('G' . $i, convertUTF8($user_info[$i-2][7]));
    // $objPHPExcel->getActiveSheet()->setCellValue('H' . $i, convertUTF8($user_info[$i-2][8]));
}
//在默认sheet后,创建一个worksheet
echo date('H:i:s') . " Create new Worksheet object\n";
$objPHPExcel->createSheet();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//$objWriter->save('php://output');
$objWriter->save("xxx.xlsx");
Ejemplo n.º 2
0
    $j = $i;
    foreach ($data as $value) {
        $j = $i;
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $i, $value['name']);
        $techs = $value["keywords"];
        if (is_array($techs)) {
            foreach ($techs as $tech) {
                $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B' . $i, convertUTF8($tech['name']))->setCellValue('C' . $i, convertUTF8($tech['weight']))->setCellValue('D' . $i, convertUTF8($tech['pass_score']))->setCellValue('E' . $i, convertUTF8($tech['pass_score'] <= $tech['_score'] ? '是' : '否'));
                $i++;
            }
            $objPHPExcel->getActiveSheet()->mergeCells('A' . $j . ':' . 'A' . ($i - 1));
        }
    }
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $i, convertUTF8("总得分:" . $scores));
    $objPHPExcel->getActiveSheet()->mergeCells('A' . $i . ':E' . $i);
    $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . ($i + 1), convertUTF8("结果:" . $meet . $pro_level));
    $objPHPExcel->getActiveSheet()->mergeCells('A' . ($i + 1) . ':E' . ($i + 1));
}
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
$callStartTime = microtime(true);
ob_end_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");