Created
August 21, 2019 04:03
-
-
Save edutrul/91636e917db81b2e9bd3ff6dd31488b0 to your computer and use it in GitHub Desktop.
Php class library from Melissa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include_once dirname(__FILE__) . '/abstract_export_renderer.php'; | |
abstract class AbstractWordRenderer extends AbstractExportRenderer | |
{ | |
abstract protected function getGridPagePart(); | |
public function RenderPage(Page $Page) | |
{ | |
//require_once dirname(__FILE__) . '/../../libs/phpoffice/word/custom.php'; | |
require_once 'libs/phpoffice/word/vendor/autoload.php'; | |
if ($Page->GetContentEncoding() != null) { | |
header('Content-type: application/vnd.ms-word; charset=' . $Page->GetContentEncoding()); | |
} else { | |
header("Content-type: application/vnd.ms-word"); | |
} | |
$options = array( | |
'filename' => Path::ReplaceFileNameIllegalCharacters($Page->GetTitle() . ".doc"), | |
); | |
$Page->GetCustomExportOptions( | |
'doc', | |
$this->getCurrentRowData($Page->GetGrid()), | |
$options | |
); | |
//hasta aqui abre quotation.php vacio | |
$this->DisableCacheControl(); | |
header("Content-Disposition: attachment;Filename=" . $options['filename']); | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0,pre-check=0"); | |
header("Pragma: public"); | |
set_time_limit(0); | |
$customParams = array(); | |
$template = $Page->GetCustomTemplate( | |
PagePart::ExportLayout, | |
PageMode::ExportWord, | |
'export/word_page.tpl', | |
$customParams | |
); | |
// (lineas arriba) aqui recien se genera el word en blanco (contratos.doc) | |
/*$phpWord = new \PhpOffice\PhpWord\PhpWord(); | |
$hoja = $phpWord->addSection(); | |
$cabecera = $hoja->addHeader(); | |
$cabecera->addText('This is my fabulous header!'); | |
$pie = $hoja->addFooter(); | |
$pie->addText('Footer text goes here.'); | |
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); | |
$objWriter ->save('hola.docx');*/ | |
$Grid = $this->Render($Page->GetGrid()); | |
$result = $this->DisplayTemplate($template, | |
array('Page' => $Page), | |
array_merge($customParams, array( | |
'Grid' => $Grid | |
)) | |
); | |
// (lineas arriba) aqui se genera el contenido del word (custom_template.tpl) | |
} | |
protected function GetCustomRenderedViewColumn(AbstractViewColumn $column, $rowValues) | |
{ | |
$result = ''; | |
$handled = false; | |
$column->GetGrid()->OnCustomRenderExportColumn->Fire(array( | |
'word', | |
$this->GetFriendlyColumnName($column), | |
$column->GetValue(), | |
$rowValues, | |
&$result, | |
&$handled, | |
)); | |
if ($handled) { | |
return $result; | |
} | |
return null; | |
} | |
function RenderGrid(Grid $Grid) | |
{ | |
$Rows = array(); | |
$HeaderCaptions = array(); | |
$Grid->GetDataset()->Open(); | |
foreach($Grid->GetExportColumns() as $Column) { | |
$HeaderCaptions[] = $Column->GetCaption(); | |
} | |
while($Grid->GetDataset()->Next()) { | |
$rowValues = $Grid->GetDataset()->GetCurrentFieldValues(); | |
$Row = array(); | |
foreach($Grid->GetExportColumns() as $Column) { | |
$cell['Value'] = $this->RenderViewColumn($Column, $rowValues); | |
$cell['Align'] = $Column->GetAlign(); | |
$Row[] = $cell; | |
} | |
$Rows[] = $Row; | |
} | |
$customParams = array(); | |
$template = $Grid->getPage()->GetCustomTemplate( | |
$this->getGridPagePart(), | |
PageMode::ExportWord, | |
'export/word_grid.tpl', | |
$customParams | |
); | |
$this->DisplayTemplate($template, | |
array('Grid' => $Grid), | |
array_merge($customParams, array( | |
'HeaderCaptions' => $HeaderCaptions, | |
'Rows' => $Rows, | |
'Totals' => $Grid->getTotalsViewData($Grid->GetExportColumns()) | |
)) | |
); | |
} | |
public function RenderPageNavigator($PageNavigator) | |
{ | |
} | |
public function RenderDetailPage(DetailPage $DetailPage) | |
{ | |
$this->RenderPage($DetailPage); | |
} | |
protected function HttpHandlersAvailable() | |
{ | |
return false; | |
} | |
protected function HtmlMarkupAvailable() | |
{ | |
return true; | |
} | |
protected function InteractionAvailable() | |
{ | |
return false; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment