Merge branch 'w51_MDL-35356_m25_excel' of git://github.com/skodak/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 8 Jan 2013 22:11:54 +0000 (23:11 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 8 Jan 2013 22:11:54 +0000 (23:11 +0100)
Conflicts:
lib/odslib.class.php

1  2 
lib/odslib.class.php
lib/thirdpartylibs.xml

@@@ -595,275 -901,611 +901,611 @@@ class MoodleODSWriter 
                      }
                  }
              }
-         }
  
-         foreach($ws->rows as $rnum=>$row) {
-             if (!empty($row->format)) {
-                 if (!array_key_exists($row->format->id, $formats)) {
-                     $formats[$row->format->id] = $row->format;
+             foreach($ws->rows as $rnum=>$row) {
+                 if (!empty($row->format)) {
+                     if (!array_key_exists($row->format->id, $formats)) {
+                         $formats[$row->format->id] = $row->format;
+                     }
                  }
-             }
-             if ($rnum > $worksheets[$wsnum]->maxr) {
-                 $worksheets[$wsnum]->maxr = $rnum;
-             }
-             //define all column styles
-             if (!empty($ws->rows[$rnum])) {
-                 $rowstyles .= '
-   <style:style style:name="ws'.$wsnum.'ro'.$rnum.'" style:family="table-row">
-    <style:table-row-properties style:row-height="'.$row->height.'pt"/>
-   </style:style>';
-             }
-         }
-         foreach($ws->columns as $cnum=>$col) {
-             if (!empty($col->format)) {
-                 if (!array_key_exists($col->format->id, $formats)) {
-                     $formats[$col->format->id] = $col->format;
+                 if ($rnum > $this->worksheets[$wsnum]->maxr) {
+                     $this->worksheets[$wsnum]->maxr = $rnum;
+                 }
+                 // Define all column styles.
+                 if (!empty($ws->rows[$rnum])) {
+                     $rowstyles .= '<style:style style:name="ws'.$wsnum.'ro'.$rnum.'" style:family="table-row">';
+                     if (isset($row->height)) {
+                         $rowstyles .= '<style:table-row-properties style:row-height="'.$row->height.'pt"/>';
+                     }
+                     $rowstyles .= '</style:style>';
                  }
              }
-             if ($cnum > $worksheets[$wsnum]->maxc) {
-                 $worksheets[$wsnum]->maxc = $cnum;
-             }
-             //define all column styles
-             if (!empty($ws->columns[$cnum])) {
-                 $colstyles .= '
-   <style:style style:name="ws'.$wsnum.'co'.$cnum.'" style:family="table-column">
-    <style:table-column-properties style:column-width="'.$col->width.'pt"/>
-   </style:style>';
-             }
-         }
-     }
  
-     foreach($formats as $format) {
-         $textprop = '';
-         $cellprop = '';
-         $parprop  = '';
-         foreach($format->properties as $pname=>$pvalue) {
-             switch ($pname) {
-                 case 'bold':
-                     if (!empty($pvalue)) {
-                         $textprop .= ' fo:font-weight="bold"';
-                     }
-                     break;
-                 case 'italic':
-                     if (!empty($pvalue)) {
-                         $textprop .= ' fo:font-style="italic"';
-                     }
-                     break;
-                 case 'underline':
-                     if (!empty($pvalue)) {
-                         $textprop .= ' style:text-underline-color="font-color" style:text-underline-style="solid" style:text-underline-width="auto"';
+             foreach($ws->columns as $cnum=>$col) {
+                 if (!empty($col->format)) {
+                     if (!array_key_exists($col->format->id, $formats)) {
+                         $formats[$col->format->id] = $col->format;
                      }
-                     break;
-                 case 'strikeout':
-                     if (!empty($pvalue)) {
-                         $textprop .= ' style:text-line-through-style="solid"';
-                     }
-                     break;
-                 case 'color':
-                     if ($pvalue !== false) {
-                         $textprop .= ' fo:color="'.$pvalue.'"';
-                     }
-                     break;
-                 case 'bg_color':
-                     if ($pvalue !== false) {
-                         $cellprop .= ' fo:background-color="'.$pvalue.'"';
+                 }
+                 if ($cnum > $this->worksheets[$wsnum]->maxc) {
+                     $this->worksheets[$wsnum]->maxc = $cnum;
+                 }
+                 // Define all column styles.
+                 if (!empty($ws->columns[$cnum])) {
+                     $colstyles .= '<style:style style:name="ws'.$wsnum.'co'.$cnum.'" style:family="table-column">';
+                     if (isset($col->width)) {
+                         $colstyles .= '<style:table-column-properties style:column-width="'.$col->width.'pt"/>';
                      }
-                     break;
-                 case 'align':
-                     $parprop .= ' fo:text-align="'.$pvalue.'"';
-                     break;
-                 case 'v_align':
-                     $cellprop .= ' style:vertical-align="'.$pvalue.'"';
-                     break;
+                     $colstyles .= '</style:style>';
+                 }
              }
          }
-         if (!empty($textprop)) {
-             $textprop = '
+         foreach($formats as $format) {
+             $textprop = '';
+             $cellprop = '';
+             $parprop  = '';
+             $dataformat = '';
+             foreach($format->properties as $pname=>$pvalue) {
+                 switch ($pname) {
+                     case 'size':
+                         if (!empty($pvalue)) {
+                             $textprop .= ' fo:font-size="'.$pvalue.'pt"';
+                         }
+                         break;
+                     case 'bold':
+                         if (!empty($pvalue)) {
+                             $textprop .= ' fo:font-weight="bold"';
+                         }
+                         break;
+                     case 'italic':
+                         if (!empty($pvalue)) {
+                             $textprop .= ' fo:font-style="italic"';
+                         }
+                         break;
+                     case 'underline':
+                         if (!empty($pvalue)) {
+                             $textprop .= ' style:text-underline-color="font-color" style:text-underline-style="solid" style:text-underline-width="auto"';
+                             if ($pvalue == 2) {
+                                 $textprop .= ' style:text-underline-type="double"';
+                             }
+                         }
+                         break;
+                     case 'strikeout':
+                         if (!empty($pvalue)) {
+                             $textprop .= ' style:text-line-through-style="solid"';
+                         }
+                         break;
+                     case 'color':
+                         if ($pvalue !== false) {
+                             $textprop .= ' fo:color="'.$pvalue.'"';
+                         }
+                         break;
+                     case 'bg_color':
+                         if ($pvalue !== false) {
+                             $cellprop .= ' fo:background-color="'.$pvalue.'"';
+                         }
+                         break;
+                     case 'align':
+                         $parprop .= ' fo:text-align="'.$pvalue.'"';
+                         break;
+                     case 'v_align':
+                         $cellprop .= ' style:vertical-align="'.$pvalue.'"';
+                         break;
+                     case 'wrap':
+                         if ($pvalue) {
+                             $cellprop .= ' fo:wrap-option="wrap"';
+                         }
+                         break;
+                     case 'border_top':
+                         $cellprop .= ' fo:border-top="'.$pvalue.'pt solid #000000"';
+                         break;
+                     case 'border_left':
+                         $cellprop .= ' fo:border-left="'.$pvalue.'pt solid #000000"';
+                         break;
+                     case 'border_bottom':
+                         $cellprop .= ' fo:border-bottom="'.$pvalue.'pt solid #000000"';
+                         break;
+                     case 'border_right':
+                         $cellprop .= ' fo:border-right="'.$pvalue.'pt solid #000000"';
+                         break;
+                     case 'num_format':
+                         $dataformat = ' style:data-style-name="NUM'.$pvalue.'"';
+                         break;
+                 }
+             }
+             if (!empty($textprop)) {
+                 $textprop = '
     <style:text-properties'.$textprop.'/>';
-         }
+             }
  
-         if (!empty($cellprop)) {
-             $cellprop = '
+             if (!empty($cellprop)) {
+                 $cellprop = '
     <style:table-cell-properties'.$cellprop.'/>';
-         }
+             }
  
-         if (!empty($parprop)) {
-             $parprop = '
+             if (!empty($parprop)) {
+                 $parprop = '
     <style:paragraph-properties'.$parprop.'/>';
-         }
+             }
  
-         $formatstyles .= '
-   <style:style style:name="format'.$format->id.'" style:family="table-cell">'.$textprop.$cellprop.$parprop.'
+             $formatstyles .= '
+   <style:style style:name="format'.$format->id.'" style:family="table-cell"'.$dataformat.'>'.$textprop.$cellprop.$parprop.'
    </style:style>';
-     }
+         }
  
- /// header
-     $buffer =
'<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
-  <office:automatic-styles>
-   <style:style style:name="ta1" style:family="table" style:master-page-name="Standard1">
-    <style:table-properties table:display="true"/>
+         // The text styles may be breaking older ODF validators.
+         $scriptstyles ='
  <style:style style:name="T1" style:family="text">
    <style:text-properties style:text-position="33% 58%"/>
+   </style:style>
+   <style:style style:name="T2" style:family="text">
+     <style:text-properties style:text-position="-33% 58%"/>
    </style:style>
-   <style:style style:name="date0" style:family="table-cell"/>';
- $buffer .= $formatstyles;
- $buffer .= $rowstyles;
- $buffer .= $colstyles;
-  $buffer .= '
-  </office:automatic-styles>
-  <office:body>
-   <office:spreadsheet>
+ ';
+         // Header.
+         $buffer =
+ '<?xml version="1.0" encoding="UTF-8"?>
+ <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
+                          xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
+                          xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
+                          xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
+                          xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
+                          xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
+                          xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
+                          xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
+                          xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
+                          xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
+                          xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
+                          xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
+                          xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
+                          xmlns:math="http://www.w3.org/1998/Math/MathML"
+                          xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
+                          xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
+                          xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
+                          xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
+                          xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                          xmlns:rpt="http://openoffice.org/2005/report"
+                          xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
+                          xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
+                          xmlns:tableooo="http://openoffice.org/2009/table"
+                          xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
+                          xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
+                          xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
+                          xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
+   <office:scripts/>
+   <office:font-face-decls>
+     <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss"
+                      style:font-pitch="variable"/>
+     <style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;"
+                      style:font-family-generic="system" style:font-pitch="variable"/>
+     <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system"
+                      style:font-pitch="variable"/>
+   </office:font-face-decls>
+   <office:automatic-styles>';
+         $buffer .= $this->get_num_styles();
+         $buffer .= '
+     <style:style style:name="ta1" style:family="table" style:master-page-name="Standard1">
+       <style:table-properties table:display="true"/>
+     </style:style>';
+         $buffer .= $formatstyles;
+         $buffer .= $rowstyles;
+         $buffer .= $colstyles;
+         $buffer .= $scriptstyles;
+          $buffer .= '
+   </office:automatic-styles>
+   <office:body>
+     <office:spreadsheet>
  ';
  
-     foreach($worksheets as $wsnum=>$ws) {
+         foreach($this->worksheets as $wsnum=>$ws) {
  
-     /// worksheet header
-         $buffer .= '<table:table table:name="' . htmlspecialchars($ws->name) . '" table:style-name="ta1">'."\n";
+             // Worksheet header.
+             $buffer .= '<table:table table:name="' . htmlspecialchars($ws->name, ENT_QUOTES, 'utf-8') . '" table:style-name="ta1">'."\n";
  
-         // define column properties
-         for($c=0; $c<=$ws->maxc; $c++) {
-             if (array_key_exists($c, $ws->columns)) {
-                 $extra = '';
-                 if (!empty($ws->columns[$c]->format)) {
-                     $extra .= ' table:default-cell-style-name="format'.$ws->columns[$c]->format->id.'"';
-                 }
-                 if ($ws->columns[$c]->hidden) {
-                     $extra .= ' table:visibility="collapse"';
+             // Define column properties.
+             $level = 0;
+             for($c=0; $c<=$ws->maxc; $c++) {
+                 if (array_key_exists($c, $ws->columns)) {
+                     $column = $ws->columns[$c];
+                     if ($column->level > $level) {
+                         while ($column->level > $level) {
+                             $buffer .= '<table:table-column-group>';
+                             $level++;
+                         }
+                     } else if ($column->level < $level) {
+                         while ($column->level < $level) {
+                             $buffer .= '</table:table-column-group>';
+                             $level--;
+                         }
+                     }
+                     $extra = '';
+                     if (!empty($column->format)) {
+                         $extra .= ' table:default-cell-style-name="format'.$column->format->id.'"';
+                     }
+                     if ($column->hidden) {
+                         $extra .= ' table:visibility="collapse"';
+                     }
+                     $buffer .= '<table:table-column table:style-name="ws'.$wsnum.'co'.$c.'"'.$extra.'/>'."\n";
+                 } else {
+                     while ($level > 0) {
+                         $buffer .= '</table:table-column-group>';
+                         $level--;
+                     }
+                     $buffer .= '<table:table-column/>'."\n";
                  }
-                 $buffer .= '<table:table-column table:style-name="ws'.$wsnum.'co'.$c.'"'.$extra.'/>'."\n";
-             } else {
-                 $buffer .= '<table:table-column/>'."\n";
              }
-         }
-         // print all rows
-         for($r=0; $r<=$ws->maxr; $r++) {
-             if (array_key_exists($r, $ws->rows)) {
-                 $extra = '';
-                 if (!empty($ws->rows[$r]->format)) {
-                     $extra .= ' table:default-cell-style-name="format'.$ws->rows[$r]->format->id.'"';
-                 }
-                 if ($ws->rows[$r]->hidden) {
-                     $extra .= ' table:visibility="collapse"';
-                 }
-                 $buffer .= '<table:table-row table:style-name="ws'.$wsnum.'ro'.$r.'"'.$extra.'>'."\n";
-             } else {
-                 $buffer .= '<table:table-row>'."\n";
+             while ($level > 0) {
+                 $buffer .= '</table:table-column-group>';
+                 $level--;
              }
-             for($c=0; $c<=$ws->maxc; $c++) {
-                 if (isset($ws->data[$r][$c])) {
-                     $cell = $ws->data[$r][$c];
-                     $extra = ' ';
-                     if (!empty($cell->format)) {
-                         $extra = ' table:style-name="format'.$cell->format->id.'"';
+             // Print all rows.
+             $level = 0;
+             for($r=0; $r<=$ws->maxr; $r++) {
+                 if (array_key_exists($r, $ws->rows)) {
+                     $row = $ws->rows[$r];
+                     if ($row->level > $level) {
+                         while ($row->level > $level) {
+                             $buffer .= '<table:table-row-group>';
+                             $level++;
+                         }
+                     } else if ($row->level < $level) {
+                         while ($row->level < $level) {
+                             $buffer .= '</table:table-row-group>';
+                             $level--;
+                         }
                      }
-                     if ($cell->type == 'date') {
-                         $buffer .= '<table:table-cell office:value-type="date" table:style-name="date0" office:date-value="' . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . '"'.$extra.'>'
-                                  . '<text:p>' . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . '</text:p>'
-                                  . '</table:table-cell>'."\n";
-                     } else if ($cell->type == 'float') {
-                         $buffer .= '<table:table-cell office:value-type="float" office:value="' . htmlspecialchars($cell->value) . '"'.$extra.'>'
-                                  . '<text:p>' . htmlspecialchars($cell->value) . '</text:p>'
-                                  . '</table:table-cell>'."\n";
-                     } else if ($cell->type == 'string') {
-                         $buffer .= '<table:table-cell office:value-type="string" office:string-value="' . htmlspecialchars($cell->value) . '"'.$extra.'>'
-                                  . '<text:p>' . htmlspecialchars($cell->value) . '</text:p>'
-                                  . '</table:table-cell>'."\n";
-                     } else {
-                         $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
-                                  . '<text:p>!!Error - unknown type!!</text:p>'
-                                  . '</table:table-cell>'."\n";
+                     $extra = '';
+                     if (!empty($row->format)) {
+                         $extra .= ' table:default-cell-style-name="format'.$row->format->id.'"';
+                     }
+                     if ($row->hidden) {
+                         $extra .= ' table:visibility="collapse"';
                      }
+                     $buffer .= '<table:table-row table:style-name="ws'.$wsnum.'ro'.$r.'"'.$extra.'>'."\n";
                  } else {
-                     $buffer .= '<table:table-cell/>'."\n";
+                     while ($level > 0) {
+                         $buffer .= '</table:table-row-group>';
+                         $level--;
+                     }
+                     $buffer .= '<table:table-row>'."\n";
                  }
+                 for($c=0; $c<=$ws->maxc; $c++) {
+                     if (isset($ws->data[$r][$c])) {
+                         $cell = $ws->data[$r][$c];
+                         $extra = '';
+                         if (!empty($cell->format)) {
+                             $extra .= ' table:style-name="format'.$cell->format->id.'"';
+                         }
+                         if (!empty($cell->merge)) {
+                             $extra .= ' table:number-columns-spanned="'.$cell->merge['columns'].'" table:number-rows-spanned="'.$cell->merge['rows'].'"';
+                         }
+                         $pretext = '<text:p>';
+                         $posttext = '</text:p>';
+                         if (!empty($cell->format->properties['sub_script'])) {
+                             $pretext = $pretext.'<text:span text:style-name="T2">';
+                             $posttext = '</text:span>'.$posttext;
+                         } else if (!empty($cell->format->properties['super_script'])) {
+                             $pretext = $pretext.'<text:span text:style-name="T1">';
+                             $posttext = '</text:span>'.$posttext;
+                         }
+                         if (isset($cell->formula)) {
+                             $buffer .= '<table:table-cell table:formula="of:'.$cell->formula.'"'.$extra.'></table:table-cell>'."\n";
+                         } else if ($cell->type == 'date') {
+                             $buffer .= '<table:table-cell office:value-type="date" office:date-value="' . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . '"'.$extra.'>'
+                                      . $pretext . strftime('%Y-%m-%dT%H:%M:%S', $cell->value) . $posttext
+                                      . '</table:table-cell>'."\n";
+                         } else if ($cell->type == 'float') {
+                             $buffer .= '<table:table-cell office:value-type="float" office:value="' . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . '"'.$extra.'>'
+                                      . $pretext . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . $posttext
+                                      . '</table:table-cell>'."\n";
+                         } else if ($cell->type == 'string') {
+                             $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
+                                      . $pretext . htmlspecialchars($cell->value, ENT_QUOTES, 'utf-8') . $posttext
+                                      . '</table:table-cell>'."\n";
+                         } else {
+                             $buffer .= '<table:table-cell office:value-type="string"'.$extra.'>'
+                                      . $pretext . '!!Error - unknown type!!' . $posttext
+                                      . '</table:table-cell>'."\n";
+                         }
+                     } else {
+                         $buffer .= '<table:table-cell/>'."\n";
+                     }
+                 }
+                 $buffer .= '</table:table-row>'."\n";
              }
-             $buffer .= '</table:table-row>'."\n";
-         }
-     /// worksheet footer
-         $buffer .= '</table:table>'."\n";
+             while ($level > 0) {
+                 $buffer .= '</table:table-row-group>';
+                 $level--;
+             }
+             $buffer .= '</table:table>'."\n";
  
-     }
+         }
  
- /// footer
-     $buffer .=
'  </office:spreadsheet>
-  </office:body>
+         // Footer.
+         $buffer .= '
    </office:spreadsheet>
+   </office:body>
  </office:document-content>';
  
-     return $buffer;
- }
+         return $buffer;
    }
  
- function get_ods_mimetype() {
-     return 'application/vnd.oasis.opendocument.spreadsheet';
- }
    public function get_ods_mimetype() {
+         return 'application/vnd.oasis.opendocument.spreadsheet';
    }
  
- function get_ods_meta() {
-     global $CFG, $USER;
+     protected function get_ods_settings() {
+         $buffer =
+ '<?xml version="1.0" encoding="UTF-8"?>
+ <office:document-settings xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
+                           xmlns:xlink="http://www.w3.org/1999/xlink"
+                           xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
+                           xmlns:ooo="http://openoffice.org/2004/office" office:version="1.2">
+     <office:settings>
+       <config:config-item-set config:name="ooo:view-settings">
+         <config:config-item config:name="VisibleAreaTop" config:type="int">0</config:config-item>
+         <config:config-item config:name="VisibleAreaLeft" config:type="int">0</config:config-item>
+         <config:config-item-map-indexed config:name="Views">
+           <config:config-item-map-entry>
+             <config:config-item config:name="ViewId" config:type="string">view1</config:config-item>
+             <config:config-item-map-named config:name="Tables">
+ ';
+         foreach ($this->worksheets as $ws) {
+             $buffer .= '               <config:config-item-map-entry config:name="'.htmlspecialchars($ws->name, ENT_QUOTES, 'utf-8').'">'."\n";
+             $buffer .= '                 <config:config-item config:name="ShowGrid" config:type="boolean">'.($ws->showgrid ? 'true' : 'false').'</config:config-item>'."\n";
+             $buffer .= '               </config:config-item-map-entry>."\n"';
+         }
+             $buffer .=
+ '           </config:config-item-map-named>
+           </config:config-item-map-entry>
+         </config:config-item-map-indexed>
+       </config:config-item-set>
+       <config:config-item-set config:name="ooo:configuration-settings">
+         <config:config-item config:name="ShowGrid" config:type="boolean">true</config:config-item>
+       </config:config-item-set>
+     </office:settings>
+ </office:document-settings>';
+         return $buffer;
+     }
+     protected function get_ods_meta() {
+         global $CFG, $USER;
  
-     return
+         return
  '<?xml version="1.0" encoding="UTF-8"?>
- <office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
-  <office:meta>
-   <meta:generator>Moodle '.$CFG->version.'</meta:generator>
-   <meta:initial-creator>'.fullname($USER, true).'</meta:initial-creator>
-   <meta:editing-cycles>1</meta:editing-cycles>
-   <meta:creation-date>'.strftime('%Y-%m-%dT%H:%M:%S').'</meta:creation-date>
-   <dc:date>'.strftime('%Y-%m-%dT%H:%M:%S').'</dc:date>
-   <dc:creator>'.fullname($USER, true).'</dc:creator>
-  </office:meta>
+ <office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
+                       xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
+                       xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
+                       xmlns:ooo="http://openoffice.org/2004/office" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
+                       office:version="1.2">
+     <office:meta>
+         <meta:generator>Moodle '.$CFG->release.'</meta:generator>
+         <meta:initial-creator>'.fullname($USER, true).'</meta:initial-creator>
+         <meta:creation-date>'.strftime('%Y-%m-%dT%H:%M:%S').'</meta:creation-date>
+         <meta:document-statistic meta:table-count="1" meta:cell-count="0" meta:object-count="0"/>
+     </office:meta>
  </office:document-meta>';
- }
    }
  
- function get_ods_styles() {
-     return
    protected function get_ods_styles() {
+         return
  '<?xml version="1.0" encoding="UTF-8"?>
- <office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xlink="http://www.w3.org/1999/xlink">
-  <office:styles>
-   <style:default-style style:family="table-column">
-    <style:table-column-properties style:column-width="75pt"/>
-   </style:default-style>
-   <style:default-style style:family="table-row">
-    <style:table-row-properties style:row-height="15pt"/>
-   </style:default-style>
-   <style:default-style style:family="table-cell">
-    <style:table-cell-properties fo:background-color="#ffffff" style:cell-protect="protected" style:vertical-align="middle"/>
-    <style:text-properties fo:color="#000000" fo:font-family="Arial" fo:font-size="12pt"/>
-   </style:default-style>
-  </office:styles>
-  <office:automatic-styles>
-   <style:page-layout style:name="pm1">
-    <style:page-layout-properties fo:margin-bottom="56.6930116pt" fo:margin-left="56.6930116pt" fo:margin-right="56.6930116pt" fo:margin-top="56.6930116pt" fo:page-height="841.89122226pt" fo:page-width="595.2766218pt" style:print="objects charts drawings zero-values" style:print-orientation="portrait"/>
-   </style:page-layout>
-  </office:automatic-styles>
-  <office:master-styles>
-   <style:master-page style:name="Standard1" style:page-layout-name="pm1">
-    <style:header>
-  <text:p>
-   <text:sheet-name>???</text:sheet-name>
-  </text:p>
- </style:header><style:footer>
-  <text:p>
-   <text:sheet-name>Page </text:sheet-name>
-   <text:page-number>1</text:page-number>
-  </text:p>
- </style:footer>
-   </style:master-page>
-  </office:master-styles>
- </office:document-styles>
- ';
- }
+ <office:document-styles xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
+                         xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
+                         xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
+                         xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
+                         xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
+                         xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
+                         xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
+                         xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
+                         xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
+                         xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
+                         xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
+                         xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
+                         xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
+                         xmlns:math="http://www.w3.org/1998/Math/MathML"
+                         xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
+                         xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
+                         xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
+                         xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
+                         xmlns:rpt="http://openoffice.org/2005/report"
+                         xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
+                         xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
+                         xmlns:tableooo="http://openoffice.org/2009/table"
+                         xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
+                         xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2">
+     <office:font-face-decls>
+         <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss"
+                          style:font-pitch="variable"/>
+         <style:font-face style:name="Arial Unicode MS" svg:font-family="&apos;Arial Unicode MS&apos;"
+                          style:font-family-generic="system" style:font-pitch="variable"/>
+         <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system"
+                          style:font-pitch="variable"/>
+     </office:font-face-decls>
+     <office:styles>
+         <style:default-style style:family="table-cell">
+             <style:paragraph-properties style:tab-stop-distance="1.25cm"/>
+         </style:default-style>
+         <number:number-style style:name="N0">
+             <number:number number:min-integer-digits="1"/>
+         </number:number-style>
+         <style:style style:name="Default" style:family="table-cell">
+             <style:text-properties style:font-name-asian="Arial Unicode MS" style:font-name-complex="Arial Unicode MS"/>
+         </style:style>
+         <style:style style:name="Result" style:family="table-cell" style:parent-style-name="Default">
+             <style:text-properties fo:font-style="italic" style:text-underline-style="solid"
+                                    style:text-underline-width="auto" style:text-underline-color="font-color"
+                                    fo:font-weight="bold"/>
+         </style:style>
+         <style:style style:name="Result2" style:family="table-cell" style:parent-style-name="Result"
+                      style:data-style-name="N104"/>
+         <style:style style:name="Heading" style:family="table-cell" style:parent-style-name="Default">
+             <style:table-cell-properties style:text-align-source="fix" style:repeat-content="false"/>
+             <style:paragraph-properties fo:text-align="center"/>
+             <style:text-properties fo:font-size="16pt" fo:font-style="italic" fo:font-weight="bold"/>
+         </style:style>
+         <style:style style:name="Heading1" style:family="table-cell" style:parent-style-name="Heading">
+             <style:table-cell-properties style:rotation-angle="90"/>
+         </style:style>
+     </office:styles>
+     <office:automatic-styles>
+         <style:page-layout style:name="Mpm1">
+             <style:page-layout-properties style:writing-mode="lr-tb"/>
+             <style:header-style>
+                 <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
+                                                 fo:margin-bottom="0.25cm"/>
+             </style:header-style>
+             <style:footer-style>
+                 <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
+                                                 fo:margin-top="0.25cm"/>
+             </style:footer-style>
+         </style:page-layout>
+         <style:page-layout style:name="Mpm2">
+             <style:page-layout-properties style:writing-mode="lr-tb"/>
+             <style:header-style>
+                 <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
+                                                 fo:margin-bottom="0.25cm" fo:border="2.49pt solid #000000"
+                                                 fo:padding="0.018cm" fo:background-color="#c0c0c0">
+                     <style:background-image/>
+                 </style:header-footer-properties>
+             </style:header-style>
+             <style:footer-style>
+                 <style:header-footer-properties fo:min-height="0.75cm" fo:margin-left="0cm" fo:margin-right="0cm"
+                                                 fo:margin-top="0.25cm" fo:border="2.49pt solid #000000"
+                                                 fo:padding="0.018cm" fo:background-color="#c0c0c0">
+                     <style:background-image/>
+                 </style:header-footer-properties>
+             </style:footer-style>
+         </style:page-layout>
+     </office:automatic-styles>
+     <office:master-styles>
+         <style:master-page style:name="Default" style:page-layout-name="Mpm1">
+             <style:header>
+                 <text:p>
+                     <text:sheet-name>???</text:sheet-name>
+                 </text:p>
+             </style:header>
+             <style:header-left style:display="false"/>
+             <style:footer>
+                 <text:p>Page
+                     <text:page-number>1</text:page-number>
+                 </text:p>
+             </style:footer>
+             <style:footer-left style:display="false"/>
+         </style:master-page>
+         <style:master-page style:name="Report" style:page-layout-name="Mpm2">
+             <style:header>
+                 <style:region-left>
+                     <text:p>
+                         <text:sheet-name>???</text:sheet-name>
+                         (<text:title>???</text:title>)
+                     </text:p>
+                 </style:region-left>
+                 <style:region-right>
+                     <text:p><text:date style:data-style-name="N2" text:date-value="2013-01-05">00.00.0000</text:date>,
+                         <text:time>00:00:00</text:time>
+                     </text:p>
+                 </style:region-right>
+             </style:header>
+             <style:header-left style:display="false"/>
+             <style:footer>
+                 <text:p>Page
+                     <text:page-number>1</text:page-number>
+                     /
+                     <text:page-count>99</text:page-count>
+                 </text:p>
+             </style:footer>
+             <style:footer-left style:display="false"/>
+         </style:master-page>
+     </office:master-styles>
+ </office:document-styles>';
+     }
  
- function get_ods_manifest() {
-     return
    protected function get_ods_manifest() {
+         return
  '<?xml version="1.0" encoding="UTF-8"?>
- <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
-  <manifest:file-entry manifest:media-type="application/vnd.oasis.opendocument.spreadsheet" manifest:full-path="/"/>
-  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="content.xml"/>
-  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="styles.xml"/>
-  <manifest:file-entry manifest:media-type="text/xml" manifest:full-path="meta.xml"/>
+ <manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">
+  <manifest:file-entry manifest:full-path="/" manifest:version="1.2" manifest:media-type="application/vnd.oasis.opendocument.spreadsheet"/>
+  <manifest:file-entry manifest:full-path="meta.xml" manifest:media-type="text/xml"/>
+  <manifest:file-entry manifest:full-path="content.xml" manifest:media-type="text/xml"/>
+  <manifest:file-entry manifest:full-path="styles.xml" manifest:media-type="text/xml"/>
+  <manifest:file-entry manifest:full-path="settings.xml" manifest:media-type="text/xml"/>
  </manifest:manifest>';
 -}
+     }
+     protected function get_num_styles() {
+         return '
+         <number:number-style style:name="NUM1">
+             <number:number number:decimal-places="0" number:min-integer-digits="1"/>
+         </number:number-style>
+         <number:number-style style:name="NUM2">
+             <number:number number:decimal-places="2" number:min-integer-digits="1"/>
+         </number:number-style>
+         <number:number-style style:name="NUM3">
+             <number:number number:decimal-places="0" number:min-integer-digits="1" number:grouping="true"/>
+         </number:number-style>
+         <number:number-style style:name="NUM4">
+             <number:number number:decimal-places="2" number:min-integer-digits="1" number:grouping="true"/>
+         </number:number-style>
+         <number:number-style style:name="NUM11">
+             <number:scientific-number number:decimal-places="2" number:min-integer-digits="1"
+                                       number:min-exponent-digits="2"/>
+         </number:number-style>
+         <number:number-style style:name="NUM12">
+             <number:fraction number:min-integer-digits="0" number:min-numerator-digits="1"
+                              number:min-denominator-digits="1"/>
+         </number:number-style>
+         <number:number-style style:name="NUM13">
+             <number:fraction number:min-integer-digits="0" number:min-numerator-digits="2"
+                              number:min-denominator-digits="2"/>
+         </number:number-style>
+         <number:date-style style:name="NUM14" number:automatic-order="true">
+             <number:month number:style="long"/>
+             <number:text>/</number:text>
+             <number:day number:style="long"/>
+             <number:text>/</number:text>
+             <number:year/>
+         </number:date-style>
+         <number:date-style style:name="NUM15">
+             <number:day/>
+             <number:text>.</number:text>
+             <number:month number:textual="true"/>
+             <number:text>.</number:text>
+             <number:year number:style="long"/>
+         </number:date-style>
+         <number:date-style style:name="NUM16" number:automatic-order="true">
+             <number:month number:textual="true"/>
+             <number:text></number:text>
+             <number:day number:style="long"/>
+         </number:date-style>
+         <number:date-style style:name="NUM17">
+             <number:month number:style="long"/>
+             <number:text>-</number:text>
+             <number:day number:style="long"/>
+         </number:date-style>
+         <number:date-style style:name="NUM22" number:automatic-order="true"
+                            number:format-source="language">
+             <number:month/>
+             <number:text>/</number:text>
+             <number:day/>
+             <number:text>/</number:text>
+             <number:year/>
+             <number:text></number:text>
+             <number:hours number:style="long"/>
+             <number:text>:</number:text>
+             <number:minutes number:style="long"/>
+             <number:text></number:text>
+             <number:am-pm/>
+         </number:date-style>
+         <number:text-style style:name="NUM49">
+             <number:text-content/>
+         </number:text-style>
+ ';
+     }
 +}
Simple merge