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

Get a blank word document #434

Closed
smroczek opened this issue Nov 21, 2014 · 7 comments
Closed

Get a blank word document #434

smroczek opened this issue Nov 21, 2014 · 7 comments

Comments

@smroczek
Copy link

smroczek commented Nov 21, 2014

$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('./documents/invoice1.docx');
$section = $PHPWord->createSection();
$section->addText( $invname);
$section->addText( $organization_link_record['organization_link_address_1'] );
$section->addText( $organization_link_record['organization_link_address_2'] );
if (!empty( $organization_link_record['organization_link_address_3']))
{$section->addText( $organization_link_record['organization_link_address_3'] );}
if (!empty( $organization_link_record['organization_link_address_4']))
{$section->addText( $organization_link_record['organization_link_address_4'] );}
$$section->addText($city);
$document->save('invoice/'.$invoicedoc);

what am i doing wrong?

@franzholz
Copy link

Could you give the full example?
The array $organization_link_record has not been initialized. The same counts for the rest of variables: $invname, ...
And you should give the file invoice1.docx for download.

"$$section" is wrong.

@smroczek
Copy link
Author

order_header_id is $order_header_id
"); $results = DB::query($q1,$order_header_id); foreach ($results as $row1) { ``` $order_header_id = ``` $row1['order_header_id']; ``` $order_header_name = ``` $row1['order_header_name']; $order_header_discount = $row1['order_header_discount']; $_SESSION['order_header_discount'] = $order_header_discount; ``` $state_tax_total = ``` $row1['order_header_tax']; ``` $_SESSION['state_tax_total'] = ``` $state_tax_total; ``` // print_r( $_SESSION ); ``` $order_header_organization_link_id = $row1['order_header_organization_link_id'] ; $order_header_organization_member_id = $row1['order_header_organization_member_id'] ; ``` $order_header_order_type_id = ``` $row1['order_header_order_type_id'] ; ``` $order_header_terms_id = ``` $row1['order_header_terms_id'] ; ``` $order_header_po_number = ``` $row1['order_header_po_number'] ; ``` if ``` (empty($order_header_terms_id)) { ``` $order_header_terms_id = ``` $row1['order_header_terms_id'] ; } ``` $order_header_due_date1 = ``` $row1['order_header_due_date'] ; ``` if ($order_header_due_date1 > ``` '0000-00-00') { ``` $phpdate = strtotime( ``` $order_header_due_date1 ); ``` $order_header_due_date = date( ``` 'm/d/Y', $phpdate ); ``` } $order_header_invoice_date1 = ``` $row1['order_header_invoice_date'] ; ``` if ($order_header_invoice_date1 ``` > '0000-00-00') { ``` $phpdate = strtotime( ``` $order_header_invoice_date1 ); ``` $order_header_invoice_date = ``` date( 'm/d/Y', $phpdate ); ``` $sqlt ='SELECT terms_id , ``` terms_percent , terms_day , terms_text ``` FROM terms WHERE terms_id = %s'; //print(" sqlt
"); $results = ``` DB::query($sqlt,$order_header_terms_id); ``` foreach ($results as $rowt) { $terms_day = ``` $rowt['terms_day'] ; ``` $terms_percent = ``` $rowt['terms_percent'] ; ``` } list ($year,$month, $day) = ``` explode('-', $order_header_invoice_date1); ``` $dateto= ``` GregorianToJD($month,$day,$year) + $terms_day; ``` $order_header_due_date = ``` JDToGregorian($dateto); ``` // print(" terms_day is $terms_day
"); } ``` } ``` //print(" order_header_terms_id is ``` $order_header_terms_id
"); ``` if (!empty($order_header_terms_id)) { $sqlt ='SELECT terms_id , ``` terms_percent , terms_day , terms_text ``` FROM terms WHERE terms_id = %s'; $results = ``` DB::query($sqlt,$order_header_terms_id); ``` foreach ($results as $rowt) { $terms_day = ``` $rowt['terms_day'] ; ``` $terms_percent = ``` $rowt['terms_percent'] ; $_SESSION['terms_percent']=$terms_percent ; $_SESSION['order_header_terms_id']=$order_header_terms_id ; ``` } ``` //print("order_header_invoice_date1 is $order_header_invoice_date1
"); ``` $yesdis ``` =strpos($order_header_invoice_date1,'/') ; ``` if ( $yesdis >0){ list ($month, ``` $day,$year) = explode('/', $order_header_invoice_date1);} ``` $yesin ``` =strpos($order_header_invoice_date1,'-') ; ``` if ( $yesin >0){ list ($year ``` ,$month, $day) = explode('-', $order_header_invoice_date1);} ``` //print("month is $month day ``` is $day year is $year terms day is $terms_day
"); ``` $dateto= ``` GregorianToJD($month,$day,$year) +$terms_day ; ``` //print("dateto is $dateto
``` "); ``` $order_header_due_date = ``` JDToGregorian($dateto); //print("order_header_invoice_date is $order_header_invoice_date
order_header_due_date is $order_header_due_date
"); ``` } ``` $organization_link_record = get_organization_link_record($order_header_organization_link_id); $organization_record = get_organization_record($organization_link_record['organization_link_organiz ation_id']); $_SESSION['state_tax'] =$organization_link_record['organization_link_state_tax'] ; $_SESSION['organization_taxable'] =$organization_record['organization_taxable'] ; $pathroot = '/home/vhosts/greatgrow.com/httpdocs/backoffice/invoice/'; $filedoc =$pathroot."invoice.doc"; //require_once 'PHPWord/PHPWord.php'; $invname =$organization_record['organization_firm_name'].' =>'; $invname.=$organization_link_record['organization_link_first_name']; $invname.=$organization_link_record['organization_link_flast_name']; $city =$organization_link_record['organization_link_city'] ; $city.= ', '.$organization_link_record['organization_link_state_name']; $city.= ' '.$organization_link_record['organization_link_zip']; $cnt =2; $invoicedoc ='invoice'.$cnt.'.docx'; // New Word Document $PHPWord = new PHPWord(); $document = $PHPWord->loadTemplate('./documents/invoice1.docx'); $section = $PHPWord->createSection(); $section->addText( $invname ); $section->addText( $organization_link_record['organization_link_address_1'] ); $section->addText($organization_link_record['organization_link_address_2'] ); if (!empty( $organization_link_record['organization_link_address_3'])) ``` {$section->addText( ``` $organization_link_record['organization_link_address_3'] );} if (!empty( $organization_link_record['organization_link_address_4'])) ``` {$section->addText( ``` $organization_link_record['organization_link_address_4'] );} $section->addText($city); $document->save('invoice/'.$invoicedoc); print (" $city
"); print_r( $organization_link_record); die; the code works here is url staten island, NEW YORK 10305 Array ( [organization_link_id] => 3 [organization_link_organization_id] => 1 [organization_link_first_name] => Tom [organization_link_last_name] => Somebody [organization_link_full_name] => Tom Somebody [organization_link_title] => [organization_link_title_id] => 0 [organization_link_title_name] => [organization_link_address_1] => 489 Steuben Street [organization_link_address_2] => po box 1234 [organization_link_address_3] => [organization_link_address_4] => [organization_link_city] => staten island [organization_link_state_id] => 33 [organization_link_state_name] => NEW YORK [organization_link_state_tax] => 4.0000 [organization_link_country_id] => 8 [organization_link_country_name] => [organization_link_region_name] => [organization_link_zip] => 10305 [organization_link_phone] => 917-968-7093 [oorganization_link_fax] => [organization_link_cell] => [organization_link_notes] => [organization_link_member_id] => 0 [organization_link_type_id] => [organization_link_email] => smroczek@verizon.net [organization_link_email_opt_out] => 0 [organization_link_potential_id] => 0 [organization_link_modified_by] => 1 [organization_link_modified_by_time] => 2014-11-17 14:24:14 [organization_link_created_by] => 0 [organization_link_created_by_time] => 0000-00-00 00:00:00 ) I fixed $$section Thank you for your help The main url is http://greatgrow.com/ From: Franz Holzinger [mailto:notifications@github.com] Sent: Friday, November 21, 2014 2:57 PM To: PHPOffice/PHPWord Cc: smroczek Subject: Re: [PHPWord] Get a blank word document (#434) Could you give the full example? The array $organization_link_record has not been initialized. The same counts for the rest of variables: $invname, ... And you should give the file invoice1.docx for download. "$$section" is wrong. ## Reply to this email directly or view it on GitHub https://github.com//issues/434#issuecomment-64028564 .

@smroczek
Copy link
Author

Some more info

phpword
object(PHPWord)#3 (4) { ["_properties":"PHPWord":private]=>
object(PHPWord_DocumentProperties)#4 (10) {
["_creator":"PHPWord_DocumentProperties":private]=> string(0) ""
["_lastModifiedBy":"PHPWord_DocumentProperties":private]=> string(0) ""
["_created":"PHPWord_DocumentProperties":private]=> int(1416680731)
["_modified":"PHPWord_DocumentProperties":private]=> int(1416680731)
["_title":"PHPWord_DocumentProperties":private]=> string(0) ""
["_description":"PHPWord_DocumentProperties":private]=> string(0) ""
["_subject":"PHPWord_DocumentProperties":private]=> string(0) ""
["_keywords":"PHPWord_DocumentProperties":private]=> string(0) ""
["_category":"PHPWord_DocumentProperties":private]=> string(0) ""
["_company":"PHPWord_DocumentProperties":private]=> string(0) "" }
["_defaultFontName":"PHPWord":private]=> string(5) "Arial"
["_defaultFontSize":"PHPWord":private]=> int(20)
["_sectionCollection":"PHPWord":private]=> array(1) { [0]=>
object(PHPWord_Section)#7 (5) {
["_sectionCount":"PHPWord_Section":private]=> int(1)
["_settings":"PHPWord_Section":private]=> object(PHPWord_Section_Settings)#8
(17) { ["_defaultPageSizeW":"PHPWord_Section_Settings":private]=> int(11906)
["_defaultPageSizeH":"PHPWord_Section_Settings":private]=> int(16838)
["_orientation":"PHPWord_Section_Settings":private]=> NULL
["_marginTop":"PHPWord_Section_Settings":private]=> int(1418)
["_marginLeft":"PHPWord_Section_Settings":private]=> int(1418)
["_marginRight":"PHPWord_Section_Settings":private]=> int(1418)
["_marginBottom":"PHPWord_Section_Settings":private]=> int(1134)
["_pageSizeW":"PHPWord_Section_Settings":private]=> int(11906)
["_pageSizeH":"PHPWord_Section_Settings":private]=> int(16838)
["_borderTopSize":"PHPWord_Section_Settings":private]=> NULL
["_borderTopColor":"PHPWord_Section_Settings":private]=> NULL
["_borderLeftSize":"PHPWord_Section_Settings":private]=> NULL
["_borderLeftColor":"PHPWord_Section_Settings":private]=> NULL
["_borderRightSize":"PHPWord_Section_Settings":private]=> NULL
["_borderRightColor":"PHPWord_Section_Settings":private]=> NULL
["_borderBottomSize":"PHPWord_Section_Settings":private]=> NULL
["_borderBottomColor":"PHPWord_Section_Settings":private]=> NULL }
["_elementCollection":"PHPWord_Section":private]=> array(7) { [0]=>
object(PHPWord_Section_Text)#9 (3) {
["_text":"PHPWord_Section_Text":private]=> string(15) "Order TypeQuote"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [1]=>
object(PHPWord_Section_TextBreak)#10 (0) { } [2]=>
object(PHPWord_Section_TextBreak)#11 (0) { } [3]=>
object(PHPWord_Section_Text)#12 (3) {
["_text":"PHPWord_Section_Text":private]=> string(29) "Staten Island Big
Store =>Tom" ["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [4]=>
object(PHPWord_Section_Text)#13 (3) {
["_text":"PHPWord_Section_Text":private]=> string(18) "489 Steuben Street"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [5]=>
object(PHPWord_Section_Text)#14 (3) {
["_text":"PHPWord_Section_Text":private]=> string(11) "po box 1234"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [6]=>
object(PHPWord_Section_Text)#15 (3) {
["_text":"PHPWord_Section_Text":private]=> string(29) "staten island, NEW
YORK 10305" ["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } }
["_header":"PHPWord_Section":private]=> NULL
["_footer":"PHPWord_Section":private]=> NULL } } }
section
object(PHPWord_Section)#7 (5) {
["_sectionCount":"PHPWord_Section":private]=> int(1)
["_settings":"PHPWord_Section":private]=> object(PHPWord_Section_Settings)#8
(17) { ["_defaultPageSizeW":"PHPWord_Section_Settings":private]=> int(11906)
["_defaultPageSizeH":"PHPWord_Section_Settings":private]=> int(16838)
["_orientation":"PHPWord_Section_Settings":private]=> NULL
["_marginTop":"PHPWord_Section_Settings":private]=> int(1418)
["_marginLeft":"PHPWord_Section_Settings":private]=> int(1418)
["_marginRight":"PHPWord_Section_Settings":private]=> int(1418)
["_marginBottom":"PHPWord_Section_Settings":private]=> int(1134)
["_pageSizeW":"PHPWord_Section_Settings":private]=> int(11906)
["_pageSizeH":"PHPWord_Section_Settings":private]=> int(16838)
["_borderTopSize":"PHPWord_Section_Settings":private]=> NULL
["_borderTopColor":"PHPWord_Section_Settings":private]=> NULL
["_borderLeftSize":"PHPWord_Section_Settings":private]=> NULL
["_borderLeftColor":"PHPWord_Section_Settings":private]=> NULL
["_borderRightSize":"PHPWord_Section_Settings":private]=> NULL
["_borderRightColor":"PHPWord_Section_Settings":private]=> NULL
["_borderBottomSize":"PHPWord_Section_Settings":private]=> NULL
["_borderBottomColor":"PHPWord_Section_Settings":private]=> NULL }
["_elementCollection":"PHPWord_Section":private]=> array(7) { [0]=>
object(PHPWord_Section_Text)#9 (3) {
["_text":"PHPWord_Section_Text":private]=> string(15) "Order TypeQuote"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [1]=>
object(PHPWord_Section_TextBreak)#10 (0) { } [2]=>
object(PHPWord_Section_TextBreak)#11 (0) { } [3]=>
object(PHPWord_Section_Text)#12 (3) {
["_text":"PHPWord_Section_Text":private]=> string(29) "Staten Island Big
Store =>Tom" ["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [4]=>
object(PHPWord_Section_Text)#13 (3) {
["_text":"PHPWord_Section_Text":private]=> string(18) "489 xx Street"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [5]=>
object(PHPWord_Section_Text)#14 (3) {
["_text":"PHPWord_Section_Text":private]=> string(11) "po box 1234"
["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } [6]=>
object(PHPWord_Section_Text)#15 (3) {
["_text":"PHPWord_Section_Text":private]=> string(29) "staten island, NEW
YORK 10305" ["_styleFont":"PHPWord_Section_Text":private]=> NULL
["_styleParagraph":"PHPWord_Section_Text":private]=> NULL } }
["_header":"PHPWord_Section":private]=> NULL
["_footer":"PHPWord_Section":private]=> NULL }
document
object(PHPWord_Template)#5 (3) { ["_objZip":"PHPWord_Template":private]=>
object(ZipArchive)#6 (5) { ["status"]=> int(0) ["statusSys"]=> int(0)
["numFiles"]=> int(0) ["filename"]=> string(0) "" ["comment"]=> string(0) ""
} ["_tempFileName":"PHPWord_Template":private]=> string(27)
"./documents/1416680731.docx" ["_documentXML":"PHPWord_Template":private]=>
string(5426) " " }

From: Franz Holzinger [mailto:notifications@github.com]
Sent: Friday, November 21, 2014 2:57 PM
To: PHPOffice/PHPWord
Cc: smroczek
Subject: Re: [PHPWord] Get a blank word document (#434)

Could you give the full example?
The array $organization_link_record has not been initialized. The same
counts for the rest of variables: $invname, ...
And you should give the file invoice1.docx for download.

"$$section" is wrong.

Reply to this email directly or view it on GitHub
#434 (comment) .
<https://github.com/notifications/beacon/AE8WFy4DmzXdyW5s-e2dHIqdh4LXOtFlks5
nP5ChgaJpZM4C_KlA.gif>

@smroczek
Copy link
Author

note error
$section = $PHPWord->createSection(sectionStyle); should be $section =
$PHPWord->createSection($sectionStyle);

@smroczek
Copy link
Author

if you use $document = $PHPWord->loadTemplate('Template.docx');

$section->addText( $invname ); will not work

@smroczek
Copy link
Author

how can i get a new table in a cell
a table in a table?

@alpha1125
Copy link

Late to the party... but here's the answer you probably didn't want.
You can't do that, unless you nest it somewhere to have it possibly replaceBlock() a ${tag} with a block.

"It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform main document part of the template using XSLT" -- Source: http://phpword.readthedocs.org/en/latest/templates-processing.html

@troosan troosan closed this as completed Jun 27, 2017
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

4 participants