Subscribe: PHPWord
http://phpword.codeplex.com/project/feeds/rss
Added By: Feedage Forager Feedage Grade B rated
Language:
Tags:
add  document  docx  file  function  new  null  objwriter  phpword  save  template  word document  word file  word  xmlwriter 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: PHPWord

PHPWord



With PHPWord you can easily create a Word document with PHP. PHPWord creates docx Files that can include all major word functions like TextElements, Tables, ListItems, Images.



 



Reviewed: PHPWord 0.6.2-1 Beta (Oct 25, 2017)

Thu, 26 Oct 2017 01:54:16 GMT

Rated 3 Stars (out of 5) - mantep jiwa



Created Unassigned: How to add special character(↑) in word document [110]

Thu, 07 Sep 2017 06:50:26 GMT

HI,

I want to add special character(↑) like $section->addText('Hello World! ↑ U+2B06');.

Could you please tell me what is the procedure to add special character in the word file.

Thanks,
Avinash



Created Unassigned: How to embed and external font into the Word doc [109]

Mon, 31 Jul 2017 15:00:03 GMT

Hi, PHPWord has been working wonderfully for me for last couple of years but I am running into an issue now. I have to use an external font into the document.
PHPWord allows me to set the font name which is great as far as the computer the word document is being opened has the said font installed.

MS Word allows to embed the font being used into the document so that it loads the font correctly even if the font used does not exist on the system (see attached).

How can I use PHPWord library to embed the font into the doc? I don't mind making changes to the library if needed.

Thanks.



Edited Unassigned: PhpWord not rendering html properly in Word doc [108]

Wed, 03 May 2017 20:04:50 GMT

html markup renders in browser: "The County Partnership for Children is a not-for-profit agency" - renders in bold, and italics, respectively.

here is my code:
```
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter( $PHPWord, 'Word2007' );
$fileloaction = '/var/www/rootwebfolder/contracts/tmp';
$filename = 'OCA_'.$LPShort."_".date('YmdHis',time()).'.docx';
$FullName = $fileloaction.'/'.$filename;
//echo $FullName;
$objWriter->save($FullName);
```

yet the rendered Word document still shows those html tags: The Caswell County Partnership for Children is a not-for-profit agency.

in fact, my app exports 2 files to Word, the first shows the html tags, the 2nd in Word ignores the tags altogether, the text not marked up at all. yet, in the sql database, the tags are in each of the files.

Help?




Created Unassigned: PhpWord not rendering html properly in Word doc [108]

Wed, 03 May 2017 20:03:33 GMT

html markup renders in browser: "The County Partnership for Children is a not-for-profit agency" - renders in bold, and italics, respectively.

here is my code:
```
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter( $PHPWord, 'Word2007' );
$fileloaction = '/var/www/ncpcphp/contracts/tmp';
$filename = 'OCA_'.$LPShort."_".date('YmdHis',time()).'.docx';
$FullName = $fileloaction.'/'.$filename;
//echo $FullName;
$objWriter->save($FullName);
```

yet the rendered Word document still shows those html tags: The Caswell County Partnership for Children is a not-for-profit agency.

in fact, my app exports 2 files to Word, the first shows the html tags, the 2nd in Word ignores the tags altogether, the text not marked up at all. yet, in the sql database, the tags are in each of the files.

Help?




New Post: Image Template

Mon, 06 Feb 2017 06:58:50 GMT

How can i change a word to an image ??



New Comment on "Documentation"

Mon, 06 Feb 2017 06:22:44 GMT

how can i set an image in a certain position



New Post: manipulate template

Tue, 31 Jan 2017 10:38:20 GMT

a suggestion to replace a token in template by a table

In /PHPWord/Shared/XMLWriter.php

Add this
public function setIndent($indent) {
    $this->_xmlWriter->setIndent((bool)$indent);
}
public function setIndentString($indentString) {
    $this->_xmlWriter->setIndentString((string)$indentString);
}
public function getWriter() {
    return $this->_xmlWriter;
}
In /PHPWord/Writer/Word2007/Base.php

replace on line 372 :
protected function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)
by
public function _writeTable(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Table $table)
And a example of use :
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate('Template.docx');

