Beispiel #1
0
 /**
  * Обрабатываем данные документа и изменяем их если нужно
  * 
  */
 public function parseContent()
 {
     if ($this->opened) {
         $this->_sharedIndex = $this->zip->locateName($this->_sharedStrings, ZIPARCHIVE::FL_NOCASE);
         $this->_sheetIndex = $this->zip->locateName($this->_workSheet, ZIPARCHIVE::FL_NOCASE);
         $this->_calcIndex = $this->zip->locateName($this->_calcChain, ZIPARCHIVE::FL_NOCASE);
         //            $this->_styleIndex  = $this->zip->locateName($this->_styles, ZIPARCHIVE::FL_NOCASE);
         $this->initDOMDocument('shared', $this->_sharedIndex);
         $this->initDOMDocument('sheet', $this->_sheetIndex);
         //            $this->initDOMDocument('style',  $this->_styleIndex);
         $this->initDOMDocument('calc', null);
         // По формулам создадим новый документ
         $pskb = sbr_meta::getReservedSbr($this->period);
         $count_rows = count($pskb);
         $from_date = date('d.m.Y', strtotime($this->period[0]));
         $to_date = date('d.m.Y', strtotime($this->period[1]));
         $period = "за период с {$from_date} по {$to_date}";
         $this->replaceSharedString(4, $period);
         $this->moveFooter($count_rows);
         foreach ($pskb as $i => $data) {
             $this->setOneRowTable($i, $data);
         }
         $this->generateFormulaData();
         $this->setContentFile($this->_sharedStrings, $this->dom['shared']->saveXML());
         $this->setContentFile($this->_workSheet, $this->dom['sheet']->saveXML());
         $this->setContentFile($this->_calcChain, $this->dom['calc']->saveXML());
         // Все гуд закрываемся
         $this->zip->close();
     }
 }
Beispiel #2
0
 /**
  * Парсим данные документа и изменяем их если нужно.
  * 
  * @param string $content Данные документа (обычно это content.xml из шаблона документа ODT)
  * 
  * @return type
  */
 public function parseContent($content)
 {
     $this->dom = new DOMDocument('1.0');
     $this->dom->loadXML($content);
     $this->xpath = new DOMXPath($this->dom);
     $this->setStyleTable();
     $period = $this->xpath->query('//text:p[@text:style-name= "period"]', $this->dom->documentElement)->item(0);
     if ($period) {
         $from_date = date('d.m.Y', strtotime($this->period[0]));
         $to_date = date('d.m.Y', strtotime($this->period[1]));
         $new_period = $this->dom->createElement('text:p', iconv('windows-1251', 'utf-8', "за период с {$from_date} по {$to_date}"));
         $new_period->setAttribute('text:style-name', 'period');
         $period->parentNode->replaceChild($new_period, $period);
     }
     $table = $this->xpath->query('//table:table[@table:name= "table_test"]', $this->dom->documentElement)->item(0);
     $pskb = sbr_meta::getReservedSbr($this->period);
     $i = 1;
     $sum = 0;
     if ($pskb) {
         foreach ($pskb as $data) {
             $table_row = $this->dom->createElement('table:table-row');
             $name_emp = $this->_enc($data['nameCust']);
             $sbr_id = $this->_enc("№ {$data['sbr_id']}, " . date('d.m.Y H:i', strtotime($data['covered'])));
             $lc_id = $this->_enc("№ {$data['lc_id']}");
             $cost = $this->_enc(number_format($data['cost'], 2, ',', ' '));
             $table_row->appendChild($this->createTableCell($i));
             // п/п
             $table_row->appendChild($this->createTableCell($name_emp));
             // Наименование Заказчика
             $table_row->appendChild($this->createTableCell($sbr_id));
             // Соглашение (№, дата)
             $table_row->appendChild($this->createTableCell($lc_id));
             // Идентификатор аккредитива
             $table_row->appendChild($this->createTableCell($cost));
             // Сумма резервирования
             ++$i;
             $sum += $data['cost'];
             $table->appendChild($table_row);
         }
     }
     // Добавляем Итого
     $table_row = $this->dom->createElement('table:table-row');
     $table_row->appendChild($this->createTableCell($this->_enc('Итого за отчетный период:'), 4, 'p_1'));
     $table_row->appendChild($this->dom->createElement('table:covered-table-cell'));
     // Наименование Заказчика
     $table_row->appendChild($this->dom->createElement('table:covered-table-cell'));
     // Соглашение (№, дата)
     $table_row->appendChild($this->dom->createElement('table:covered-table-cell'));
     // Идентификатор аккредитива
     $table_row->appendChild($this->createTableCell(number_format($sum, 2, ',', ' ')));
     // Итого
     $table->appendChild($table_row);
     return $this->dom->saveXML();
 }