I am writing the code to download logs to excel, OO and txt.
I wrote this few days ago and I am testing this now.
All is fine on my desktop computer. I can download to excel and to txt all my logs both in Moodle 1.5.3+ and 1.6. Yesterday I moved my "addition" to my portable pc.
Well, what I found was that... my "addition" is working fine on the laptop in Moodle 1.5.3+ but not in Moodle 1.6. The excel file I download is not "well formatted" and, by opening it, rubbish is in it. I spent some hours to check and check again the code and at the end I went to download to Excel the "Item Analysis" of a quiz and I found the same error: "Excel file is not recognized as well formatted". I went back to the desktop computer and... the "Item Analysis" download works fine. What it can be? I made a fresh installation of Moodle 1.6 beta 3 this morning both on the desktop and the portable. They have both the same OS (MacOSX 10.4.6) with the same php version (4.3.6) and the same mysql version (4.1.18). Do you have suggestions?
Attached is my "addition". Rev03 is for Moodle 1.6 and rev21 is for Moodle 1.5.3+
To test it backup and overwrite the existing files (2 files in Moodle 1.5.3+ and three files in Moodle 1.6) . You know better than me where do they are. Languages files are included.
Please reply me with an answer. I am getting crazy.
And to close: where can I find a macintosh free php IDE???????????
Hi Daniele,
Moodle 1.5 and Moodle 1.6 have different Excel libraries, so perhaps your PHP code does not take this into account?
Here is an example of PHP code which will create Excel files in Moodle 1.5 and Moodle 1.6. I offer it to you in case it may be useful:
all the best
Gordon
Moodle 1.5 and Moodle 1.6 have different Excel libraries, so perhaps your PHP code does not take this into account?
Here is an example of PHP code which will create Excel files in Moodle 1.5 and Moodle 1.6. I offer it to you in case it may be useful:
$downloadfilename = 'excel-file.xls';
// uncomment the following line, if this code is in a function
// global $CFG;
// create Excel workbook
if (file_exists("$CFG->libdir/excellib.class.php")) {
// Moodle >= 1.6
require_once("$CFG->libdir/excellib.class.php");
$wb = new MoodleExcelWorkbook("-");
} else {
// Moodle <= 1.5
require_once("$CFG->libdir/excel/Worksheet.php");
require_once("$CFG->libdir/excel/Workbook.php");
$wb = new Workbook("-");
}
// send headers
if (method_exists($wb, 'send')) {
// Moodle >=1.6
$wb->send($downloadfilename);
} else {
// Moodle <=1.5
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$downloadfilename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
// create worksheet
$ws = &$wb->add_worksheet('worksheet name');
// set cell format using:
// $fmt_properties = array();
// $fmt = &$wb->add_format($fmt_properties);
// print your cells here using:
// $ws->write_number($row, $col, $cellcontent, $fmt);
// $ws->write_string($row, $col, $cellcontent, $fmt);
// close the workbook (and send it to the browser)
$wb->close();
// uncomment the following line, if this code is in a function
// global $CFG;
// create Excel workbook
if (file_exists("$CFG->libdir/excellib.class.php")) {
// Moodle >= 1.6
require_once("$CFG->libdir/excellib.class.php");
$wb = new MoodleExcelWorkbook("-");
} else {
// Moodle <= 1.5
require_once("$CFG->libdir/excel/Worksheet.php");
require_once("$CFG->libdir/excel/Workbook.php");
$wb = new Workbook("-");
}
// send headers
if (method_exists($wb, 'send')) {
// Moodle >=1.6
$wb->send($downloadfilename);
} else {
// Moodle <=1.5
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$downloadfilename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
}
// create worksheet
$ws = &$wb->add_worksheet('worksheet name');
// set cell format using:
// $fmt_properties = array();
// $fmt = &$wb->add_format($fmt_properties);
// print your cells here using:
// $ws->write_number($row, $col, $cellcontent, $fmt);
// $ws->write_string($row, $col, $cellcontent, $fmt);
// close the workbook (and send it to the browser)
$wb->close();
all the best
Gordon
Thank you Gordon.
I changed my 1.6 code but it still works on my desktop computer and doesn't work on the laptop.
I'll continue my investigation.
Just a question. With the new library how can I change the width of an Excel column?
I used: $worksheet[1]->set_column(1, 1, 20);
in 1.5.3+ but now this doesn't work any more.
I changed my 1.6 code but it still works on my desktop computer and doesn't work on the laptop.
I'll continue my investigation.
Just a question. With the new library how can I change the width of an Excel column?
I used: $worksheet[1]->set_column(1, 1, 20);
in 1.5.3+ but now this doesn't work any more.
Hei Gordon
I read the uncorrect Excel file with
hexdump -C wrongExcelFile.xls
and I found that an extra line feed is the first character of the file (0a). By removing it manually I can open the file properly.
Which can be the source of the extra line feed? Attached is the code I modified on the basis of your suggestions.
Thank you in advance.
I read the uncorrect Excel file with
hexdump -C wrongExcelFile.xls
and I found that an extra line feed is the first character of the file (0a). By removing it manually I can open the file properly.
Which can be the source of the extra line feed? Attached is the code I modified on the basis of your suggestions.
Thank you in advance.
Hi Eloy and thank you for your support.
I tested your two updated function and they worked fine to me.
But I tested them only on my desktop PC because they didn't solve my problem of not "well formed excel file" on my laptop. I still have the extra 0a char at BOF.
I tested your two updated function and they worked fine to me.
But I tested them only on my desktop PC because they didn't solve my problem of not "well formed excel file" on my laptop. I still have the extra 0a char at BOF.
Which can be the source of the extra line feed?
Most probably an extra line feed at the end of some included php file, after the closing '?>' tag. Usual suspect is config.php.
Saludos. Iñaki.
GREEEEEEEEEEAT!!!!!!!!!!!!!
Thank you Iñaki
you were totally right.
I was quite a week I was changing all but not the first file in front of me.
Thank you.
Thank you, thank you and thank you again.
Thank you Iñaki
you were totally right.
I was quite a week I was changing all but not the first file in front of me.
Thank you.
Thank you, thank you and thank you again.