123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- /**
- * Create XLSX
- *
- * @category Phpdocx
- * @package elements
- * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
- * (http://www.2mdc.com)
- * @license LGPL
- * @version 1.0
- * @link http://www.phpdocx.com
- * @since File available since Release 1.0
- */
- /**
- * Create XLSX
- *
- * @category Phpdocx
- * @package elements
- * @copyright Copyright (c) 2009-2011 Narcea Producciones Multimedia S.L.
- * (http://www.2mdc.com)
- * @license http://www.phpdocx.com/wp-content/themes/lightword/pro_license.php
- * @version 1.0
- * @link http://www.phpdocx.com
- * @since Class available since Release 1.0
- */
- class CreateXlsx
- {
- /**
- * @access private
- * @var CreateFooter
- * @static
- */
- private static $_instance = NULL;
- /**
- *
- * @access private
- * @var <type>
- */
- private $_zipXlsx;
- /**
- *
- * @access private
- * @var <type>
- */
- private $_xmlXlTablesContent;
- /**
- *
- * @access private
- * @var <type>
- */
- private $_xmlXlSharedStringsContent;
- /**
- *
- * @access private
- * @var <type>
- */
- private $_xmlXlSheetContent;
- /**
- * Construct
- *
- * @access public
- */
- public function __construct()
- {
- }
- /**
- * Destruct
- *
- * @access public
- */
- public function __destruct()
- {
-
- }
- /**
- *
- * @access public
- * @return string
- */
- public function __toString()
- {
- return $this->_zipXlsx;
- }
- /**
- *
- * @access public
- * @return CreateXlsx
- * @static
- */
- public static function getInstance()
- {
- if (self::$_instance == NULL) {
- self::$_instance = new CreateXlsx();
- }
- return self::$_instance;
- }
- /**
- * Create XLSX
- *
- * @access public
- * @return bool
- */
- public function createXlsx()
- {
- $args = func_get_args();
- $this->_zipXlsx = new ZipArchive();
- $this->_zipXlsx->open($args[0], ZipArchive::OVERWRITE);
- $this->_xmlXlTablesContent = '';
- $this->_xmlXlSharedStringsContent = '';
- $this->_xmlXlSheetContent = '';
- try {
- $dirname = substr(__FILE__, 0, strpos(__FILE__, '/classes')) .
- '/excel/';
- $this->_zipXlsx->addFile(
- $dirname . '[Content_Types].xml',
- '[Content_Types].xml'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'docProps/core.xml',
- 'docProps/core.xml'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'docProps/app.xml',
- 'docProps/app.xml'
- );
- $this->_zipXlsx->addFile(
- $dirname . '_rels/.rels',
- '_rels/.rels'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'xl/_rels/workbook.xml.rels',
- 'xl/_rels/workbook.xml.rels'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'xl/theme/theme1.xml',
- 'xl/theme/theme1.xml'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'xl/worksheets/_rels/sheet1.xml.rels',
- 'xl/worksheets/_rels/sheet1.xml.rels'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'xl/styles.xml',
- 'xl/styles.xml'
- );
- $this->_zipXlsx->addFile(
- $dirname . 'xl/workbook.xml',
- 'xl/workbook.xml'
- );
- $this->addTable($args[1], $args[2]);
- $this->_zipXlsx->addFromString(
- 'xl/tables/table1.xml',
- $this->_xmlXlTablesContent
- );
- $this->addSharedStrings($args[1], $args[2]);
- $this->_zipXlsx->addFromString(
- 'xl/sharedStrings.xml',
- $this->_xmlXlSharedStringsContent
- );
- $this->addSheet($args[1], $args[2]);
- $this->_zipXlsx->addFromString(
- 'xl/worksheets/sheet1.xml',
- $this->_xmlXlSheetContent
- );
- $this->_zipXlsx->close();
- return true;
- } catch (Exception $e) {
- echo 'There was an error related to XLSX file: ',
- $e->getMessage(),
- "\n";
- return false;
- }
- }
- /**
- * Add table
- *
- * @access protected
- * @param array $args[0]
- * @param array $args[1]
- */
- protected function addTable()
- {
- $args = func_get_args();
- $excelTable = CreateExcelTable::getInstance();
- $excelTable->createExcelTable($args[0], $args[1]);
- $this->_xmlXlTablesContent .= (string) $excelTable;
- }
- /**
- * Add shared strings
- *
- * @access protected
- * * @param array $args[0]
- * @param array $args[1]
- */
- protected function addSharedStrings()
- {
- $args = func_get_args();
- $excelSS = CreateExcelSharedStrings::getInstance();
- $excelSS->createExcelSharedStrings($args[0], $args[1]);
- $this->_xmlXlSharedStringsContent .= (string) $excelSS;
- }
- /**
- * Add sheet
- *
- * @access protected
- * * @param array $args[0]
- * @param array $args[1]
- */
- protected function addSheet()
- {
- $args = func_get_args();
- $excelSheet = CreateExcelSheet::getInstance();
- $excelSheet->createExcelSheet($args[0], $args[1]);
- $this->_xmlXlSheetContent .= (string) $excelSheet;
- }
- /**
- *
- * @access private
- * @deprecated
- */
- private function cleanTemplate()
- {
- $this->_xmlWordDocumentTemplate = preg_replace(
- '/__[A-Z]+__/',
- '',
- $this->_xmlWordDocumentTemplate
- );
- }
- }
|