PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.24k stars 2.69k forks source link

Problems downloading doc Error in content #1372

Closed eulemis closed 6 years ago

eulemis commented 6 years ago

This is:

Expected Behavior

Document can be opened

Current Behavior

when downloading the file the word tells me that the content of the file is damaged if I give it that I accept the risks it opens me without problems how to correct this problem?

Failure Information

if I remove these lines does not give me the warning

How to Reproduce

<?php
require __DIR__ . '/vendor/autoload.php';

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$textrun = $section->addTextRun();
$textrun->addText($num.'.'.$texto1);
$textrun->addText(htmlspecialchars_decode($titulo), ['italic' => true]);
$textrun->addText(htmlspecialchars_decode($texto2);

Context

troosan commented 6 years ago

what is the text you are trying to add?

eulemis commented 6 years ago

Thanks for answering what I show are some bibliographical references, that come in an array which I cross and I separate to be able to give the cursive style to the titles and then I show with addListItemRun a list of each reference. this is the string array that I receive in a method

result:{,…}
0: "Hernandez, E. A. (2011). :Capitulo I- El Renacer de un mejor pais:. En Palacios, J.(Ed/s.). El Bachaqueo en venezuela (pp.500). Valles del Tuy: Edit. Rombo."
1:"Hernandez, E., Camaro, L., Lopez, N., Sanchez, J. F. y Sanchez, M.L.  (s.f). :El Renacimiento:. Valles del tuy: renacer."
2:"Sanoja, T. (1990). :Emprendimiento en tiempo de crisis:. Valles del tuy: Renacer."
3:"Dominguez, K. (2010). :El Despertar:. Program ade superacion: lunes."
4:"Hernandez, S.E.  (1988). :TodospodemosconDios:. Contruye: ."
5:"El libro sin autor.(2012). Valles del tuy: Renacer."

And this is the function that runs through that string array

foreach($refer as $r){
            $arrDivTitulo = explode(':', ($r));

            $texto1 = $arrDivTitulo[0];
            $titulo = $arrDivTitulo[1];
            $texto2 = $arrDivTitulo[2];

            $listItemRun = $section->addListItemRun();
            $listItemRun->addText(htmlspecialchars($texto1), array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::DISTRIBUTE));
            $listItemRun->addText(htmlspecialchars($titulo), array('italic' => true));
            $listItemRun->addText(htmlspecialchars($texto2), null, array('keepNext' => true, 'indentation' => array('firstLine' => 340)));
        }
troosan commented 6 years ago

this works fine, except that your entry 5 does not contain a :

eulemis commented 6 years ago

Excuse me but what is the entrance 5, I do not understand much the answer, maybe I'm dull with so many attempts could clarify me?

eulemis commented 6 years ago

Excuse me again, I saw what he was referring to in Array 5, I corrected him and it worked, thank you very much. God bless you.