What is the best way to create XLS file in PHP

后端 未结 9 1250
予麋鹿
予麋鹿 2020-12-05 14:03

I am currently trying to figure out the best way to create a .xls file from PHP. It seems like to me that all I need to do is change the header content type to \"application

相关标签:
9条回答
  • 2020-12-05 15:02

    You could use one of the XML formats that Microsoft Office understands.

    See Microsoft's OpenXML Developer site for details/specs.

    There is a library on called PHPExcel that you can look at to help you with this.

    Of course, this all depends on what you mean by:

    "get the most out of that file format"

    If you just have simple tables with no formatting, CSV files may be all you need; however, if you want to use more features of a spreadsheet, I would recommend taking a look at OpenXML.

    0 讨论(0)
  • 2020-12-05 15:05

    Take a look at this PEAR package: Spreadsheet Excel Writer

    0 讨论(0)
  • 2020-12-05 15:05

    You can start using this files. It will create a excel file and help you download it.

    You can add rows like this in the

    01-simple-download-xlsx.php

    $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A1', 'Roll')
                ->setCellValue('B1', 'Name')
                ->setCellValue('C1', 'Total Classes')
                ->setCellValue('D1', 'Class Attended')
            ->setCellValue('E1', 'Percentage');
    

    You can print data from a database like this using a while loop.

    $i=2;   
    while ($row = $database->fetch_array($result)) 
     { 
    
           $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A'.$i, $row[0])
                ->setCellValue('B'.$i, $row[1])
                ->setCellValue('C'.$i, $row[2])
                ->setCellValue('D'.$i, $total)
            ->setCellValue('E'.$i, round(($row[2]/$total)*100));
              $i++;
     }
    
    0 讨论(0)
提交回复
热议问题