使用php文件和excel导出来阅读php文件 [英] Read php file using php file and excel export

查看:128
本文介绍了使用php文件和excel导出来阅读php文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个文件,如下所示。

我想要做的是,我想获取第一个文件中的第二个文件内容,然后导出它xls。

下面的代码有什么问题。



我的意图是 - 读一秒php文件使用第一个php文件,然后excel将该内容导出到C:/myfiles/test.xls中的.xls中。
$ b

index.php



 <?php 
$ read_file = readfile(my_export_file.php);
$ file ='test.xls';
header(Content-type:application / vnd.ms-excel);
header(Content-Disposition:attachment; filename = $ file);
echo $ read_file;
?>



my_export_file.php



 < script type =text / javascript>我的javascript内容< / script> 
<?php
包括'db.php';
$ my_query =mysql查询获取表格内容;
?>
< table>
< tr>< td> .. mysql行内容..< / td>< td> .. mysql行内容..< / td>< / tr>
< tr>< td> .. mysql行内容..< / td>< td> .. mysql行内容..< / td>< / tr>
< tr>< td> .. mysql行内容..< / td>< td> .. mysql行内容..< / td>< / tr>
< / table>

有人可以帮我完成这件事。



问候,
Kimz

解决方案

发现解决方案,试试这个:

index.php

 <?php 
ob_start();
包含my_export_file.php;
$ contents = ob_get_contents();
ob_end_clean();
echo $ contents; //获取全部内容/测试
?>

希望这对您有所帮助。


I have two files like below.

What I'm trying to do is, I want to fetch the second file content in first file, and then export it to xls.

What is the problem with the below code.

My intension is to - read a second php file using first php file, and then excel export that content into .xls in C:/myfiles/test.xls

index.php

    <?php
    $read_file = readfile("my_export_file.php");
    $file = 'test.xls';
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename=$file");
    echo $read_file;
    ?>

my_export_file.php

    <script type="text/javascript"> my javascript content</script>
    <?php
    include 'db.php';
    $my_query = "mysql query to get the table content";
    ?>
    <table>
    <tr><td>.. mysql row content ..</td><td>.. mysql row content ..</td></tr>
    <tr><td>.. mysql row content ..</td><td>.. mysql row content ..</td></tr>
    <tr><td>.. mysql row content ..</td><td>.. mysql row content ..</td></tr>
    </table>

Could someone help me to get this done.

Thanks in advance.

Regards, Kimz

解决方案

Found out solution, try this:

index.php

<?php
ob_start();
include "my_export_file.php";
$contents = ob_get_contents();
ob_end_clean();
echo $contents; //get whole content/test
?>

Hope this help you.

这篇关于使用php文件和excel导出来阅读php文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