libreoffice-writer

Use when creating, editing, formatting, exporting, or extracting LibreOffice Writer (.odt) documents via UNO, including session-based edits, tables, images, metadata, patch workflows, and snapshots.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "libreoffice-writer" with this command: npx skills add dfk1352/libreoffice-skills/dfk1352-libreoffice-skills-libreoffice-writer

LibreOffice Writer

Use the bundled writer modules for UNO-backed Writer document work. All paths must be absolute. Bundled modules live under scripts/ in this skill directory — set PYTHONPATH=<skill_base_dir>/scripts.

API Surface

# Lifecycle
create_document(path)
export_document(path, output_path, format)   # formats: "pdf", "docx"

# Session (primary editing API)
open_writer_session(path) -> WriterSession   # use as context manager

WriterSession methods:
  read_text(selector=None) -> str
  insert_text(text, selector=None)
  replace_text(selector, new_text)
  delete_text(selector)
  insert_table(rows, cols, data=None, name=None, selector=None)
  update_table(selector, data)
  delete_table(selector)
  insert_image(image_path, width=None, height=None, name=None, selector=None)
  update_image(selector, image_path=None, width=None, height=None)
  delete_image(selector)
  patch(patch_text, mode="atomic") -> PatchApplyResult
  export(output_path, format)                # exports current in-memory state
  reset()                                    # discard unsaved changes
  close(save=True)

# Standalone utilities
patch(path, patch_text, mode="atomic") -> PatchApplyResult
snapshot_page(doc_path, output_path, page=1, dpi=150)
metadata.set_metadata(path, metadata)
metadata.get_metadata(path)
formatting.apply_formatting(path, formatting, selection="all")
  # selection: "all" | "last_paragraph"
  # formatting keys: bold, font_size, align, color, ...

Selectors

Selectors target content for reads, edits, and insertions.

SelectorApplies toBehaviour
contains:"text"textmatch the exact span
after:"text"textinsert as a new paragraph after the match
before:"text"textinsert as a new paragraph before the match
name:"ObjectName"table, imagematch by name (case-insensitive, spaces→underscores)
index:0table, imagematch by 0-based position

Omit selector to operate at the end of the document (for inserts) or on the whole document (for reads).

Patch DSL

Use patch() to apply multiple ordered operations in one call.

[operation]
type = insert_text
# selector = after:"Introduction"   (optional)
text = New paragraph content.

[operation]
type = replace_text
selector = contains:"old phrase"
new_text = replacement

[operation]
type = delete_text
selector = contains:"remove this"

[operation]
type = insert_table
rows = 2
cols = 3
# selector, name, data (JSON array of arrays) are all optional
data = [["A","B","C"],["1","2","3"]]
name = MyTable

[operation]
type = update_table
selector = name:"MyTable"
data = [["A","B","C"],["4","5","6"]]

[operation]
type = delete_table
selector = index:0

[operation]
type = insert_image
image_path = /abs/path/to/logo.png
# width, height (hundredths of mm), selector, name are all optional

[operation]
type = update_image
selector = name:"Logo"
image_path = /abs/path/to/new.png

[operation]
type = delete_image
selector = name:"Logo"

Modes:

  • atomic (default) — stop on first failure; revert document to pre-patch state
  • best_effort — continue past failures; report partial success

PatchApplyResult fields: mode, overall_status ("ok" | "partial" | "failed"), operations (list of PatchOperationResult), document_persisted.

Example: Build a Report

from pathlib import Path
from writer import open_writer_session
from writer.core import create_document, export_document
from writer.formatting import apply_formatting
from writer.metadata import set_metadata

output = str(Path("test-output/report.odt").resolve())

create_document(output)
set_metadata(output, {"title": "Quarterly Report", "author": "Ops"})

with open_writer_session(output) as session:
    session.insert_text("Quarterly Report")
    session.insert_table(2, 2, [["Metric", "Value"], ["Revenue", "$1M"]], name="Summary")
    session.insert_image("/abs/path/logo.png", width=5000, height=5000, name="Logo")

apply_formatting(output, {"bold": True, "font_size": 18, "align": "center"},
                 selection="last_paragraph")
export_document(output, "test-output/report.pdf", "pdf")

Example: Patch Existing Document

from writer import patch

result = patch("/abs/path/report.odt", """
[operation]
type = update_table
selector = name:"Summary"
data = [["Metric","Value"],["Revenue","$2M"]]

[operation]
type = delete_image
selector = name:"Logo"
""", mode="best_effort")

print(result.overall_status)   # "ok" | "partial" | "failed"

Snapshots

from writer.snapshot import snapshot_page

result = snapshot_page(doc_path, "/tmp/page1.png", page=1, dpi=150)
# result.file_path, result.width, result.height
Path(result.file_path).unlink(missing_ok=True)  # clean up after verification

Use snapshots to verify layout after inserting images or applying formatting. Check for overlapping elements, cut-off content, or misaligned objects.

Common Mistakes

  • Passing a relative path — UNO requires absolute paths.
  • Forgetting create_document() before opening a session.
  • Using contains: when you want an insertion point — use after: or before:.
  • Calling session.export() after session.close() — export before closing.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

clinic-visit-prep

帮助患者整理就诊前问题、既往记录、检查清单与时间线,不提供诊断。;use for healthcare, intake, prep workflows;do not use for 给诊断结论, 替代医生意见.

Archived SourceRecently Updated
Automation

changelog-curator

从变更记录、提交摘要或发布说明中整理对外 changelog,并区分用户价值与内部改动。;use for changelog, release-notes, docs workflows;do not use for 捏造未发布功能, 替代正式合规审批.

Archived SourceRecently Updated
Automation

klaviyo

Klaviyo API integration with managed OAuth. Access profiles, lists, segments, campaigns, flows, events, metrics, templates, catalogs, and webhooks. Use this skill when users want to manage email marketing, customer data, or integrate with Klaviyo workflows. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).

Archived SourceRecently Updated
Automation

lifelog

生活记录自动化系统。自动识别消息中的日期(今天/昨天/前天/具体日期),使用 SubAgent 智能判断,记录到 Notion 对应日期,支持补录标记。 适用于:(1) 用户分享日常生活点滴时自动记录;(2) 定时自动汇总分析并填充情绪、事件、位置、人员字段

Archived SourceRecently Updated