Download any Moodle report as a Word document

Moodle downloads tables as CSV, Excel, ODS, HTML, JSON and PDF, not Word. Our free dataformat_docx plugin adds Microsoft Word (.docx) to every download menu.

Drawing of a blue spreadsheet grid with an arrow pointing to a sheet of paper holding a table with a grey header row.

Short answer: Moodle’s “Download table data as” menu offers CSV, Excel, OpenDocument, HTML, JSON and PDF. There is no Word option, so a report that has to end up in a document people edit goes through Excel and copy and paste. Our free plugin, dataformat_docx, adds Microsoft Word (.docx) to that menu everywhere Moodle shows it: custom reports, participants, logs, grade history, activity reports and other plugins’ tables.

This is the twenty-ninth plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works. The plugins directory has Markdown and XML data formats. Its Word plugins import into question banks, books and lessons, but none add Word to the download menus.

What the Word file looks like

  1. Open any report or table with a download menu, choose Microsoft Word (.docx) and press Download.
  2. You get one Word table with borders and a shaded header row.
  • The header row repeats at the top of every page, and rows never split across two pages.
  • Tables with seven or more columns get landscape pages.
  • Line breaks inside a cell are kept.
  • Arabic, Hebrew and other right-to-left text is set right to left cell by cell, so a name in Arabic reads correctly even on an English site. On a site in a right-to-left language the whole table runs right to left.
  • Scheduled custom reports can send it as a Word attachment too.

There are no settings. It supports Moodle 4.5 LTS to 5.3. The code is on GitHub.

How a Moodle data format works

From Moodle 5.3’s data format code (the same API as 4.5):

  1. A data format is one class, writer, that Moodle drives in a fixed order: start the file, start a table with the column names, write each row, close the table, close the file. Whatever the writer prints is the download. Moodle finds it by name, so it shows up in every download menu with no other registration.
  2. Saving to a file (scheduled reports, files stored in Moodle) uses the same steps. By default Moodle collects the printed output in memory and saves it at the end. A Word file is a zip, so ours writes rows to a temporary file as they come and zips once at the end. Memory stays flat on a 50,000-row log.
  3. Word is stricter than most readers about the order of elements in its XML. One table setting in the wrong place and Word says the file is damaged, while LibreOffice opens it fine. We wrote the parts in the order the format requires and checked the output by rendering it.

The browser tests open a custom report without JavaScript, check that Word is in the download menu, download it, and check the admin list of data formats. Unit tests open the file and check the table, the repeating header, escaping of <, & and quotes, removal of characters Word rejects, line breaks, landscape pages, right-to-left cells and headings. With the cleaning step taken out, two of them fail.

Need a plugin like this for your own Moodle?

Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.

Open DevLMS Studio