用于 Excel 的新 Excel 电子表格库为 PHP codigniter 生成演示

发布于 2025-01-09 21:20:52 字数 226 浏览 1 评论 0原文

我正在使用 https://github.com/PHPOffice/PhpSpreadsheet 这个库。如果我们包含这个库,我们会收到与类相关的错误。我们面临找不到电子表格类的问题。

如何使用电子表格库生成 Excel。如果有任何例子,它对我很有帮助。

i am using https://github.com/PHPOffice/PhpSpreadsheet this library. If we include this library we getting error related to class. We facing issue of spreadsheet class not found.

how to generate excel using spreadsheet library. if any example it is help full for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏夜暖风 2025-01-16 21:20:52

只需通过 https://phpspreadsheet.readthedocs.io/en/latest/#installation 一次用于安装。之前我也遇到过这个问题,但我可以在本地主机和实时服务器上使用它。
这是示例代码...

<?php 
        $host = 'hostaddress';
        $user = 'root';
        $password = '';
        $database = 'db';

        $conn = mysqli_connect($host,$user,$password,$database);
        if(mysqli_connect_errno()){
            echo "Failed to connect to database" . mysqli_connect_errno();
        }

        $query1 = mysqli_query($conn, "SELECT * FROM restaurent_feedback ");
        $output = '';
        $i = 1;
        if($query1->num_rows > 0){
            $output = '<table border=1>
                        <tr>
                          <th>Slno</th>
                          <th>Restaurent_Name </th>
                          <th>Estimation_Name</th>
                          <th>Comment</th>
                          <th>Commented_By</th>
                          <th>Commented_on</th>
                        </tr>
            ';
        while($row = mysqli_fetch_array($query1)){
            $output .= '<tr>
                            <td>'.$i.'</td>
                            <td>'.$row['rest_name'].'</td>
                            <td>'.$row['est_name'].'</td>
                            <td>'.$row['comment'].'</td>
                            <td>'.$row['created_by'].'</td>
                            <td>'.$row['created_on'].'</td>
                </tr>';
                $i++;
        }
        $output .= "</table>";
    }
    require "vendor/autoload.php";
    use PhpOffice\PhpSpreadsheet\Spreadsheet;
    use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
    $spreadsheet = $reader->loadFromString($output);
    header("Content-Type: application/vnd.md-excel");
    header("Content-Disposition: attachment;filename=\"exporttoexcel.xls\"");
    $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
    $writer->save("php://output"); 
    ?>

这是我得到的输出

Just go through https://phpspreadsheet.readthedocs.io/en/latest/#installation once for installation.Earlier i too faced the issue but i can use it on both localhost and liveserver.
Here is the sample code...

<?php 
        $host = 'hostaddress';
        $user = 'root';
        $password = '';
        $database = 'db';

        $conn = mysqli_connect($host,$user,$password,$database);
        if(mysqli_connect_errno()){
            echo "Failed to connect to database" . mysqli_connect_errno();
        }

        $query1 = mysqli_query($conn, "SELECT * FROM restaurent_feedback ");
        $output = '';
        $i = 1;
        if($query1->num_rows > 0){
            $output = '<table border=1>
                        <tr>
                          <th>Slno</th>
                          <th>Restaurent_Name </th>
                          <th>Estimation_Name</th>
                          <th>Comment</th>
                          <th>Commented_By</th>
                          <th>Commented_on</th>
                        </tr>
            ';
        while($row = mysqli_fetch_array($query1)){
            $output .= '<tr>
                            <td>'.$i.'</td>
                            <td>'.$row['rest_name'].'</td>
                            <td>'.$row['est_name'].'</td>
                            <td>'.$row['comment'].'</td>
                            <td>'.$row['created_by'].'</td>
                            <td>'.$row['created_on'].'</td>
                </tr>';
                $i++;
        }
        $output .= "</table>";
    }
    require "vendor/autoload.php";
    use PhpOffice\PhpSpreadsheet\Spreadsheet;
    use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
    $reader = new \PhpOffice\PhpSpreadsheet\Reader\Html();
    $spreadsheet = $reader->loadFromString($output);
    header("Content-Type: application/vnd.md-excel");
    header("Content-Disposition: attachment;filename=\"exporttoexcel.xls\"");
    $writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
    $writer->save("php://output"); 
    ?>

here is the output which i got

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文