mirror of
https://github.com/ZeroHawkeye/wordZero.git
synced 2025-10-04 07:26:29 +08:00
Page:
en API Reference
Pages
01 快速开始
02 基础功能
03 样式系统
04 文本格式化
05 表格操作
06 页面设置
07 图片操作
08 高级功能
09 最佳实践
10 API参考
11 示例项目
12 模板功能
13 性能基准测试
14 功能特性详览
15 项目结构详解
16 Markdown双向转换
Home
en API Reference
en Advanced Features
en Basic Features
en Best Practices
en Example Projects
en Feature Overview
en Home
en Image Operations
en Markdown Conversion
en Page Settings
en Performance Benchmarks
en Project Structure
en Quick Start
en Style System
en Table Operations
en Template Features
en Text Formatting
Clone
1
en API Reference
zero edited this page 2025-06-05 09:38:49 +08:00
API Reference
This document provides a complete reference for all public APIs in the WordZero library.
📋 Package Overview
WordZero consists of three main packages:
github.com/ZeroHawkeye/wordZero/pkg/document
- Core document manipulationgithub.com/ZeroHawkeye/wordZero/pkg/style
- Style definitions and managementgithub.com/ZeroHawkeye/wordZero/pkg/markdown
- Markdown conversion utilities
📄 Document Package
Document Creation
New() *Document
Creates a new empty Word document.
doc := document.New()
Document Operations
Save(filename string) error
Saves the document to the specified file path.
err := doc.Save("document.docx")
if err != nil {
log.Printf("Save failed: %v", err)
}
AddParagraph(text string) *Paragraph
Adds a new paragraph with the specified text to the document.
para := doc.AddParagraph("Hello, WordZero!")
AddTable(rows, cols int) *Table
Creates a new table with the specified number of rows and columns.
table := doc.AddTable(3, 4) // 3 rows, 4 columns
Advanced Features
AddTableOfContents() error
Adds a table of contents to the document based on heading styles.
err := doc.AddTableOfContents()
if err != nil {
log.Printf("Failed to add TOC: %v", err)
}
📝 Paragraph Structure
Text Operations
SetStyle(style style.StyleType) error
Applies a predefined style to the paragraph.
err := para.SetStyle(style.StyleHeading1)
AddFormattedText(text string, format *TextFormat)
Adds formatted text to the paragraph.
para.AddFormattedText("Bold text", &document.TextFormat{
Bold: true,
})
🎨 Text Formatting
TextFormat Structure
type TextFormat struct {
FontName string // Font family name
FontSize int // Font size in points
Bold bool // Bold formatting
Italic bool // Italic formatting
Underline bool // Underline formatting
FontColor string // Hex color code (without #)
}
📊 Table Operations
Basic Operations
SetCellText(row, col int, text string) error
Sets the text content of a specific cell.
err := table.SetCellText(0, 0, "Header 1")
GetCellText(row, col int) (string, error)
Gets the text content of a specific cell.
text, err := table.GetCellText(0, 0)
🎨 Style Package
Predefined Styles
const (
StyleNormal StyleType = "Normal"
StyleTitle StyleType = "Title"
StyleSubtitle StyleType = "Subtitle"
StyleHeading1 StyleType = "Heading1"
StyleHeading2 StyleType = "Heading2"
StyleHeading3 StyleType = "Heading3"
StyleQuote StyleType = "Quote"
StyleCodeBlock StyleType = "CodeBlock"
)
This API reference provides comprehensive coverage of WordZero's functionality.