ソースを参照

+ ss:Type Number for fields double in exportXLS

Piotr Labudda 5 年 前
コミット
8a57eaa468
1 ファイル変更26 行追加3 行削除
  1. 26 3
      SE/se-lib/Route/ExportTableAjax.php

+ 26 - 3
SE/se-lib/Route/ExportTableAjax.php

@@ -150,6 +150,14 @@ class Route_ExportTableAjax extends RouteBase {
 	}
 	function _exportToXLS($acl, $items, $toExportFields, $format = 'xls') {
 		// https://en.wikipedia.org/wiki/Microsoft_Excel#XML_Spreadsheet
+
+		$DBG_OUTPUT = 0;
+		if ($DBG_OUTPUT) {
+			$items = array_slice($items, 0, 10);
+			DBG::nicePrint($acl, '$acl');
+		}
+
+
 		$csvFileName = "Tabela-" . $acl->getName() . "-" . date("Y-m-d_H_s");
 		$labels = array();
 		foreach ($toExportFields as $fieldName) {
@@ -157,6 +165,7 @@ class Route_ExportTableAjax extends RouteBase {
 		}
 		$xw = new XMLWriter();
 		$xw->openMemory();
+		if ($DBG_OUTPUT) $xw->setIndent(true); //set the indentation to true (if false all the xml will be written on one line)
 		$xw->startDocument("1.0");
 		$xw->startElement("Workbook");
 		$xw->writeAttribute("xmlns", "urn:schemas-microsoft-com:office:spreadsheet");
@@ -192,7 +201,19 @@ class Route_ExportTableAjax extends RouteBase {
 							$xw->startElement('Cell');
 							{
 								$xw->startElement('Data');
-								$xw->writeAttribute("ss:Type", "String");
+								$xsdType = $acl->getXsdFieldType($fieldName);
+								switch ($xsdType) {
+									case 'xsd:double':
+									{
+										if (!empty($item[$fieldName])) {
+											$xw->writeAttribute("ss:Type", "Number");
+										} else {
+											$xw->writeAttribute("ss:Type", "String");
+										}
+										break;
+									}
+									default: $xw->writeAttribute("ss:Type", "String");
+								}
 								$xw->text($item[$fieldName]);
 								$xw->endElement();
 							}
@@ -208,8 +229,10 @@ class Route_ExportTableAjax extends RouteBase {
 		$xw->endElement();
 		$xw->endDocument();
 
-		header("Content-Type: text/xml; charset=utf-8");
-		header("Content-Disposition: attachment; filename={$csvFileName}.xls");
+		if (!$DBG_OUTPUT) {
+			header("Content-Type: text/xml; charset=utf-8");
+			header("Content-Disposition: attachment; filename={$csvFileName}.xls");
+		}
 		echo $xw->outputMemory();
 	}
 	function _exportToXLSX($acl, $items, $toExportFields, $format = 'xlsx') {