mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
tablelib MDL-24327 CSV and TSV export was not right.
For example, cells containing \n or " were not handled properly.
This commit is contained in:
parent
9404c7dbe7
commit
6944b5e47e
1 changed files with 42 additions and 20 deletions
|
@ -1536,33 +1536,53 @@ class table_ods_export_format extends table_spreadsheet_export_format_parent{
|
||||||
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class table_text_export_format_parent extends table_default_export_format_parent{
|
class table_text_export_format_parent extends table_default_export_format_parent {
|
||||||
var $seperator = "\t";
|
protected $seperator = "\t";
|
||||||
function start_document($filename){
|
protected $mimetype = 'text/tab-separated-values';
|
||||||
$this->filename = $filename.".txt";
|
protected $ext = '.txt';
|
||||||
header("Content-Type: application/download\n");
|
|
||||||
header("Content-Disposition: attachment; filename=\"{$filename}.txt\"");
|
public function start_document($filename) {
|
||||||
header("Expires: 0");
|
$this->filename = $filename . $this->ext;
|
||||||
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
|
header('Content-Type: ' . $this->mimetype . '; charset=UTF-8');
|
||||||
header("Pragma: public");
|
header('Content-Disposition: attachment; filename="' . $this->filename . '"');
|
||||||
|
header('Expires: 0');
|
||||||
|
header('Cache-Control: must-revalidate,post-check=0,pre-check=0');
|
||||||
|
header('Pragma: public');
|
||||||
$this->documentstarted = true;
|
$this->documentstarted = true;
|
||||||
}
|
}
|
||||||
function start_table($sheettitle){
|
|
||||||
|
public function start_table($sheettitle) {
|
||||||
//nothing to do here
|
//nothing to do here
|
||||||
}
|
}
|
||||||
function output_headers($headers){
|
|
||||||
echo implode($this->seperator, $headers)."\n";
|
public function output_headers($headers) {
|
||||||
|
echo $this->format_row($headers);
|
||||||
}
|
}
|
||||||
function add_data($row){
|
|
||||||
echo implode($this->seperator, $row)."\n";
|
public function add_data($row) {
|
||||||
|
echo $this->format_row($row);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
function finish_table(){
|
|
||||||
|
public function finish_table() {
|
||||||
echo "\n\n";
|
echo "\n\n";
|
||||||
}
|
}
|
||||||
function finish_document(){
|
|
||||||
|
public function finish_document() {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a row of data.
|
||||||
|
* @param array $data
|
||||||
|
*/
|
||||||
|
protected function format_row($data) {
|
||||||
|
$escapeddata = array();
|
||||||
|
foreach ($data as $value) {
|
||||||
|
$escapeddata[] = '"' . str_replace('"', '""', $value) . '"';
|
||||||
|
}
|
||||||
|
return implode($this->seperator, $escapeddata) . "\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1571,8 +1591,9 @@ class table_text_export_format_parent extends table_default_export_format_parent
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class table_tsv_export_format extends table_text_export_format_parent{
|
class table_tsv_export_format extends table_text_export_format_parent{
|
||||||
var $seperator = "\t";
|
protected $seperator = "\t";
|
||||||
|
protected $mimetype = 'text/tab-separated-values';
|
||||||
|
protected $ext = '.txt';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1581,8 +1602,9 @@ class table_tsv_export_format extends table_text_export_format_parent{
|
||||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||||
*/
|
*/
|
||||||
class table_csv_export_format extends table_text_export_format_parent{
|
class table_csv_export_format extends table_text_export_format_parent{
|
||||||
var $seperator = ",";
|
protected $seperator = ",";
|
||||||
|
protected $mimetype = 'text/csv';
|
||||||
|
protected $ext = '.csv';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue