From 25ea2ad6c35b800444dae98f10b87f248d91302e Mon Sep 17 00:00:00 2001 From: skodak Date: Fri, 22 Dec 2006 10:26:34 +0000 Subject: [PATCH] MDL-7996 Add ods export support - column width fixed --- lib/odslib.class.php | 74 ++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/lib/odslib.class.php b/lib/odslib.class.php index 5ddfd0f15d..e6c87e2c65 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 .= '' -- 2.39.5