2
require_once 'data.php';
echo '<table cellspacing="3" cellpadding="2" border="1">';
reset($mas);
$header = current($mas);
$header = array_merge(array('tankla'=>'tankla'), $header);
foreach ($header as $key=>$val) {
    echo '<th>'.$key.'</th>';
}
echo '</tr>';
foreach ($mas as $tankla=>$data) {
    echo '<tr>';
    echo '<td>'.utf8_decode($tankla).'</td>';
    foreach ($data as $day=>$value) {
        echo '<td style="text-align: right;">'.$value.'</td>';
    }
    echo '</tr>';
}
echo '</table>';

我需要这个东西在phpexcel里面。有关如何制作此代码的任何建议?

4

2 回答 2

0

你可以看看PHPEXCEL

示例用法:

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);

//foreach loop{
    $objPHPExcel->getActiveSheet()->SetCellValue('A', <your_column_val>);
    $objPHPExcel->getActiveSheet()->SetCellValue('B', <your_column_val>);

//}
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('your_file_name.xlsx');
于 2013-04-02T12:06:04.413 回答
0
$row = 1;
$column = 'A';
foreach ($header as $key=>$val) {
    $objPHPExcel->getActiveSheet()->setCellValue(
        $column . $row,
        $key
    );
    $column++;
}
$row++;
foreach ($mas as $tankla=>$data) {
    $column = 'A';
    $objPHPExcel->getActiveSheet()->setCellValue(
        $column . $row,
        utf8_decode($tankla)
    );
    foreach ($data as $day=>$value) {
        $column++;
        $objPHPExcel->getActiveSheet()->setCellValue(
            $column . $row,
            $value
        );
    }
    $row++;
}
于 2013-04-02T14:38:03.257 回答