Php 与moodle excellib合作
谁能给我提供一个moodle excellib库的工作示例。目前我无法使用它,因为它使用当前页面的所有html标记编写xls文件,而不是我真正想要在其中编写的内容。我需要使用此库创建自定义表。目前,我在/local中创建了一个实验页面,只是为了玩它。但是没有运气。代码如下:Php 与moodle excellib合作,php,excel,moodle,Php,Excel,Moodle,谁能给我提供一个moodle excellib库的工作示例。目前我无法使用它,因为它使用当前页面的所有html标记编写xls文件,而不是我真正想要在其中编写的内容。我需要使用此库创建自定义表。目前,我在/local中创建了一个实验页面,只是为了玩它。但是没有运气。代码如下: <?php /* * To change this license header, choose License Headers in Project Properties. * To change this
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//The number of lines in front of config file determine the // hierarchy of files.
require_once(dirname(dirname(__FILE__)).'/config.php');
$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('admin');
$PAGE->set_title("Experiment Page");
$PAGE->set_heading("Blank page");
$PAGE->set_url($CFG->wwwroot.'/blank_page.php');
echo $OUTPUT->header();
$filename = 'report_'.(time());
$downloadfilename = clean_filename($filename);
/// Creating a workbook
$workbook = new MoodleExcelWorkbook("-");
/// Sending HTTP headers
$workbook->send($downloadfilename);
/// Adding the worksheet
$myxls = $workbook->add_worksheet($filename);
$workbook->close();
exit;
echo $OUTPUT->footer();
问题是您正在将页眉输出回用户的浏览器,然后开始生成Excel文件。删除所有$PAGE行,最重要的是删除echo$OUTPUT->header;线路,它会工作得更好 如果我想要输出和页面变量,同时想在文件中写入我喜欢的内容,该怎么办?你可以输出文件或网页,但不能同时输出这两个变量。你可以输出一个页面,通过链接输出文件,或通过javascript重定向输出文件。我尝试了后一个,我有一个链接,它将表对象发送到另一个php文件中定义的函数,该文件将其写入excel,但它也会输出整个页面……我不确定“它将表对象发送到另一个php文件中定义的函数”是什么意思。链接应该指向一个PHP文件,它只做一件事,即输出Excel文件。如果在同一请求中输出了其他内容,则下载将无法工作。这里有一个例子:。'“index.php”有一个发布到“export.php”的表单“export.php”除了Excel文档外,不输出任何内容。谢谢您的回答。