DocxEditor
Version 1.0.0 (36.6 KB) by
Dirk-Jan Kroon
Replace text / images in a Microsoft Word .docx file, no dependencies
DocxEditor, can be used to Replace text / images in a Microsoft Word .docx file. Example usage, is a template of a report with some default text and images which are replaced to generate a report in a certain style.
It has no dependencies, no Microsoft Word, no toolboxes, it simply unzips, the .docx uses Matlab's xml functions to manipulate the files, and then zips it back to a .docx file.
Example code:
editor = DocxEditor('template.docx';);
editor.replaceBatch({ ...
"%footer_text%", 'footer noise template';
"%header_text%", 'header noise template';
"%title%", 'Noise Template';
"%cell1%", 'Table cell left';
"%cell2%", 'Table cell right';
"%first%", 'first bullet point';
"%second%", 'second bullet point';
"%second_page%", 'second page' ...
});
im = uint8(rand(256,256,3)*255);
im_std = std(single(im(:)));
editor.replaceText("%mainstd%", sprintf('%0.5f', im_std));
editor.replaceText("%figure1%", 'color noise');
filenames_images = editor.listImages();
editor.replaceImage(filenames_images{1}, im);
im2 = uint8(rand(256,256,1)*255);
im_std2 = std(single(im2(:)));
editor.replaceText("%mainstd2%", sprintf('%0.5f', im_std2));
editor.replaceText("%figure2%", 'grey noise');
imwrite(im2, 'temp.png');
editor.replaceImage(filenames_images{2}, 'temp.png');
editor.save('test.docx');
Note, code is written by me, but simplified through Microsoft Copilot GPT5.2
Cite As
Dirk-Jan Kroon (2026). DocxEditor (https://www.mathworks.com/matlabcentral/fileexchange/182855-docxeditor), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
