Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationzpe.lib.docx

zpe.lib.docx

The official DOCX plugin for ZPE, providing support for creating, reading and modifying .docx files directly from ZPE.

This plugin is built on Apache POI and allows structured Word document generation, heading creation, paragraph insertion and simple text replacement.

Introduction

The Docx object represents a single Word document. You can either create a new document or open an existing one, then modify and save it.

All file operations require permission level 3.

Objects

ZPEDocx

open(string path) ⇒ boolean
Opens an existing .docx file from the given path. Returns true if successful.
new_file() ⇒ boolean
Creates a new blank Word document in memory.
save(string path) ⇒ boolean
Saves the current document to the given path.
close() ⇒ boolean
Closes the document and releases resources.
is_open() ⇒ boolean
Returns true if a document is currently open.
add_paragraph(string text) ⇒ number
Adds a new paragraph containing the given text. Returns the paragraph index (0-based).
add_heading(string text, number level) ⇒ number
Adds a heading using Word's built-in styles Heading1 to Heading6. Levels are clamped between 1 and 6. Returns the paragraph index.
replace_all(string find, string replace) ⇒ number
Replaces all occurrences of a string within paragraph runs. Returns the number of replacements made.

Note: Word may split text across runs, so this method may not catch every possible occurrence.

Example

YASS
import "zpe.lib.docx"

d = new docx()

d -> new_file()
d -> add_heading("ZPE Document Example", 1)
d -> add_paragraph("This document was generated using ZPE.")
d -> add_paragraph("It supports headings, paragraphs and text replacement.")

d -> replace_all("ZPE", "Zen Programming Environment")

d -> save("example.docx")
d -> close()

Notes

  • Supports .docx format only.
  • Requires Apache POI (bundled within the plugin).
  • File operations require permission level 3.
  • Always call close() after saving to release resources.
Comments

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.