Quantcast
Channel: PHPWord
Viewing all 450 articles
Browse latest View live

New Post: Pb with $document->setValue(‘Value1′, ‘Name on the first row’);

$
0
0
Hi every body,

This evening i'am in trouble with the flwg :

instead of using
$document->setValue(‘Value1′, ‘Name on the first row’);
i want to change to
$document->setValue(‘first_name′, ‘Name on the first row’);
and i put in the template ${first_name} ==> error and no word document save!

How can i circumnavigate this pb to achieve what i want, i've a doc in which i include (i want to) about 190 MySql column data i'd prefer to use, in php script, the native MySql column name instead of value1... value190 !

New Post: Pb with $document->setValue(‘Value1′, ‘Name on the first row’);

New Post: Pb with $document->setValue(‘Value1′, ‘Name on the first row’);

$
0
0
I am a bit confused as to what your problem is. Is it that your word document does not save? Or is it that there is no output?

New Post: How to create fields in Word for PHPWord template

$
0
0
Hi

How do I create fields in Word in order to change the value of it in PHPWord? I tried to use Insert->Quickparts->Comments but that doesn't work. I use Word 2007.

This is my code to change the value:
$filename = 'joren.docx';
$PHPWord = new PHPWord();
$template = $PHPWord->loadTemplate('files/cv/test.docx');
$template->setValue('field1', 'Somebody someone');
$template->save('files/cv/'.$filename);

$downlink = 'files/cv/'.$filename;
header("Content-type: application/vnd.ms-word");
header("Content-disposition: attachment; filename=".$filename.";");
header('Content-Length: '.filesize($downlink));
header("Pragma: no-cache");
header("Expires: 0");
ob_clean();
@readfile($downlink);

New Post: How to add a table where img

New Post: Pb with $document->setValue(‘Value1′, ‘Name on the first row’);

$
0
0
how do I create the field in word ?
i have tried to set a DOCPROPERTY, DOCVARIABLE.
the phpword does not declare what is required exactly so left a bit uncertain.

New Post: Inserting multi-line text in table cell

$
0
0
basically same solution here:

This is taking advantage of the fact that ->addText adds a newline. (which some people don't want anyway, but in this situation, it's used to achieve the desired result)
  $positionTitleArray = explode("\n", $positionTitle);
  foreach ($positionTitleArray as $positionLine) {
    $cell->addText($positionLine, null, $tableSpace);
  }

New Post: Row index Reset

$
0
0
When you tab to a new page, this reset the count on first row and then continue with the normal count

like show in this image:
Image

so in the second page in the first row start in 0 but the second row continue normally the count

I need the count rate usually when jumping a following page, how I can know if the document to jump from one page to the next? or some help for these issues


my code:
 $PHPWord = new PHPWord();
    $res = $system->getOrderByCostumer($_POST["start"], $_POST["end"]);
    $section = $PHPWord->createSection();
    $table = $section->addTable();
    $array = $function->getArrayDoc($res);

    for ($index = 0; $index < count($array); $index) {

        $table->addRow();
        for ($c = 1; $c <= 4; $c++, $index++) {


            $table->addCell(1750)->addText(isset($array[$index]) ? $index : '');
        }
    }



    header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8');
    header("Content-Disposition: attachment;filename='" . $dateNow . ".docx'");
    header('Cache-Control: max-age=0');
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
    $objWriter->save('php://output');

New Post: add header in current word file

$
0
0
i want add header when load a word file,but try more again,not success always,someone help me?thanks.

New Post: Template SetValue not replacing in Word 2010

$
0
0
I have got the same type of problems.
And I cannot find any valid response in this forum.

It is very very unclear to me what exactly I need to create in Word in order to get the setValue populated.

is it a DOCVARIABLE, DOCPROPERTY, ${testValue}, ...
the documentation is far from complete i.e. an a to z explication is missing.

I hope that someone picks this up very soon. I cannot wait that much longer and am looking at alternative products that might fullfil our requirements if this does not get clarified.

P.

Created Unassigned: CLONEPART FUNCTION (Repeat part of Template) [56]

