问题
I'm using PHPOffice/PHPWord, and I have a MySQL Database with a table named trials
. It contains 2 columns id
and name
. Both columns are VARCHAR(255)
. There are several rows such as below:
id | name
---+-----------
A1 | Avatar
B1 | Browser
C1 | Calculator
A2 | Align
The query that I use is SELECT * FROM trials ORDER BY id ASC
What I'm trying to do is Make a DOC file and add a new page for each row with (1 page for 1 id
and 1 for name
).
How can I insert a page break between rows?
Also, how can I set the margin and page orientation?
As an example I want the content of mytrial.doc
as below:
Page 01
A1 - Avatar
Page 02
A2 - Align
Page 03
B1 - Browser
Page 04
C1 - Calculator
I use Laravel 4 as my framework.
PS: I already read the following:
how to remove section pagebreak in phpword
sample paragraph pagination
回答1:
You have 2 options to insert a page break
- pageBreakBefore
addPageBreak()
$section->addPageBreak();
Set the margin and page orientation via Styles
- margin
$section = $phpWord->addSection( array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600) );
- orientation
$section= $phpWord->addSection(array('orientation' => 'landscape'));
来源:https://stackoverflow.com/questions/29651259/phpword-insert-page-break-and-set-margin-and-page-orientation-using-laravel-4