Code Monkey home page Code Monkey logo

phpword's People

Contributors

0b10011 avatar ahrens-sven avatar carusogabriel avatar csk83 avatar dependabot[bot] avatar gabrielbull avatar hazington avatar hskrtich avatar ivanlanin avatar jeroenmoors avatar jhfangying avatar jonnsn avatar kernusr avatar liborm85 avatar lubosdz avatar manunchik avatar mariahaubner avatar mussbach avatar nicoder avatar oleibman avatar powerkiki avatar progi1984 avatar sailormax avatar sergeizelenyi avatar shaedrich avatar simivar avatar spikex avatar terryzwt avatar trainmaster avatar troosan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpword's Issues

Ability to limit number of replacements performed by setValue() method of Template class

Sometimes we need to replace only several string occurrences in text. Current implementation of the corresponded method of Template class looks like as followed

/**
 * Set a Template value
 *
 * @param mixed $search
 * @param mixed $replace
 */
public function setValue($search, $replace)
{
    ...

    $this->_documentXML = str_replace($search, $replace, $this->_documentXML);
}

This gives us no chance to replace, for example, the first occcurrence only.

This issue is a proposal of setValue method inhancement by implementing the followed signature:

/**
 * Set a Template value
 *
 * @param mixed $search
 * @param mixed $replace
 * @param integer $limit
 */
public function setValue($search, $replace, $limit = -1) {
    ...
}

Cannot use variables in header / footer for template

I'm using the loadTemplate() function to set values in a template.
It works great except for values that are in header / footer. They're not replaced

The reason is because PHPWord only replaces values in the body, and not in the header / footer.

It has been quoted here, with a patch to make it work:
http://phpword.codeplex.com/discussions/236472

with a more generic way here: https://phpword.codeplex.com/workitem/69

Would be nice to have this feature in the official PHPWord :)

Anywhere position image

We need new feature for text/image wrapping. Today is very difficult align images.

maybe I can fork this project and contribute to it.

someone already did it?

Create develop branch

Unstable version should not be the master branch but another branch named develop.

addTextBreak styling?

textBreak's don't seem to follow any sort of style. I could be wrong. I'd like to think it'd follow a paragraphStyle or the last textStyle used. textBreaks for my document seem to large.

rights after creating Sample_02_TabStops.php

After doing Sample_02_TabStops.php

i got:
luuk@opensuse:~/public_html/PHPWord-master/samples> ll Sample_02*
-rw-r--r-- 1 luuk users 8309 jan 4 18:31 Sample_02_TabStops.docx
-rw-r--r-- 1 luuk users 3052 jan 4 18:31 Sample_02_TabStops.odt
-rwxrwxr-x 1 wwwrun users 1807 dec 17 11:45 Sample_02_TabStops.php
-rw-rw-r-- 1 wwwrun users 307 jan 4 18:31 Sample_02_TabStops.rtf

Is it not odd that the docx and odt file are created with user-rights, and that the rtf includes the group rights?

row span?

how do I create cells with rowspan more than 1?

Example in README.md is broken

The readme file refers this example:
$myTextElement->setBold();
$myTextElement->setName('Verdana');
$myTextElement->setSize(22);

However these functions are (no longer?) implemented. I'm not sure if they should be implemented or if the example should be changed.

Postprocessing of documents returned by Template class before moving to final destination

Currently, Template class has the "save()" method with the followed signature.

/**
 * Save Template
 *
 * @param string $strFilename
 */
public function save($strFilename)
{
    ...
}

In most cases that's fine, but in some situations this approach it's not optimal enough.

For example, we have a batch of templates and we need to perform the followed actions with them.
a) Substitute macroses in each template.
b) Pack all the result documents in ZIP-archive and move this archive somewhere.

In such situtation Template class of current implementation allows us to do this, but it will require to save processed templates somewhere which involves unnecessary file copying. Moreover, we will have to delete these garbage files after archiving.

So, suggestion is to give options.

  1. To save the processed template in the current location (temporary directory) with it's current unique name. This allows user to do whatever he wants with the document in temporary directory before the file will be moved to final destination.
/**
 * Save Template
 *
 * @return string
 */
public function save() {
    ...
}
  1. To save the processed template in the user defined location with user defined filename.
/**
 * Save Template As...
 *
 * @param string $strFilename
 */
public function saveAs($strFilename) {
    ...
}

Change setIndent and setIndentString to be more compatible

The files PHPWord create seem to be malformed for OpenOffice because PHPWord formats the xml with spaces and newlines. Word removes this lines and shows the document how its supposed to be, but OO inserts a newline for every newline in the xml-doc in the document is shows. Changing these line in Shared/XMLWriter.php fix this.

$this->_xmlWriter->setIndent(false);
$this->_xmlWriter->setIndentString('')

There is a comment in the code saying this might need to be turned off for production.

Namespacing

Should the namespacing be done like this:

namespace PHPWord;

class PHPWord
{}

which will result in using the lib like this: new PHPWord\PHPWord();

OR

namespace PHPOffice\PHPWord;

class PHPWord
{}

which will result in using the lib like this: new PHPOffice\PHPWord\PHPWord();

Both of which are PSR-0 and PSR-4 compliant.

Word2007 writer does not reset PHPWord_Media::_sectionMedia

I'm using the GIT branch "custom-numbered-lists" of your PHPWord code.
I'm generating several docx documents in a row inside my php module. The documents contain images. I realised that when generating the second document the PHPWord_Writer_Word2007 tried to access the images of the first document. I think this is due to the fact that the static information in PHPWord_Media is not reset.
I wrote a simple reset function and now everything works as expected.