// the construction of the table 
$section = $PHPWord->createSection();
$table = $section->addTable();
$competences = array(
    "Developpement"  => array("JAVA","PHP","HTML", "ttttt"),     
    "Data base"  => array("ORACLE","MYSQL","DATABASE", "ttttt"),     
    "Framework"  => array("LIEFRY" ,"STRUTS" ,"NOHETO", "ttttt"),
);
foreach($competences as $cle1 => $valeur1)
{
    foreach ($valeur1 as $cle2=>$valeur2)
    {
     $table->addRow();
     $table->addCell(1750)->addText("$cle1,$valeur2");
    }
}

$objWriter = new PHPWord_Shared_XMLWriter();
$objWriter->setIndent(FALSE);
$objWriter->setIndentString('');
$word2007Writer = new PHPWord_Writer_Word2007_Base();
$word2007Writer->_writeTable($objWriter, $table);
$xmlWriter = $objWriter->getWriter();
$output = $xmlWriter->outputMemory();

$document->setValue('test', $output );

$document->save('Solarsystem.docx');



New Post: PDF

Mon, 19 Dec 2016 03:02:53 GMT

hello guys!
Question:
  1. can I save .pdf?
  2. or I need save as .doc , and then load this .doc in memory to save as .pdf?
  3. if I can save .pdf, how to do this?
Looking forward to your reply!
good luck!



New Post: Can i save to pdf ?

Mon, 12 Dec 2016 11:53:05 GMT

Hi !

Some way to save it to pdf ?

Thanks for advance ?
Carles.



New Post: Example template add rows from mysql database

Mon, 12 Dec 2016 11:07:58 GMT

Hi,
how can i add rows dynamic from mysql database ?

Thanks for advance.

Carles



New Post: Getting started from zero knowledge

Fri, 11 Nov 2016 10:55:53 GMT

Hi

I am trying to get up and running with phpWord because it sounds amazing. I have tried to work my way through the installation instructions but I don't really know what I am doing and so after I have done a step I don't know how to check if I've done it properly.

My server is Windows Server 2008 running IIS. What I have done so far:
  1. Downloaded php-5.6.28-nts-Win32-VC11-x86 and installed this. This appears to be working as when I load my test.php page with phpinfo(); it shows a page with a load of info and PHP Version 5.6.28 at the top.
  2. I then installed composer on the server - I know this is working as it downloaded stuff for me in later steps of the installation.
  3. On the server I then typed composer require zendframework/zendframework and it downloaded a bunch of stuff - I am not sure where it actually put everything but it seemed to have worked.
  4. On the server I then typed composer require phpoffice/phpword "v0.13.*" this downloaded and installed pclzip, common and phpword files. Again, I don't know where those files actually went but it seems to have worked.
Things I am unsure of at this point:
  1. Do I need to do anything with regards XML Parser extension
  2. What is Zend\Stdlib component and how do I get it
  3. What is Zend\Validator component and how do I get it
My test script begins with this:

require_once 'bootstrap.php';

// Creating the new document...
$phpWord = new \PhpOffice\PhpWord\PhpWord();
?>

More questions:
  1. What is bootstrap.php and does my php script know where to look for it? Does bootstrap.php need to be in the same folder as my test script?
  2. I am getting a 500 error when I run my test script - do I need to tell IIS where the phpword library is or should composer have done that for me?
Thanks very much - like I say I am starting from zero knowledge. I'd be happy to turn an answers into a complete beginner's guide and make it available to all.

Thanks very much

Ed



New Post: is possible to set margin to paragraph ?

Wed, 02 Nov 2016 23:43:25 GMT

I created a solution that works for me. I don't know if is the right way, if works every time, if works to everyone, etc....do the following:

FILE -> /PHPWord/Style/Paragraph.php

ADD TO THE CLASS PHPWord_Style_Paragraph
private $_indentLeft;
private $_indentRight;
public function getIndentLeft() {
    return $this->_indentLeft;
}
public function getIndentRight() {
    return $this->_indentRight;
}
public function setIndentLeft($pValue = null) {
    $this->_indentLeft = $pValue;
    return $this;
}
public function setIndentRight($pValue = null) {
    $this->_indentRight = $pValue;
    return $this;
}
AND ADD TO __construct() FUNCTION
$this->_indentLeft         = null;
$this->_indentRight         = null;

