浏览代码

excel update with example

euromark 13 年之前
父节点
当前提交
d2cf4ff20d

+ 19 - 3
Vendor/SpreadsheetExcelReader/SpreadsheetExcelReader.php

@@ -90,7 +90,7 @@ class OLERead {
 	// http://uk.php.net/manual/en/function.getdate.php
 	public static function gmgetdate($ts = null) {
 		$k = array('seconds', 'minutes', 'hours', 'mday', 'wday', 'mon', 'year', 'yday', 'weekday', 'month',0);
-		return(array_combine($k, split(':', gmdate('s:i:G:j:w:n:Y:z:l:F:U', is_null($ts)?time():$ts))));
+		return(array_combine($k, explode(':', gmdate('s:i:G:j:w:n:Y:z:l:F:U', is_null($ts)?time():$ts))));
 	}
 
 	public static function v($data, $pos) {
@@ -851,7 +851,7 @@ class SpreadsheetExcelReader {
 
 		// Custom pattern can be POSITIVE;NEGATIVE;ZERO
 		// The "text" option as 4th parameter is not handled
-		$parts = split(";", $format);
+		$parts = explode(";", $format);
 		$pattern = $parts[0];
 		// Negative pattern
 		if (count($parts)>2 && $num==0) {
@@ -997,6 +997,22 @@ class SpreadsheetExcelReader {
 		$this->_parse();
 	}
 
+	public function readFromBlob($data) {
+		$res = $this->_ole->readFromBlob($data);
+
+		// oops, something goes wrong (Darko Miljanovic)
+		if ($res === false) {
+			// check error code
+			if ($this->_ole->error == 1) {
+				// bad file
+				die('The filename ' . $sFileName . ' is not readable');
+			}
+			// check other error codes here (eg bad fileformat, etc...)
+		}
+		$this->data = $this->_ole->getWorkBook();
+		$this->_parse();
+	}
+
 	/**
 	 * Parse a workbook
 	 *
@@ -1618,7 +1634,7 @@ class SpreadsheetExcelReader {
 			// Convert numeric $this->_value into a date
 			$utcDays = floor($numValue - ($this->nineteenFour ? SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS1904 : SPREADSHEET_EXCEL_READER_UTCOFFSETDAYS));
 			$utcValue = ($utcDays) * SPREADSHEET_EXCEL_READER_MSINADAY;
-			$dateinfo = gmgetdate($utcValue);
+			$dateinfo = OLERead::gmgetdate($utcValue);
 
 			$raw = $numValue;
 			$fractionalDay = $numValue - floor($numValue) + .0000001; // The .0000001 is to fix for php/excel fractional diffs

+ 56 - 0
Vendor/SpreadsheetExcelReader/example.php

@@ -0,0 +1,56 @@
+<?php
+error_reporting(E_ALL ^ E_NOTICE);
+require_once 'SpreadsheetExcelReader.php';
+$reader = new SpreadsheetExcelReader("example.xls");
+
+// or
+$reader = new SpreadsheetExcelReader();
+$fileContent = file_get_contents("example.xls");
+$reader->readFromBlob($fileContent);
+?>
+<html>
+<head>
+<style>
+table.excel {
+	border-style:ridge;
+	border-width:1;
+	border-collapse:collapse;
+	font-family:sans-serif;
+	font-size:12px;
+}
+table.excel thead th, table.excel tbody th {
+	background:#CCCCCC;
+	border-style:ridge;
+	border-width:1;
+	text-align: center;
+	vertical-align:bottom;
+}
+table.excel tbody th {
+	text-align:center;
+	width:20px;
+}
+table.excel tbody td {
+	vertical-align:bottom;
+}
+table.excel tbody td {
+	padding: 0 3px;
+	border: 1px solid #EEEEEE;
+}
+</style>
+</head>
+
+<body>
+<table class="excel">
+<?php
+	$table = $reader->dumpToArray();
+	foreach ($table as $row) {
+		echo '<tr>';
+		foreach ($row as $field) {
+			echo '<td>' . $field . '</td>';
+		}
+		echo '</tr>';
+	}
+?>
+</table>
+</body>
+</html>

二进制
Vendor/SpreadsheetExcelReader/example.xls