Add Export to Word Support

Created on 25 May 2016, about 8 years ago
Updated 14 April 2024, 2 months ago

@benjy Is this something that you would consider for this module. I developed a custom module, for a Drupal 8 application at work, that uses the PHPWord (https://github.com/PHPOffice/PHPWord) project to allow Users, determined by role(s)/permission(s), to export Node entities to a Word document. There were some assumptions that I was able to make in my custom module because I knew that this module would, likely, only be used on that project. That being said, I think that I could use some of the code of that module, along with my recent familiarity of Entity Print, to get us started on the path to this feature. I could implement it in a similar manner to the PDF libraries currently in Entity Print so that the codebase remains modular and extensible.

Let me know what you think. I am completely open to your thoughts and suggestions.

If we are able to combine forces with the Print (and Printable) projects, I think that we will want to want to support EPUB and email. We already have a task for email support.

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇺🇸United States jordanpagewhite

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France Julien Tekrane

    Based on #61, I added the fact if no is present.

  • 🇺🇸United States SocialNicheGuru

    I do not see any of the settings when I select the Word Docx library.

  • 🇮🇳India Abhinand Gokhala K

    I have applied the patch and selected the engine for word export.

    But got this error while exporting the entity as a Word doc.

    TypeError: Cannot assign array to property DOMDocument::$preserveWhiteSpace of type bool in PhpOffice\PhpWord\Shared\Html::addHtml() (line 83 of

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    54 pass
  • 🇵🇱Poland piotrsmykaj

    Added the output escape option.

  • 🇧🇪Belgium seutje Antwerp

    When I try to set the Word Document engine to Word Docx and submit the settings form, I am greeted with the following error on Drupal 9.5.4 on PHP 8.0.27:

    TypeError: Illegal offset type in Drupal\Core\Entity\EntityStorageBase->load() (line 297 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
    Drupal\Core\Entity\EntityStorageBase->load(Array) (Line: 262)
    Drupal\entity_print\Form\SettingsForm->loadConfigEntity(Array) (Line: 214)
    Drupal\entity_print\Form\SettingsForm->validateForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 82)
    Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 275)
    Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'entity_print_admin_settings_form') (Line: 118)
    Drupal\Core\Form\FormValidator->validateForm('entity_print_admin_settings_form', Array, Object) (Line: 591)
    Drupal\Core\Form\FormBuilder->processForm('entity_print_admin_settings_form', Array, Object) (Line: 323)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

    I assume there's something missing in entity_print.schema.yml.

  • 🇪🇸Spain guardiola86

    entity-print-2733781-export-word-72.patch isn't working for me, I get this error:

    Drupal\Component\Plugin\Exception\PluginNotFoundException: The "Array" plugin does not exist. Valid plugin IDs for Drupal\entity_print\Plugin\EntityPrintPluginManager are: tcpdfv1, phpwkhtmltopdf, dompdf, word_docx in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of /var/www/html/docroot/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).
    
  • 🇪🇸Spain guardiola86

    actually it works, but it breaks this page on submit: /admin/config/content/entityprint

  • Patch #72 caused these errors on saving default `Word Document` at /admin/config/content/entityprint

    TypeError: Illegal offset type in Drupal\Core\Entity\EntityStorageBase->load() (line 263 of
     pathto\web\core\lib\Drupal\Core\Entity\EntityStorageBase.php).

    Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 278 of pathto\web\core\lib\Drupal\Core\Entity\EntityStorageBase.php).

    form Error The submitted value 1 in the Word Document element is not allowed.

    Drupal 10.1.2
    entity_print 8.x-2.x-dev
    php 8.1.10

  • 🇺🇸United States rimbu002

    Patch 72 on entity_print:2.x-dev on Drupal 9.5.10 and PHP 8.1.21 add the Word Docx engine, but saving the configuration at admin/config/content/entityprint produces 3 errors

    1. TypeError: Illegal offset type in Drupal\Core\Entity\EntityStorageBase->load() (line 297 of /mnt/www/html/umnpcid8stg/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
    2. Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 312 of /mnt/www/html/umnpcid8stg/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
    3. Illegal choice 1 in Word Document element.

  • 🇺🇸United States rimbu002

    Patch #72 on entity_print:2.x-dev, Drupal 9.5.10 and PHP 8.1.21 adds the Word Docx engine, but saving the configuration at admin/config/content/entityprint produces 3 errors

    1. TypeError: Illegal offset type in Drupal\Core\Entity\EntityStorageBase->load() (line 297 of /mnt/www/html/umnpcid8stg/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
    2. Warning: array_flip(): Can only flip string and integer values, entry skipped in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 312 of /mnt/www/html/umnpcid8stg/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php)
    3. Illegal choice 1 in Word Document element.

  • Status changed to Needs work 8 months ago
  • 🇺🇸United States hmohan

    I get the same errors as rimbu002 mentioned. Is there any update on this?

    Thanks

  • I'm working with Patch #72 on entity_print:2.x-dev, Drupal 10.2.1 and PHP 8.1.26.

    After installing phpoffice/phpword:^1.0 per installation prompts, I set the Word engine, but threw a "The website encountered an unexpected error. Try again later." error on the config page that would not clear. I uninstalled both Entity Print and Entity Print Views, then reinstalled. Now I can't set the word engine at all - when I click save, it throws the same error on the page, but while I can now refresh, none of the changes are saved.

    This produces similar errors to the previous folk, with some differences:

    TypeError: Illegal offset type in Drupal\Core\Entity\EntityStorageBase->load() (line 263 of /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

    Warning: Array to string conversion in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 281 of /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php)

    The submitted value 1 in the Word Document element is not allowed.

  • I retried Patch #72 after upgrading to Drupal 10.2.2. Now I'm down to 1 error:

    TypeError: Cannot access offset of type string on string in Drupal\Component\Utility\NestedArray::setValue() (line 155 of /code/web/core/lib/Drupal/Component/Utility/NestedArray.php).

    Looking at the console inspector, I also found the following (which does not exist without the patch):

    [DOM] Found 2 elements with non-unique id #edit-submit: (More info: https://goo.gl/9p2vKq) <input data-drupal-selector=​"edit-submit" type=​"submit" id=​"edit-submit" name=​"op" value=​"Save configuration" class=​"button button--primary js-form-submit form-submit">

  • I'm back to the errors I reported in #80 Add Export to Word Support Needs work .

    Has anyone found a solution yet?

  • patch #72 throws the error as reported above.

    However, I did get it to work like this, clearly a workaround.

    1) Install entity_print and the word engine.
    2) Install patch #69
    3) configure the word print-engine in the interface.
    4) SAVE
    5) (if you print now, it has the previous errors as reported in #71)
    6) NOW after you turned on the engine, SWITCH the patch to #72.
    7) If you visit the configuration page, it still shows the engine as turned on, with an extra config.
    8) Now you can print the doc.

    So the point is: you must have the word print engine installed and set in the intetface BEFORE you install patch #72.

    Clearly only a workaround.

  • Took me a while to circle back, but #83 works great. Thanks so much.

Production build 0.69.0 2024