public static function resetMedia() {
    self::$_sectionMedia = array(
            'images' => array(),
            'embeddings' => array(),
            'links' => array());
    self::$_headerMedia = array();
    self::$_footerMedia = array();
}

I suppose such a method should actually be called when calling
PHPWord_IOFactory::createWriter(..., 'Word2007');

I don't know if this also affects other branches of the code.

Suport on table rowspan e colspan

First I want to say congratulations on the project too. Now one thing that was sorely lacking in the styles used in the table was colspan and rowspan properties because they are widely used in creating tables. Now if you go as a way to debug irrei also assist in this project because it is of much interest

Add Github Pages

Duplicate PHPOffice/PHPExcel pages and adapt them for PHPWord

Mission to 1.0.0

WPS Writer (#69), Daisy XML Writer (#54), and ePub2 Writer (#55) will be implemented later.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Implement Daisy XML Document (DTBook)

Link :

Format :

Validator :

Samples :

ToDo :

  • Implement basic features (text, tables, images)
  • Validate locally
  • Unit Tests
  • Validate files with Travis-CI
  • Documentation (Differences with others format, Specifications for the Daisy Format)

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

UTF8 encoding

I cannot use UTF8 signs, like " ' " or โ‚ฌ, but get a ? instead.

Restart ListItem Numbering

Is there a way to restart the ListItem numbering (lettering)?

Using this code snippet:

$numberStyleList = array('listType' => \PHPWord_Style_ListItem::TYPE_NUMBER);
$alphStyleList = array('listType' => \PHPWord_Style_ListItem::TYPE_ALPHANUM);

$section->addListItem('One', 0, null, $numberStyleList);
$section->addListItem('Two', 0, null, $numberStyleList);
$section->addListItem('Alpha', 1, null, $alphStyleList);
$section->addListItem('Beta', 1, null, $alphStyleList);
$section->addListItem('Three', 0, null, $numberStyleList);
$section->addListItem('Charlie', 1, null, $alphStyleList);

Currently it would output this:

1. One
2. Two
   A. Alpha
   B. Beta
3. Three
   C. Charlie

I want to output this:

1. One
2. Two
   A. Alpha
   B. Beta
3. Three
   A. Charlie

Is there some other code call that needs to be made? Or is this a limitation of PHPWord?

Alignment footer PreserveText

Alignment of the PreserveText can only be done by entering an emty fontstyle array.
Leaving out the fontsyle array will result in left alignment of the text.

Adding a value that contains "&" in a template breaks it

I'm using the template stuff in order to replace some values, but the following code breaks the template (anything in the template after the & symbol is not shown):

        $document = $PHPWord->loadTemplate($templatePath);
        $document->setValue('type', "some value & foobar");

I guess the & is a specific character in xml word files, like it can be in html

The workaround I'm currently using is to wrap the value into an htmlspecialchars and all is ok afterwards:

        $document = $PHPWord->loadTemplate($templatePath);
        $document->setValue('type', htmlspecialchars("some value & foobar"));

=> why not add this htmlspecialchars right into the setValue function ?

Thanks for your feedback

Implement HTML reader

On the odd occasion you want to turn some HTML into a PHPWord object, it would be nice to have a utility for doing so.

Ability to apply XSL style sheet to Template

Sometimes we need to perform more complex actions with document template than just simple replace of ${} parameters. XSLT really helps in such situations.

This issue is a proposal of the correspondent class method implementation with the followed signature.

/**
 * Applies XSL style sheet to XML template.
 *
 * @param DOMDocument &$xslDOMDocument
 * @param array $xslOptions = array()
 * @param string $xslOptionsURI = ''
 */
public function applyXslStyleSheet(&$xslDOMDocument, $xslOptions = array(), $xslOptionsURI = '')
{
    ...
}

Assumption: we have XSL style sheet loaded as DOMDocument before the method call.
Requirement: "php_xml.dll" library.
Limitation: XSLT 1.0, XPath 1.0 (because of XSLTProcessor).

Temporary files naming logic in PHPWord_Template can lead to a collision

Temporary files naming logic in PHPWord_Template can lead to a collision

The problem is in the followed peace of code:

public function __construct($strFilename) {
    $path = dirname($strFilename);
    $this->_tempFileName = $path.DIRECTORY_SEPARATOR.time().'.docx';

    copy($strFilename, $this->_tempFileName); // Copy the source File to the temp File

    $this->_objZip = new ZipArchive();
    $this->_objZip->open($this->_tempFileName);

    $this->_documentXML = $this->_objZip->getFromName('word/document.xml');
}

As we may see, temporary files are named using "the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)". In this case, if we have several requests per one second, the code will generate us files with exactly the same names, and that may lead to some confusions. So, we need to generate really unique filenames. tempnam() function meets this requirement.

Moreover, according to ETL, it's not correct to transform data right in the source we extract this data from. But this is what the peace of code does while creating temporary file in the datasource directory. It's not correct to generate temporary files in the destination directory too. There may be tons of such destination directories and, in case of bugs in our code, they may be populated with garbage temporary files. So, we need separate temporary directory for our temporary files, which allows us easily maintain it's content (when deal with garbage). sys_get_temp_dir() function meets this requirement.

Finally, what we need to do is to correct couple lines of code. :)

Implementing textRuns in RTF & ODT Writer

$this->_writeTextRun($objWriter, $element);
is not yet implemented, in both (basic) writers.

Unfortunately the HTML to docx Converter (http://htmltodocx.codeplex.com/) makes heavy use of textruns, so if you want to export userinput, made by a WYSIWYG Editor, to .rtf or .odt, there is currently no possibility for that.
So implementing at least this function would make the 2 writers become more usefull...

thx!
sahib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.