dsdioa9545 2016-08-03 10:28
浏览 150

使用PHPExcel保存xlsx文件

I want to create an xlsx file and I'm using PHPExcel. For now I just added a line and I'm trying to create and save the file but it doesn't work.

My code is :

$objPHPExcel = new PHPExcel();
    $chemin = "./././files/resultats/simulation".$singleton->getNom()."_".date("d").".".date("m").".".date("y").".xml";
    $xmlFile = simplexml_load_file($chemin);

    $ligne = "3";
    $colonne = "B";

    foreach ($xmlFile as $xml) //on aprcours les attributs <Simulation>
    {
        $objPHPExcel->getActiveSheet()->setTitle('Synthèse système culture');
        $objPHPExcel->getActiveSheet()->setCellValue("B".$ligne,"Nom du système de culture");
        $objPHPExcel->getActiveSheet()->mergeCells("B3:B4");

        $ligne++; //Quand on termine une simulation, on ajoute une ligne pour afficher la simulation suivante sur la ligne du dessous
    }
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="test.xlsx"');
    header('Cache-Control: max-age=0');

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    $objWriter->save('test.xlsx');

What is wrong with that ? I'm trying to save "test.xlsx" and it doesn't work.

  • 写回答

1条回答 默认 最新

  • duanpoqiu0919 2016-08-03 10:38
    关注

    You are saving the .xlsx file to the server and not to the output stream. You could do this by using:

    $objWriter->save('php://output'); 
    

    Or by reading the saved file to the output buffer using:

    readfile('test.xlsx');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