mirror of
https://github.com/ZeroHawkeye/wordZero.git
synced 2025-09-26 20:01:17 +08:00
Page:
en Advanced Features
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
Table of Contents
- Advanced Features
- 📋 Table of Contents
- 📄 Headers and Footers
- Basic Headers and Footers
- Different Headers for First Page
- Odd/Even Page Headers
- Adding Headers
- Adding Footers
- Different First Page Headers/Footers
- 📝 Footnotes and Endnotes
- 📋 Lists and Numbering
- 🏢 Document Properties
- 📑 Structured Document Tags (SDT)
- 📋 Complete Advanced Features Example
- 💡 Best Practices
- ⚠️ Common Issues
- Next Steps
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Advanced Features
WordZero provides advanced document features that enable you to create professional, complex documents. This chapter covers headers and footers, table of contents, footnotes, endnotes, lists, and document properties.
📋 Table of Contents
Basic Table of Contents
import "github.com/ZeroHawkeye/wordZero/pkg/document"
doc := document.New()
// Add headings first
doc.AddParagraph("Introduction").SetStyle(style.StyleHeading1)
doc.AddParagraph("Getting Started").SetStyle(style.StyleHeading2)
doc.AddParagraph("Installation").SetStyle(style.StyleHeading3)
doc.AddParagraph("Advanced Topics").SetStyle(style.StyleHeading1)
// Generate table of contents
toc := doc.AddTableOfContents()
// Configure TOC levels (1-9)
toc.SetMaxLevel(3) // Include headings up to level 3
// Customize TOC
toc.SetTitle("Table of Contents")
toc.SetShowPageNumbers(true)
toc.SetShowHyperlinks(true)
Advanced TOC Configuration
// Create TOC with custom settings
tocConfig := &document.TOCConfig{
Title: "Contents",
MaxLevel: 4,
ShowPageNumbers: true,
ShowHyperlinks: true,
RightAlignPageNumbers: true,
TabLeader: ".",
Styles: map[int]string{
1: "TOC1",
2: "TOC2",
3: "TOC3",
},
}
toc := doc.AddTableOfContentsWithConfig(tocConfig)
// Update TOC after adding content
toc.Update()
📄 Headers and Footers
Basic Headers and Footers
// Add default header
err := doc.AddHeader(document.HeaderFooterTypeDefault, "Document Title - WordZero Guide")
if err != nil {
log.Printf("Failed to add header: %v", err)
}
// Add default footer with page numbers
err = doc.AddFooterWithPageNumber(document.HeaderFooterTypeDefault, "", true)
if err != nil {
log.Printf("Failed to add footer: %v", err)
}
Different Headers for First Page
// Enable different first page header/footer
doc.SetDifferentFirstPage(true)
// Add first page header
err := doc.AddHeader(document.HeaderFooterTypeFirst, "Cover Page Header")
if err != nil {
log.Printf("Failed to add first page header: %v", err)
}
// Add regular header (for subsequent pages)
err = doc.AddHeader(document.HeaderFooterTypeDefault, "Regular Header - Page Header")
if err != nil {
log.Printf("Failed to add header: %v", err)
}
// First page footer
err = doc.AddFooter(document.HeaderFooterTypeFirst, "First Page Footer")
if err != nil {
log.Printf("Failed to add first page footer: %v", err)
}
// Regular footer
err = doc.AddFooter(document.HeaderFooterTypeDefault, "Regular Footer")
if err != nil {
log.Printf("Failed to add footer: %v", err)
}
Odd/Even Page Headers
// Enable different odd/even page headers
doc.SetDifferentOddEvenPages(true)
// Note: The following methods are not available in the current version
// Odd/Even page headers need to be implemented using HeaderFooterTypeEven constant
/*
// Odd page header (right pages)
oddHeader := doc.AddOddPageHeader()
oddHeader.AddParagraph("Chapter Title").SetAlignment(document.AlignmentRight)
// Even page header (left pages)
evenHeader := doc.AddEvenPageHeader()
evenHeader.AddParagraph("Document Title").SetAlignment(document.AlignmentLeft)
// Odd page footer
oddFooter := doc.AddOddPageFooter()
oddFooter.AddParagraph("Odd Page Footer")
// Even page footer
evenFooter := doc.AddEvenPageFooter()
evenFooter.AddParagraph("Even Page Footer")
*/
// Current implementation would use:
// err := doc.AddHeader(document.HeaderFooterTypeEven, "Even Page Header")
Adding Headers
// Add simple header
err := doc.AddHeader(document.HeaderFooterTypeDefault, "Document Title - WordZero Demo")
if err != nil {
log.Printf("Failed to add header: %v", err)
}
// Add header with page number
err = doc.AddHeaderWithPageNumber(document.HeaderFooterTypeDefault, "Company Name - Internal Document", true)
if err != nil {
log.Printf("Failed to add header: %v", err)
}
Adding Footers
// Add footer
err := doc.AddFooter(document.HeaderFooterTypeDefault, "© 2024 WordZero. All rights reserved.")
if err != nil {
log.Printf("Failed to add footer: %v", err)
}
// Add footer with page number
err = doc.AddFooterWithPageNumber(document.HeaderFooterTypeDefault, "Page", true)
if err != nil {
log.Printf("Failed to add footer: %v", err)
}
Different First Page Headers/Footers
// Set different first page
doc.SetDifferentFirstPage(true)
// First page header
err := doc.AddHeader(document.HeaderFooterTypeFirst, "First Page Header")
if err != nil {
log.Printf("Failed to add first page header: %v", err)
}
// First page footer
err = doc.AddFooter(document.HeaderFooterTypeFirst, "First Page Footer")
if err != nil {
log.Printf("Failed to add first page footer: %v", err)
}
📝 Footnotes and Endnotes
Adding Footnotes
// Add paragraph with footnote
para := doc.AddParagraph("This statement needs clarification")
// Add footnote reference
footnoteRef := para.AddFootnoteReference()
// Create footnote content
footnote := doc.AddFootnote(footnoteRef)
footnote.AddParagraph("This is the footnote explanation.")
// Multiple footnotes in same paragraph
para2 := doc.AddParagraph("")
para2.AddFormattedText("First point", nil)
ref1 := para2.AddFootnoteReference()
para2.AddFormattedText(" and second point", nil)
ref2 := para2.AddFootnoteReference()
// Add footnote content
footnote1 := doc.AddFootnote(ref1)
footnote1.AddParagraph("Explanation for first point.")
footnote2 := doc.AddFootnote(ref2)
footnote2.AddParagraph("Explanation for second point.")
Footnote Configuration
// Configure footnote numbering
doc.SetFootnoteNumbering(&document.FootnoteConfig{
Format: document.FootnoteFormatDecimal, // 1, 2, 3...
StartNumber: 1,
RestartRule: document.RestartContinuous, // or RestartEachSection, RestartEachPage
Position: document.FootnotePositionPageBottom,
})
// Alternative formats
doc.SetFootnoteNumbering(&document.FootnoteConfig{
Format: document.FootnoteFormatLowerLetter, // a, b, c...
// Format: document.FootnoteFormatUpperLetter, // A, B, C...
// Format: document.FootnoteFormatLowerRoman, // i, ii, iii...
// Format: document.FootnoteFormatUpperRoman, // I, II, III...
// Format: document.FootnoteFormatSymbol, // *, †, ‡...
})
Adding Endnotes
// Add endnote (similar to footnote but appears at document end)
para := doc.AddParagraph("This requires an endnote")
endnoteRef := para.AddEndnoteReference()
endnote := doc.AddEndnote(endnoteRef)
endnote.AddParagraph("This endnote appears at the end of the document.")
// Configure endnote numbering
doc.SetEndnoteNumbering(&document.EndnoteConfig{
Format: document.EndnoteFormatLowerRoman,
StartNumber: 1,
Position: document.EndnotePositionDocumentEnd,
})
📋 Lists and Numbering
Unordered Lists
// Create unordered list with bullet points
items := []string{
"First item",
"Second item",
"Third item",
}
list := doc.AddUnorderedList(items)
// Customize bullet style
list.SetBulletStyle(document.BulletStyleDot) // •
// list.SetBulletStyle(document.BulletStyleCircle) // ○
// list.SetBulletStyle(document.BulletStyleSquare) // ■
// list.SetBulletStyle(document.BulletStyleDash) // –
// list.SetBulletStyle(document.BulletStyleArrow) // ►
Ordered Lists
// Create numbered list
numberedItems := []string{
"First step",
"Second step",
"Third step",
}
orderedList := doc.AddOrderedList(numberedItems)
// Customize numbering format
orderedList.SetNumberFormat(document.NumberFormatDecimal) // 1, 2, 3...
// orderedList.SetNumberFormat(document.NumberFormatLowerLetter) // a, b, c...
// orderedList.SetNumberFormat(document.NumberFormatUpperLetter) // A, B, C...
// orderedList.SetNumberFormat(document.NumberFormatLowerRoman) // i, ii, iii...
// orderedList.SetNumberFormat(document.NumberFormatUpperRoman) // I, II, III...
Multi-level Lists
// Create multi-level list
multiList := doc.AddMultiLevelList()
// Add items at different levels
multiList.AddItem("First level item", 0)
multiList.AddItem("Second level item", 1)
multiList.AddItem("Third level item", 2)
multiList.AddItem("Another second level", 1)
multiList.AddItem("Back to first level", 0)
// Configure level formatting
multiList.SetLevelFormat(0, document.NumberFormatDecimal, "") // 1.
multiList.SetLevelFormat(1, document.NumberFormatLowerLetter, "") // a.
multiList.SetLevelFormat(2, document.NumberFormatLowerRoman, "") // i.
// Set indentation for each level
multiList.SetLevelIndent(0, 0) // No indent
multiList.SetLevelIndent(1, 720) // 0.5 inch indent
multiList.SetLevelIndent(2, 1440) // 1 inch indent
Custom List Styles
// Create custom list with specific styling
customList := doc.AddCustomList()
// Configure list properties
customList.SetNumberFormat(document.NumberFormatDecimal)
customList.SetPrefix("Step ")
customList.SetSuffix(":")
customList.SetStartNumber(1)
customList.SetIndent(360) // 0.25 inch
// Add items
customList.AddItem("Initialize the project")
customList.AddItem("Configure settings")
customList.AddItem("Run the application")
🏢 Document Properties
Basic Document Properties
// Set document metadata
doc.SetTitle("WordZero User Guide")
doc.SetAuthor("WordZero Team")
doc.SetSubject("Documentation")
doc.SetKeywords("wordZero, go, documentation, word")
doc.SetDescription("Comprehensive guide for WordZero library")
doc.SetCategory("Documentation")
// Set creation and modification times
doc.SetCreatedTime(time.Now())
doc.SetModifiedTime(time.Now())
// Set version and revision
doc.SetVersion("1.0")
doc.SetRevision("1")
Document Statistics
// Get document statistics
stats := doc.GetStatistics()
fmt.Printf("Pages: %d\n", stats.Pages)
fmt.Printf("Words: %d\n", stats.Words)
fmt.Printf("Characters: %d\n", stats.Characters)
fmt.Printf("Paragraphs: %d\n", stats.Paragraphs)
fmt.Printf("Lines: %d\n", stats.Lines)
// Update statistics (called automatically on save)
doc.UpdateStatistics()
// Set custom statistics
doc.SetCustomProperty("LastReviewDate", time.Now().Format("2006-01-02"))
doc.SetCustomProperty("ReviewedBy", "John Doe")
doc.SetCustomProperty("Version", "2.1")
📑 Structured Document Tags (SDT)
Content Controls
// Add text content control
textControl := doc.AddTextContentControl("Enter your name")
textControl.SetPlaceholder("Your Name Here")
textControl.SetTitle("Name Field")
// Add dropdown content control
dropdownControl := doc.AddDropdownContentControl()
dropdownControl.SetTitle("Select Option")
dropdownControl.AddOption("Option 1", "value1")
dropdownControl.AddOption("Option 2", "value2")
dropdownControl.AddOption("Option 3", "value3")
// Add date picker content control
dateControl := doc.AddDateContentControl()
dateControl.SetTitle("Select Date")
dateControl.SetDateFormat("MM/dd/yyyy")
dateControl.SetDefaultDate(time.Now())
Rich Text Controls
// Add rich text content control for formatted content
richTextControl := doc.AddRichTextContentControl()
richTextControl.SetTitle("Rich Text Area")
richTextControl.SetPlaceholder("Enter formatted text here")
// Add content to the control
richTextPara := richTextControl.AddParagraph("")
richTextPara.AddFormattedText("Bold text", &document.TextFormat{Bold: true})
richTextPara.AddFormattedText(" and normal text", nil)
📋 Complete Advanced Features Example
Here's a comprehensive example using various advanced features:
package main
import (
"fmt"
"log"
"time"
"github.com/ZeroHawkeye/wordZero/pkg/document"
"github.com/ZeroHawkeye/wordZero/pkg/style"
)
func createAdvancedDocument() error {
doc := document.New()
// Set document properties
doc.SetTitle("Advanced WordZero Features Guide")
doc.SetAuthor("WordZero Development Team")
doc.SetSubject("Technical Documentation")
doc.SetKeywords("wordZero, advanced, features, guide")
doc.SetCreatedTime(time.Now())
// Configure different first page
doc.SetDifferentFirstPage(true)
// Add first page header
err := doc.AddHeader(document.HeaderFooterTypeFirst, "WordZero Advanced Features")
if err != nil {
return fmt.Errorf("failed to add first page header: %v", err)
}
// Add regular header
err = doc.AddHeaderWithPageNumber(document.HeaderFooterTypeDefault, "WordZero Guide", false)
if err != nil {
return fmt.Errorf("failed to add header: %v", err)
}
// Add footer with page numbers
err = doc.AddFooterWithPageNumber(document.HeaderFooterTypeDefault, "", true)
if err != nil {
return fmt.Errorf("failed to add footer: %v", err)
}
// Document title
title := doc.AddParagraph("Advanced Features Guide")
title.SetStyle(style.StyleTitle)
// Table of contents
toc := doc.AddTableOfContents()
toc.SetTitle("Table of Contents")
toc.SetMaxLevel(3)
// Chapter 1
chapter1 := doc.AddParagraph("1. Lists and Numbering")
chapter1.SetStyle(style.StyleHeading1)
// Unordered list
section1_1 := doc.AddParagraph("1.1 Unordered Lists")
section1_1.SetStyle(style.StyleHeading2)
listItems := []string{
"Bullet point one",
"Bullet point two",
"Bullet point three",
}
doc.AddUnorderedList(listItems)
// Ordered list
section1_2 := doc.AddParagraph("1.2 Ordered Lists")
section1_2.SetStyle(style.StyleHeading2)
orderedItems := []string{
"First numbered item",
"Second numbered item",
"Third numbered item",
}
doc.AddOrderedList(orderedItems)
// Chapter 2
chapter2 := doc.AddParagraph("2. Footnotes and Endnotes")
chapter2.SetStyle(style.StyleHeading1)
// Paragraph with footnotes
footnotePara := doc.AddParagraph("")
footnotePara.AddFormattedText("This is a statement that requires clarification", nil)
footnoteRef1 := footnotePara.AddFootnoteReference()
footnotePara.AddFormattedText(" and additional information", nil)
footnoteRef2 := footnotePara.AddFootnoteReference()
footnotePara.AddFormattedText(".", nil)
// Add footnote content
footnote1 := doc.AddFootnote(footnoteRef1)
footnote1.AddParagraph("This is the first footnote explanation.")
footnote2 := doc.AddFootnote(footnoteRef2)
footnote2.AddParagraph("This is the second footnote with additional details.")
// Chapter 3
chapter3 := doc.AddParagraph("3. Document Structure")
chapter3.SetStyle(style.StyleHeading1)
// Multi-level list
section3_1 := doc.AddParagraph("3.1 Hierarchical Information")
section3_1.SetStyle(style.StyleHeading2)
multiList := doc.AddMultiLevelList()
multiList.AddItem("Main topic", 0)
multiList.AddItem("Subtopic one", 1)
multiList.AddItem("Sub-subtopic", 2)
multiList.AddItem("Subtopic two", 1)
multiList.AddItem("Another main topic", 0)
// Quote section
section3_2 := doc.AddParagraph("3.2 Important Notes")
section3_2.SetStyle(style.StyleHeading2)
quote := doc.AddParagraph("Advanced features enable you to create professional, structured documents that meet enterprise standards.")
quote.SetStyle(style.StyleQuote)
// Update TOC after adding all content
toc.Update()
return doc.Save("advanced_features_guide.docx")
}
func main() {
if err := createAdvancedDocument(); err != nil {
log.Fatalf("Error creating document: %v", err)
}
fmt.Println("Advanced features guide created successfully!")
}
💡 Best Practices
1. Table of Contents
- Add TOC after creating the document structure
- Use consistent heading styles for proper TOC generation
- Update TOC before finalizing the document
2. Headers and Footers
- Keep headers and footers concise
- Use consistent formatting across pages
- Include page numbers for multi-page documents
3. Footnotes and Endnotes
- Use footnotes for clarifications and citations
- Use endnotes for supplementary information
- Keep footnote text concise and relevant
4. Lists
- Use appropriate list types for content
- Maintain consistent indentation in multi-level lists
- Don't overuse complex list structures
⚠️ Common Issues
TOC Not Updating
- Ensure headings use proper styles
- Call
toc.Update()
after adding content - Check TOC level settings
Header/Footer Problems
- Verify different page settings are configured correctly
- Check alignment and formatting
- Ensure proper page setup
Footnote Numbering Issues
- Configure numbering format before adding footnotes
- Check restart rules for multi-section documents
- Verify footnote references are properly linked
Next Steps
Continue learning about document optimization:
- Best Practices - Performance and optimization
- Template Features - Dynamic document generation
- API Reference - Complete API documentation
Master these advanced features to create professional, sophisticated documents!