FILE -> /PHPWord/Writer/Word2007/Base.php

ADD TO _writeParagraphStyle() FUNCTION
    $indentLeft = $style->getIndentLeft();
    $indentRight = $style->getIndentRight();

    if(!is_null($indentLeft) || !is_null($indentRight)) {
            $objWriter->startElement('w:pPr');
                $objWriter->startElement('w:ind');
                if(!is_null($indentLeft)){
                    $objWriter->writeAttribute('w:left', $indentLeft);
                }
                if(!is_null($indentRight)){
                    $objWriter->writeAttribute('w:right', $indentRight);
                }
                $objWriter->endElement();
            $objWriter->endElement(); 
      }
THAN JUST USE AS A STYLE
$paragraph = $section->createTextRun(array('indentLeft' => 500,'indentRight'=>500))->addText('YOUR TEXT' );



Created Unassigned: Mail Image issue [107]

Sat, 08 Oct 2016 07:08:07 GMT

php word document issue in gmail attachment .
When i open file in gmail doc the image of word document is not displayed only just text will appear.





New Post: Template problem

Wed, 28 Sep 2016 15:43:24 GMT

Hi

Using your php2excel -> working fine.

But one thing about php2rowd, maybe I havent read documentation properly or something else.
But anyway.

My problem is.

I have a template .docx and some fields marked ${value1}.... Using my template with example tamplete php. works fine, but it saves the new document on server.

How can I get it locally saved like in php2excel, there using template it automatically saves it locally.

I have tried different header functions, but when using those I get what I want but the document is EMPTY.

regards
Pekka R



Created Unassigned: after save i have a corrupted file [106]

Thu, 08 Sep 2016 07:51:16 GMT

here is my code :


$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getCompatibility()->setOoxmlVersion(15);

$phpWord->setDefaultFontSize(10);
$sectionRun = $phpWord->addSection(array('marginLeft'=>"900",'marginRight'=>"900"));
$section= $sectionRun->addTextRun();
$filename = "Arrete-Renouvellement.docx";

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save($webPath . '/courrier/renouvellement/'.$filename);

when I open the saved file it 's corrupted, i'm on symfony2

I dont know what is the problem can you help me

thank you

my file on the attachment




New Post: tblHeader

Sun, 21 Aug 2016 21:47:09 GMT

Hi there,

How can I add a function to add a table header (tblHeader) for the first row in table (Repeat table row on every new page). PHPWord 0.6.2-1 Beta does not have this function.

Your help in this regard is highly appreciated.

Thanks.



Edited Unassigned: How to insert an image in existing word file at a specified position? [105]

Fri, 08 Jul 2016 10:34:43 GMT

I started using PHPWORD, it is a nice API to work on. But, I have an issue regarding this. I didn't find the way to __insert an image in a existing word file at a specified position I need.__

Can anyone help me understanding of how to insert it...



Created Unassigned: How to insert an image in existing word file at a specified position? [105]

Tue, 05 Jul 2016 09:06:11 GMT

I started using PHPWORD, it is a nice API to work on. But, I have an issue regarding this. I didn't find the way to __insert an image in a existing word file at a specified position I need.__

Can anyone help me understanding of how to insert it.



New Post: Some issues in exporting

Tue, 28 Jun 2016 18:47:43 GMT

Hi there,
I love this library because this saves a lot of my time in exporting to .docx files.
Working fine till I want to add some HTML output in docx file.
So my problem is like this way:
I have a form where a user can enter information about him/herself.
Then I have to export that entered information from database to a word file.
I done this job by using placeholder concept using PHPWord.
But now I have something like this, user have an option to write information in WYSIWYG editor which outputs in html.
So now I am trying to do something that in docx file the output of html will be shown not the HTML tags. Because that document eventually downloaded by the user.
So I had searched through the library and cant get any solution.
Can anyone help me in this case.
Thanks