Exemplo n.º 1
0
 /**
  * Close the Moodle Workbook.
  */
 public function close()
 {
     global $CFG;
     require_once $CFG->libdir . '/filelib.php';
     $writer = new MoodleODSWriter($this->worksheets);
     $contents = $writer->get_file_content();
     send_file($contents, $this->filename, 0, 0, true, true, $writer->get_ods_mimetype());
 }
Exemplo n.º 2
0
    function export_ods($report, $filename = null) {
        global $DB, $CFG;
        require_once($CFG->dirroot . '/lib/odslib.class.php');

        $table = $report->table;
        $matrix = array();
        //!$fname? $filename = 'report_'.(time()).'.ods':
        $filename = $filename . '.ods';

        if (!empty($table->head)) {
            $countcols = count($table->head);
            $keys = array_keys($table->head);
            $lastkey = end($keys);
            foreach ($table->head as $key => $heading) {
                $matrix[0][$key] = str_replace("\n", ' ', htmlspecialchars_decode(strip_tags(nl2br($heading))));
            }
        }

        if (!empty($table->data)) {
            foreach ($table->data as $rkey => $row) {
                foreach ($row as $key => $item) {
                    $matrix[$rkey + 1][$key] = str_replace("\n", ' ', htmlspecialchars_decode(strip_tags(nl2br($item))));
                }
            }
        }
        $workbook = new MoodleODSWorkbook($filename);

        $myxls = array();

        $myxls[0] = $workbook->add_worksheet('');
        foreach ($matrix as $ri => $col) {
            foreach ($col as $ci => $cv) {
                $myxls[0]->write($ri, $ci, $cv);
            }
        }
        $writer = new MoodleODSWriter($myxls);
        $contents = $writer->get_file_content();
        $handle = fopen($filename, 'w');
        fwrite($handle, $contents);
        fclose($handle);
    }
Exemplo n.º 3
0
 /**
  * Close the Moodle Workbook.
  */
 public function close()
 {
     $writer = new MoodleODSWriter($this->worksheets);
     $contents = $writer->get_file_content();
     send_file($contents, $this->filename, 0, 0, true, true, $writer->get_ods_mimetype());
 }