iOfficeAI / iOfficeAI/OfficeCLI

feat(docx): support cross-document paragraph cloning with source formatting

Open
#404 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
30.7k
Forks
2.1k
Avg merge
9d 8h
Merged PRs (30d)
5

Description

## Problem

`officecli add --from ` can clone a paragraph only within the same DOCX file. When an agent needs to assemble a new document from existing Word documents, the available paragraph-level `dump`/`batch` path does not carry sibling document resources such as styles, numbering, and theme definitions. As a result, copying a paragraph into a new DOCX cannot reliably match Word's **Keep Source Formatting** behavior.

## Proposed interface

Add an explicit source-document option, or an equivalent cross-document clone operation:

```powershell
officecli add target.docx /body `
--from-file source.docx `
--from "/body/p[12]" `
--after "/body/p[3]"
```

The source document should remain read-only.

## Expected behavior

For a copied Word paragraph:

- preserve paragraph properties and all child runs/direct character formatting;
- import or remap referenced custom styles and numbering definitions;
- preserve theme-dependent appearance where required;
- copy and remap media and hyperlink relationships used by the paragraph;
- remap colliding bookmark, comment, footnote, endnote, drawing, and relationship IDs;
- reuse identical target definitions where safe and handle conflicting definitions deterministically;
- produce a DOCX that passes `officecli validate` and opens correctly in Microsoft Word.

## Motivation

This is useful for contract assembly, compliance-review summaries, report compilation, and other workflows that collect selected source paragraphs into a new Word document. Today agents can find the paragraph and clone it inside its original document, but cannot transfer it to a new document with source formatting intact.

A paragraph-first implementation would already cover the primary use case; support for tables and other block elements could follow separately.

Contributor guide

Open the contributing guide

Research direction

Start with the officecli add command and its existing --from paragraph-cloning path, then compare the paragraph-level dump/batch workflow. Use the proposed --from-file interface as the starting point and run officecli validate on a copied paragraph; done means source formatting and referenced resources survive remapping and the result opens correctly in Word.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
cli, content
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.