Subscribe: phpword Discussions Rss Feed
http://phpword.codeplex.com/project/feeds/rss?ProjectRSSFeed=codeplex://forum/phpword
Added By: Feedage Forager Feedage Grade B rated
Language:
Tags:
array  document  docx  file  function  new  null  objwriter  phpword new  phpword  save pdf  save  section  template  word 
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 Discussions Rss Feed

phpword Discussions Rss Feed



phpword Discussions Rss Description



 



New Post: Image Template

Mon, 06 Feb 2017 06:58:50 GMT

How can i change a word to an image ??



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' );



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



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.



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



New Post: Templates, tegs

Wed, 11 May 2016 12:58:49 GMT

Hallo,

I have a .doc template file. there are tegs in this file, for example {{Adresse}} or . I upload the file to the server. There i need to read file, fill tegs and save.

The question is: how can i parse File and fill tegs and is there any standart tags in the library?

Thanks in advice



New Post: PHP - replace strings in .doc file

Wed, 04 May 2016 03:17:54 GMT

Hi,

I am new to PHPWord and was wondering if the script can help with the following problem.

I have a folder with numerous .doc (and some .docx) files and would like to open each of them, and then replace strings such as "$$PROPERTY$$" with my previously entered $property variable. There are also replacements for $$DATE$$, $$AREA$$, $$OUTLET$$ and others.

Finally, there is also one image embedded in the word files that should be replaced with the one linked in my $logo variable. The pictures are both the same size and same location.

How would I best go about this and can WordPHP actually do this?

Thank you,
Patrick



New Post: Help ADDCHART

Mon, 29 Feb 2016 15:42:24 GMT

the Sample Chart 32 only has the type of graph but does not have to add caption and how to feed their part, someone has a more complete example , like the image below

thanks in advance


(image)



New Post: break line in table

Sun, 17 Jan 2016 21:59:33 GMT

I have difficulty putting line break in a text within a table

$section->addTextBreak(8);


and to use within the table would look like ?



New Post: TemplateProcessor -> Set Checkbox Value

Mon, 04 Jan 2016 16:55:37 GMT

Hello,

could somebody tell me, how to set the Checkbox value in a template file with the TemplateProcessor .php.

Thank's
Beys
Frank Dörsam



New Post: how to read a word file and save him in pdf?

Mon, 30 Nov 2015 14:45:26 GMT

The User climbed one word file and the system will save it in pdf which the code to make risso downloaded the version = PHPWord_0.6.2_Beta.zip

if anyone able to help me with the code and dependencies I thank



New Post: Html to .docx (ol, li, p, span)

Mon, 09 Nov 2015 11:59:20 GMT

Hello,
I'm using PHPWord to generate .docx words, from HTML.
I have the following situation:
  1. I'm directly inside the LI tag
  2. I'm directly inside the SPAN tag
  3. I'm directly inside the SPAN tag... SPAN is inside P tag

The content of the 2nd and 3rd LI, doesn't render. It shows a blank content in the .docx.

I tried render the SPAN tag changing the parseChildNodes():
$cNodes = $node->childNodes;
            if (count($cNodes) > 0) {
                foreach ($cNodes as $cNode) {              
                    // Added to get tables to work                    
                    $htmlContainers = array(
                        'span'
                        
                    );
                    if (in_array( $cNode->nodeName, $htmlContainers ) ) {                        
                        self::parseNode($cNode, $element, $styles, $data);
                    } else{                    
                        // All other containers as defined in AbstractContainer
                        if ($element instanceof AbstractContainer) {                        
                            self::parseNode($cNode, $element, $styles, $data);
                        }
                    }  
                }
            }



New Post: Create a text with a newspaper style (sample 05 is not working)?

Tue, 22 Sep 2015 18:16:22 GMT

I'm Trying use the sample 05 on phpword to create a text with Multi Columns (like a newspaper).

The sample here:

https://github.com/PHPOffice/PHPWord/blob/develop/samples/Sample_05_Multicolumn.php#L1

But using the sample 05 is not working, an error appears saying

"Call to a member function addSection() on null"

Can somebody give me a another example to how to do this?


This is my code:

require_once 'PHPWord.php';
 // New Word Document
 $PHPWord = new PHPWord();

 // New portrait section
  $section = $PHPWord->createSection();



 // Two columns text
     $section = $phpWord->addSection(
         array(
        'colsNum'   => 2,
        'colsSpace' => 1440,
        'breakType' => 'continuous',
      )
);


$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing.", ENT_COMPAT, 'UTF-8'));




// Save File
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('AdvancedTable.docx');

Thanks.



New Post: Adding Tab-spaces to Word documents

Fri, 24 Jul 2015 10:37:39 GMT

I cannot seem to find any examples of how to add tab-spaces to the document using PHPWord.
Can anyone assist with some example code?



New Post: Images in Templates

Tue, 07 Jul 2015 17:06:30 GMT

add in Template.php class :

public function replaceStrToImg( $strKey, $arrImgPath ){
        $strKey = '${'.$strKey.'}';
        if( !is_array($arrImgPath) )
            $arrImgPath = array($arrImgPath);
        
        $rels = $this->_objZip->getFromName('word/_rels/document.xml.rels'); 
        $types = $this->_objZip->getFromName('[Content_Types].xml'); 
        
        $count =  substr_count($rels, 'Relationship') - 1;
        $relationTmpl = '';
        $imgTmpl = '';
        $typeTmpl = ' ';
        $toAdd = $toAddImg = $toAddType = '';
        $aSearch = array('RID', 'IMG');
        $aSearchType = array('IMG', 'EXT');
        
        foreach($arrImgPath as $index => $img ){
            $imgExt = array_pop( explode('.', $img) );
            if( in_array($imgExt, array('jpg', 'JPG') ) )
                $imgExt = 'jpeg';
            $imgName = 'img' . ( time() + $index ) . '.' . $imgExt;
            $rid = 'rId' . ($count + $index);
            
            $this->_objZip->addFile($img, 'word/media/' . $imgName);
            
            $toAddImg .= str_replace('RID', $rid, $imgTmpl) ;
            
            $aReplace = array($imgName, $imgExt);
            $toAddType .= str_replace($aSearchType, $aReplace, $typeTmpl) ;
            
            $aReplace = array($rid, $imgName);
            $toAdd .= str_replace($aSearch, $aReplace, $relationTmpl);
        }
        
        $this->_documentXML = str_replace( '' . $strKey . '', $toAddImg, $this->_documentXML);
        $types = str_replace('', $toAddType, $types) . '';
        $rels = str_replace('', $toAdd, $rels) . '';
       
        $this->_objZip->addFromString('word/_rels/document.xml.rels', $rels);
        $this->_objZip->addFromString('[Content_Types].xml', $types);
        $this->_objZip->addFromString('word/document.xml', $this->_documentXML);
    }


use example:

$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate($template);
$arrImagenes =  array(
    '../../images/mc.png',
    '../../images/logo.png',
    '../../mineria/image/logo.jpg',
    '../../images/draw-icon.png'
    
);
$document->replaceStrToImg('AreaImg', $arrImagenes);
$documentName = 'Concepto_Tecnico_' . date('Ymd_His') . '.docx';
$document->save( $documentName);