diff --git a/lib/odslib.class.php b/lib/odslib.class.php
index 5ddfd0f15d1..e6c87e2c654 100644
--- a/lib/odslib.class.php
+++ b/lib/odslib.class.php
@@ -422,6 +422,40 @@ class MoodleODSFormat {
// OpenDocument XML functions
//=============================
function get_ods_content(&$worksheets) {
+
+
+ // find out the size of worksheets and used formats
+ $formats = array();
+ $formatstyles = '';
+ $colstyles = '';
+
+ foreach($worksheets as $wsnum=>$ws) {
+ $ws->maxr = 0;
+ $ws->maxc = 0;
+ foreach($ws->data as $rnum=>$row) {
+ if ($rnum > $ws->maxr) {
+ $ws->maxr = $rnum;
+ }
+ foreach($row as $cnum=>$col) {
+ if ($cnum > $ws->maxc) {
+ $ws->maxc = $cnum;
+ }
+ }
+ }
+
+ foreach($ws->columns as $cnum=>$col) {
+ if ($cnum > $ws->maxc) {
+ $ws->maxc = $cnum;
+ }
+ //define all column styles
+ if (!empty($ws->columns[$cnum])) {
+ $colstyles .= '
+
+
+ ';
+ }
+ }
+ }
/// header
$buffer =
@@ -433,15 +467,8 @@ function get_ods_content(&$worksheets) {
';
- //define all needed styles
- foreach($worksheets as $ws) {
- foreach($ws->columns as $ckey=>$col) {
- $buffer .= '
-
-
- ';
- }
- }
+$buffer .= $formatstyles;
+$buffer .= $colstyles;
$buffer .= '
@@ -449,43 +476,24 @@ function get_ods_content(&$worksheets) {
';
- foreach($worksheets as $ws) {
+ foreach($worksheets as $wsnum=>$ws) {
/// worksheet header
$buffer .= ''."\n";
- $maxr = 0;
- $maxc = 0;
- foreach($ws->data as $rkey=>$row) {
- if ($rkey > $maxr) {
- $maxr = $rkey;
- }
- foreach($row as $ckey=>$col) {
- if ($ckey > $maxc) {
- $maxc = $ckey;
- }
- }
- }
-
- foreach($ws->columns as $ckey=>$col) {
- if ($ckey > $maxc) {
- $maxc = $ckey;
- }
- }
-
// define column properties
- for($c=0; $c<=$maxc; $c++) {
+ for($c=0; $c<=$ws->maxc; $c++) {
if (!empty($ws->columns[$c])) {
- $buffer .= ''."\n";
+ $buffer .= ''."\n";
} else {
$buffer .= ''."\n";
}
}
// print all rows
- for($r=0; $r<=$maxr; $r++) {
+ for($r=0; $r<=$ws->maxr; $r++) {
$buffer .= ''."\n";
- for($c=0; $c<=$maxc; $c++) {
+ for($c=0; $c<=$ws->maxc; $c++) {
if (isset($ws->data[$r][$c])) {
if ($ws->data[$r][$c]->type == 'date') {
$buffer .= ''