PHP simple Excel lib

2019-08-18 04:52发布

I'm looking for a way to do the following:

$file = 'file.xls';
$input = '<tr><td>Some input</td></tr>';

if (!file_exists($file))
{
     create_excel($file);  //Create the sheet
     input_titles($file);  //Add column titles
}
else
{
     add_input_to_the_last_line($input);
}

Is there a library which can simply do the above?

标签: php excel
1条回答
smile是对你的礼貌
2楼-- · 2019-08-18 05:41

You could use PHPExcel library:

Example Usage:

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$rowCount = 1;
while($row = mysql_fetch_array($result)){
    $objPHPExcel->getActiveSheet()->SetCellValue('A'.$rowCount, <your_row_name>);
    $objPHPExcel->getActiveSheet()->SetCellValue('B'.$rowCount, <your_row_name>);
    $rowCount++;
}
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save('your_file_name.xlsx');
查看更多
登录 后发表回答