$
0
0
Good morning my friends!

  I'm posting here a code that I created to use the while to repeat part of the document between two tags. Sorry for my English, I'm using a translator

  Note # 1: The beginning and the size of substr I made based on the XML document, taking care not to cut through the xml tags. This still needs to be improved so that does not depend on changes in this case funcioanaria with a portion of the document, but can be pulled inside the function by placing the counter. eg clonePart ('[tags]', '[tage]', $ num, 120.14). If someone can help me improve this code so grateful that it becomes automated.

  Note # 2: This code will create a numbering in all variables according to the number of copies, so you can access all the variables of all copies, see the example after the code.
 
  IMPORTANT: This code is not yet optimized, but it works. He was inspired by the code cloneRows made ​​by Jeroen Moors (http://jeroen.is/phpword-templates-with-repeating-rows/) that can even be used together as I myself. Any doubts do whatever possible to help!

Add to Template.php
```
public function clonePart($start, $end, $numberOfClones){
$string = $this->_documentXML;
$ini = strpos($string,$start);

if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;

$part = substr($string,$ini,$len);
$part = substr($part,18,(strlen($part)-237)); //Note #1
$partJN = '';

for ($i = 1; $i <= $numberOfClones; $i++) {
$partJN .= str_replace('OT}','_'.$i.'}',$part); //Note #2, this is used to put numbers to variables, OT is a anchor, exemple: ${nameOT} turn to ${name_1} ${name_2}...
}

$this->_documentXML = str_replace('[STApart]','',$this->_documentXML); //Erase Tag
$this->_documentXML = str_replace('[ENDpart]','',$this->_documentXML); //Erase Tag
$this->_documentXML = str_replace($part,'',$this->_documentXML); //Erase Original Part Because doenst have count

$partJN = utf8_decode($partJN);
$this->setValue('reportone',$partJN); //Place Content to a Variable (in this case ${reportone}
}
```

Mysql use exemple:

```
$NUM = num_rows;
clonePart('[mystarttag]', '[myendtag]', $NUM);
$i=1;

while($FET){
$doc->SetValue('name_'.$i,$FET['name']);
$i++;
}
```

New Post: Duplicate Part of an document

Commented Unassigned: page orientation [54]

$
0
0
is it possible change page orientation?
Comments: $section = $PHPWord->createSection(array('orientation'=>'landscape'));

Commented Issue: Advanced string replace in setValue [49]

$
0
0
When started using Phpword it saved me a lot of time as i needed to replace a template in docx using php. I had a minor issue when started using the setValue method. I found that using Word, the program creates some tags that the str_replace couldn't detect.

I cracked a little bit the function, using some regular expressions in order to:
1. Find the regular expressions commencing with '${' and ending with '}' (in my case i dropped the $ sign cause i needed to use the $ sign in my word file)
2. With only that string, find and eliminate all the opening tags
3. find and eliminate the closing tags in that string
4. replace the old string (with garbage code) with the cleaned string
5. output the _documentXML

this is the piece of code I implemented if anyone is interested

Btw, great job with this tool it saved me a lot of time!

public function setValue($search, $replace) {
$pattern = '|\{([^\}]+)\}|U'; //if you need the $, use: '|\$\{([^\}]+)\}|U''
preg_match_all($pattern, $this->_documentXML, $matches);
$openedTagPattern= '/<[^>]+>/';
$closedTagPattern= '/<\/[^>]+>/';
foreach ($matches[0] as $value) {
$modificado = preg_replace($openedTagPattern, '', $value);
$modificado = preg_replace($closedTagPattern, '', $modificado);
$this->_documentXML = str_replace($value, $modificado, $this->_documentXML);
}

if(substr($search, 0, 1) !== '{' && substr($search, -1) !== '}') { //change to: substr($search, 0, 2) !== '${' if you need the $ character
$search = '{'.$search.'}'; //change to '${'.$search.'}' if $ needed
}

if(!is_array($replace)) {
$replace = utf8_encode($replace);
}

$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
}
Comments: Hey !! Thanks a lot for this. still , I have a problem with the new line ('\n') character. I tried to replace '\n' with word break - $template = str_replace("\n","<w:br/>",$template); but i think it wouldn't match with above changes. Do you have any solution for the new line ?

New Post: How to add Image for template?

$
0
0
Hi all,

I am new for PHPWord, I am trying to adding the image in my existing file.
I used for that the loadTemplate(), and addImage().

Can any one help me how to add that image in my template file?

its urgent for me.

New Post: how to merge the two file in PHPword?

$
0
0
Hi all,

can any one tell me how to merge two .docx file in one .docx file?


Thank you in advance.

New Post: Load Preformatted File and Enter Data

$
0
0
I have a client that needs excel files and word files generated dynamically from data in the database. I used PHPExcel for the excel files and it works great.

I now need to load a preformatted file just like I did in PHPExcel using the filereaders. Here is my code but it does not load the file.
//generate word file for gwentries
$PHPWord = new PHPWord();
$document = $PHPWord->loadTemplate(APPPATH.'files/gwsw.doc');

// save file
$wordWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$wordWriter->save('files/test.doc');
Any help would be great. Thanks

New Post: Load Preformatted File and Enter Data

$
0
0
It does generate the file "test.doc" but the file is completely empty.

New Post: Template SetValue not replacing in Word 2010

$
0
0
patrickvdbemt wrote:
I hope that someone picks this up very soon. I cannot wait that much longer and am looking at alternative products that might fullfil our requirements if this does not get clarified.
I am in the same boat. There is no documentation anywhere saying how the word file should be set up. Is it a field or just text? Who knows. The documentation for PHPWord is very disappointing after using PHPExcel which was a great product.

I can load the template and create a new file with it but setValue() does absolutely nothing.

Very frustrating.

New Post: setValue() broken

$
0
0
here is my php code:
$PHPWord = new PHPWord();
$template = $PHPWord->loadTemplate(APPPATH.'files/test.docx');
$template->setValue('test1', 'hello');
$template->setValue('test2', 'whats');
$template->setValue('test3', 'up');
$template->setValue('test4', 'koby');
$template->setValue('test5', '!!!!!!');
$template->save('files/test.docx');
here is my word document text:

${test1}
${test2}
${test3}
${test4}
${test5}

The output word content:

hello
${test2}
${test3}
${test4}
${test5}

setValue(); only sets the value for the first line ${test1}

Any help would be great
Viewing all 450 articles
Browse latest View live