/** * @covers ::setTempDir * @covers ::getTempDir * @depends testPhpTempDirIsUsedByDefault * @test */ public function testTempDirCanBeSet() { $userDefinedTempDir = 'C:\\PhpWordTemp'; Settings::setTempDir($userDefinedTempDir); $currentTempDir = Settings::getTempDir(); $this->assertEquals($userDefinedTempDir, $currentTempDir); $this->assertNotEquals(sys_get_temp_dir(), $currentTempDir); }
public function _testReadWriteCycleSucks() { PhpWord\Settings::setTempDir(Tinebase_Core::getTempDir()); $source = str_replace('tests/tine20', 'tine20', __DIR__) . '/templates/addressbook_contact_letter.docx'; $phpWord = PhpWord\IOFactory::load($source); $tempfile = tempnam(Tinebase_Core::getTempDir(), __METHOD__ . '_') . '.docx'; $writer = $phpWord->save($tempfile); `open {$tempfile}`; }
function __construct() { parent::__construct(); Autoloader::register(); Settings::loadConfig(); Settings::setTempDir(getcwd() . TMPDIR_WORD); // Set writers $writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf'); // Set PDF renderer if (Settings::getPdfRendererPath() === null) { $writers['PDF'] = null; } // Return to the caller script when runs by CLI if (PHP_SAPI == 'cli') { return; } }
/** * create new PhpWord document * * @return void */ protected function _createDocument() { \PhpOffice\PhpWord\Settings::setTempDir(Tinebase_Core::getTempDir()); $templateFile = $this->_getTemplateFilename(); $this->_docObject = new \PhpOffice\PhpWord\PhpWord(); if ($templateFile !== NULL) { $this->_docTemplate = new \PhpOffice\PhpWord\TemplateProcessor($templateFile); } }
/** * Funció que em retorna el document de tancament **/ public static function generaDocumentTancament($idSessio) { \PhpOffice\PhpWord\Settings::setTempDir(BASEURL . 'tmp/'); $phpword = new \PhpOffice\PhpWord\PhpWord(); $T = $phpword->loadTemplate(BASEURL . '/Data/Documents/InformeTancamentLaGorga.docx'); $EM = new EspectaclesModel(); $LlistatLocalitats = $EM->getLocalitatsForDocument($idSessio); if (sizeof($LlistatLocalitats) == 0) { throw new MyException('No he trobat cap seient ocupat.'); } $RECAPTAT = array('TOTALS' => array('M' => array('PERSONES' => 0, 'PREU' => 0), 'T' => array('PERSONES' => 0, 'PREU' => 0), 'D' => array('PERSONES' => 0, 'PREU' => 0), 'TOTAL' => 0, 'PERSONES' => 0), 'TIPUS_ENTRADA' => array()); $LC = $LlistatLocalitats['COMANDES']; $LS = $LlistatLocalitats['SESSIO']; $LE = $LlistatLocalitats['ESPECTACLE']; foreach ($LlistatLocalitats['LOCALITATS'] as $K => $LTO) { $OP = $LTO->getPreu(); $idComanda = $LTO->localitat['l_idComanda']; $TipusPagament = $LC[$idComanda]->comanda['co_TipusPagament']; $NomPreu = $OP->preu['nom']; $Import = $OP->preu['import']; if ($LTO->localitat['l_estat'] == 'O') { if (!isset($RECAPTAT['TOTALS'][$TipusPagament])) { $RECAPTAT['TOTALS'][$TipusPagament] = array('PERSONES' => 0, 'PREU' => 0); } //Sumem import al recaptat per tipus pagament $RECAPTAT['TOTALS'][$TipusPagament]['PREU'] += $Import; $RECAPTAT['TOTALS'][$TipusPagament]['PERSONES'] += 1; //Sumem import al total recaptat $RECAPTAT['TOTALS']['TOTAL'] += $Import; //Sumem l'import a la persona $RECAPTAT['TOTALS']['PERSONES'] += 1; //Sumem import al tipus de preu if (!isset($RECAPTAT['TIPUS_ENTRADA'][$NomPreu])) { $RECAPTAT['TIPUS_ENTRADA'][$NomPreu] = array('TOTAL' => 0, 'PERSONES' => 0, 'PREU' => $Import); } //Sumem import al total per tipus de preu $RECAPTAT['TIPUS_ENTRADA'][$NomPreu]['TOTAL'] += $Import; //Sumem persona al tipus de preu $RECAPTAT['TIPUS_ENTRADA'][$NomPreu]['PERSONES'] += 1; } else { //Sumem import al tipus de preu if (!isset($RECAPTAT['TIPUS_ENTRADA']['Reserves'])) { $RECAPTAT['TIPUS_ENTRADA']['Reserves'] = array('TOTAL' => 0, 'PERSONES' => 0, 'PREU' => 0); } //Sumem import al total per tipus de preu $RECAPTAT['TIPUS_ENTRADA']['Reserves']['TOTAL'] = 0; //Sumem persona al tipus de preu $RECAPTAT['TIPUS_ENTRADA']['Reserves']['PERSONES'] += 1; } } $T->setValue('Espectacle', htmlspecialchars($LE->espectacle['e_Titol'])); $T->setValue('Dia', htmlspecialchars($LS->sessio['tmp_Dia'])); $T->setValue('Hora', htmlspecialchars($LS->sessio['tmp_Hora'])); $T->setValue('Organitzador', htmlspecialchars($LE->espectacle['e_OrganitzadorNom'])); $T->setValue('Cif', htmlspecialchars($LE->espectacle['e_OrganitzadorCif'])); $T->setValue('Recaptat', $RECAPTAT['TOTALS']['TOTAL']); $T->setValue('Online', $RECAPTAT['TOTALS']['T']['PREU']); $T->setValue('Datafon', $RECAPTAT['TOTALS']['D']['PREU']); $T->setValue('Metalic', $RECAPTAT['TOTALS']['M']['PREU']); $T->setValue('NOnline', $RECAPTAT['TOTALS']['T']['PERSONES']); $T->setValue('NDatafon', $RECAPTAT['TOTALS']['D']['PERSONES']); $T->setValue('NMetalic', $RECAPTAT['TOTALS']['M']['PERSONES']); $T->setValue('Persones', $RECAPTAT['TOTALS']['PERSONES']); $T->cloneRow('rowValue', sizeof($RECAPTAT['TIPUS_ENTRADA'])); $i = 1; foreach ($RECAPTAT['TIPUS_ENTRADA'] as $K => $V) { $T->setValue('rowValue#' . strval($i), htmlspecialchars($K)); $T->setValue('rowQuantitat#' . strval($i), $V['PERSONES']); $T->setValue('rowPreu#' . strval($i), $V['PREU']); $T->setValue('rowImport#' . strval($i), $V['TOTAL']); $i++; } $T->setValue('Total', $RECAPTAT['TOTALS']['TOTAL']); $config = J::loadJsonConfigFile("config.json"); $importTaxa1Dia = floatval($config['TAXA_OCUPACIO']); $importTaxa = $RECAPTAT['TOTALS']['TOTAL'] * 25 / 100; if ($importTaxa > $importTaxa1Dia) { $importTaxa = $importTaxa1Dia * 0.3; } $T->setValue('ImportTaxa', $importTaxa); $T->saveAs(BASEURL . 'Data/Documents/S' . $idSessio . '.docx'); return true; }
function mergeDOCX($source_file, $merged_file) { // Important: we get the merge data first, because the phpWord // autoloader included below stuffs up the Jethro autoloader // and causes errors. $data = array_values($this->getMergeData()); // NB THIS FILE HAS BEEN CHANGED! require_once 'include/phpword/src/PhpWord/Autoloader.php'; \PhpOffice\PhpWord\Autoloader::register(); \PhpOffice\PhpWord\Settings::setTempDir(dirname($source_file)); $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($source_file); if (!$templateProcessor->cloneBlock('MERGEBLOCK', count($data))) { $vars = $templateProcessor->getVariables(); if (empty($vars)) { trigger_error("You don't seem to have included any \${keywords} in your file; cannot merge"); return; } $templateProcessor->cloneRow(reset($vars), count($data)); } foreach ($data as $num => $row) { foreach ($row as $k => $v) { $templateProcessor->setValue(strtoupper($k) . '#' . ($num + 1), $this->xmlEntities($v)); } } $templateProcessor->saveAs($merged_file); }