Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add footer and header for a word #1371

Open
rommer-luo opened this issue May 18, 2018 · 3 comments
Open

add footer and header for a word #1371

rommer-luo opened this issue May 18, 2018 · 3 comments

Comments

@rommer-luo
Copy link

rommer-luo commented May 18, 2018

loadTemplate('1.doc'); // echo $template_content; $header = $template ->createHeader(); $header->addPreserveText('和和科技'); $footer = $template ->createFooter(); $footer->addPreserveText('Page {PAGE} of {NUMPAGES}.'); // Save File $fileName = "word报表".date("YmdHis"); header("Content-type: application/vnd.ms-word"); header("Content-Disposition:attachment;filename=".$fileName.".doc"); header('Cache-Control: max-age=0'); $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); $objWriter->save('php:https://output');
@troosan
Copy link
Contributor

troosan commented May 20, 2018

I'm very sorry, but I do not understand what you are trying to explain ...

@rommer-luo
Copy link
Author

thank you reply,
I just want to set header and footer of a word document use function loadTemplate.
I don`t konw you know it or not?

@rommer-luo rommer-luo changed the title add footer and header for a word(Hello, I want to know. For example, when someone gives an Word document, I use this editor to add the header, footer, and Word to save the download. Instead of directly generating documents with header and footer, I know that.) add footer and header for a word May 21, 2018
@Ahmed-Nasser
Copy link

Ahmed-Nasser commented Nov 20, 2018

@troosan Hello sir, I am absolutely sorry I am new in github and I don't know how to create an issue so I am gonna asking you here. I have a problem with creating a word file using phpWord lib I just created 3 sections one for the header, one for the date and one for some information and this section was a table. the problem here is whenever I add another section after the table the content jumping to the next page I don't know why please help me and I highly appreciate your effort, Thanks
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$textAlign = new \PhpOffice\PhpWord\SimpleType\TextAlignment();
$headerSection = $phpWord->addSection();
$headerImageSource = "";
$header = $headerSection->addHeader();
$header->addImage($headerImageSource, array('width' => 250, 'height'=> 50, 'marginTop'=> -1, 'marginLeft'=> -1, 'wrappingStyle'=> 'behind', 'align'=> 'center'));
$date= date("F jS, Y", time());
$dateSection = $phpWord->addSection();
$dateSection->addText('Date: '.$date, array('name'=> 'Arial', 'size'=> '11'), ['align'=> $textAlign ::CENTER]);
$patientSection = $phpWord->addSection();
$tableStyle = array(
'cellMargin' => 50
);
$textStyle = array('name'=> 'Arial', 'size'=> '10');
$table = $patientSection->addTable($tableStyle);
//creatTableRowsAndCells($table, 2, 3, 3000);
$table->addRow();
$table->addCell(3000)->addText('Patient Name: '.$patientName, $textStyle);
$table->addCell(3000)->addText('DOB: '.$DOB, $textStyle);
$table->addCell(3000)->addText('Gender: '.$gender, $textStyle);`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants