diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 971afb8..4561611 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -1,7 +1,5 @@ fields[$name]); + return Tools_String::strToArray($this->fields[$name]); } function getRecordCount() { diff --git a/src/Excel/DataTime.php b/src/Excel/DataTime.php new file mode 100644 index 0000000..0536cbd --- /dev/null +++ b/src/Excel/DataTime.php @@ -0,0 +1,16 @@ +value = intval($value); + } + + function getString() + { + return date('Y-m-d\TH:i:s.u', $this->value); + } +} diff --git a/src/Excel/Document.php b/src/Excel/Document.php new file mode 100644 index 0000000..e46ff31 --- /dev/null +++ b/src/Excel/Document.php @@ -0,0 +1,100 @@ +table [] = $table; + } + + /** + * Добавление стиля к документу + * @param $name string Имя стиля + * @param $values array Параметры стиля + * @param $type Тип стиля + */ + function setStyle ($name, array $values, $type = 'Interior') + { + if(!isset($this->styles[$name])) { + $this->styles[$name] = array(); + } + $this->styles[$name][$type] = $values; + } + + /** + * Генерация стилей + */ + private function createStyles (XMLWriter $doc) { + $doc->startElement('Styles'); + foreach ($this->styles as $name => $sn) { + $doc->startElement('Style'); + $doc->writeAttribute('ss:ID', $name); + foreach ($sn as $type => $s) { + // Стиль Borders - составной + if ($type == 'Borders') { + $doc->startElement('Borders'); + foreach ($s as $border) { + /*.array.*/$border = $border; + $doc->startElement('Border'); + foreach ($border as $key => $value) { + $doc->writeAttribute('ss:' . $key, $value); + } + $doc->endElement(); + } + $doc->endElement(); + } else { + $doc->startElement($type); + foreach ($s as $key => $value) { + $doc->writeAttribute('ss:' . $key, $value); + } + $doc->endElement(); + } + } + $doc->endElement(); + } + $doc->endElement(); + } + + /** + * Преобразует переводы строки в спец символы + */ + function clean ($s) { + assert(is_string($s)); + + return strtr($s, array ("\n" => " ")); + } + + /** + * Сохраняет таблицу в формате Office 2003 XML + * http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats + */ + function save($filename) + { + $doc = new XMLWriter(); + $doc->openURI($filename); + $doc->setIndent(false); + $doc->startDocument('1.0','utf-8'); + $doc->startElement('Workbook'); + $doc->writeAttribute('xmlns', self::$ns); + $doc->writeAttribute('xmlns:ss', self::$ns); + + $this->createStyles($doc); + + foreach ($this->table as $table) { + if ($table instanceof Excel_Table) { + $table->createTable($doc); + } else { + $table_data = call_user_func($table); + $table_data->createTable($doc); + unset($table_data); + } + } + $doc->endElement(); + } +} + diff --git a/src/Excel/Number.php b/src/Excel/Number.php new file mode 100644 index 0000000..66dd6b6 --- /dev/null +++ b/src/Excel/Number.php @@ -0,0 +1,17 @@ +value = intval($value); + } + + function getString() + { + return $this->value; + } +} + diff --git a/src/Tools/ExcelTable.php b/src/Excel/Table.php similarity index 71% rename from src/Tools/ExcelTable.php rename to src/Excel/Table.php index bc7ea38..162c823 100644 --- a/src/Tools/ExcelTable.php +++ b/src/Excel/Table.php @@ -1,35 +1,5 @@ value = intval($value); - } - - function getString() - { - return $this->value; - } -} - -class Excel_DateTime -{ - public $value; - - function __construct($value) - { - $this->value = intval($value); - } - - function getString() - { - return date('Y-m-d\TH:i:s.u', $this->value); - } -} - /** * Клетка таблицы */ @@ -68,7 +38,7 @@ class TableRow /** * Таблица */ -class ExcelTable +class Excel_Table { static $index; private $name; @@ -339,101 +309,3 @@ class ExcelTable } } -/** - * Документ - */ -class ExcelDocument { - static $ns = "urn:schemas-microsoft-com:office:spreadsheet"; - private $table = array (); - protected $styles = array(); - - function addTable($table) { - $this->table [] = $table; - } - - /** - * Добавление стиля к документу - * @param $name string Имя стиля - * @param $values array Параметры стиля - * @param $type Тип стиля - */ - function setStyle ($name, array $values, $type = 'Interior') - { - if(!isset($this->styles[$name])) { - $this->styles[$name] = array(); - } - $this->styles[$name][$type] = $values; - } - - /** - * Генерация стилей - */ - private function createStyles (XMLWriter $doc) { - $doc->startElement('Styles'); - foreach ($this->styles as $name => $sn) { - $doc->startElement('Style'); - $doc->writeAttribute('ss:ID', $name); - foreach ($sn as $type => $s) { - // Стиль Borders - составной - if ($type == 'Borders') { - $doc->startElement('Borders'); - foreach ($s as $border) { - /*.array.*/$border = $border; - $doc->startElement('Border'); - foreach ($border as $key => $value) { - $doc->writeAttribute('ss:' . $key, $value); - } - $doc->endElement(); - } - $doc->endElement(); - } else { - $doc->startElement($type); - foreach ($s as $key => $value) { - $doc->writeAttribute('ss:' . $key, $value); - } - $doc->endElement(); - } - } - $doc->endElement(); - } - $doc->endElement(); - } - - /** - * Преобразует переводы строки в спец символы - */ - function clean ($s) { - assert(is_string($s)); - - return strtr($s, array ("\n" => " ")); - } - - /** - * Сохраняет таблицу в формате Office 2003 XML - * http://en.wikipedia.org/wiki/Microsoft_Office_XML_formats - */ - function save($filename) - { - $doc = new XMLWriter(); - $doc->openURI($filename); - $doc->setIndent(false); - $doc->startDocument('1.0','utf-8'); - $doc->startElement('Workbook'); - $doc->writeAttribute('xmlns', self::$ns); - $doc->writeAttribute('xmlns:ss', self::$ns); - - $this->createStyles($doc); - - foreach ($this->table as $table) { - if ($table instanceof ExcelTable) { - $table->createTable($doc); - } else { - $table_data = call_user_func($table); - $table_data->createTable($doc); - unset($table_data); - } - } - $doc->endElement(); - } -} -