en Quick Start - ZeroHawkeye/wordZero GitHub Wiki
Quick Start
Welcome to WordZero! This chapter will guide you through getting started quickly and creating your first Word document.
📦 Installation
Prerequisites
- Go 1.19 or higher
- Basic Go programming knowledge
Installing WordZero
Install using Go modules:
go mod init your-project-name
go get github.com/ZeroHawkeye/wordZero
🏗️ Core Concepts
Before we start coding, let's understand WordZero's core concepts:
Document
The Document is WordZero's core object, representing a complete Word document.
Paragraph
A Paragraph is the basic text container in a document, which can contain text, formatting, and styles.
Style
WordZero provides 18 predefined styles, including headings, body text, quotes, and more.
Table
Tables are used to organize structured data, with support for styling and cell operations.
Image
WordZero supports inserting images in documents, including PNG, JPEG, GIF formats, with various layout and positioning controls.
🚀 First Example
Let's create a simple Word document:
package main
import (
"fmt"
"log"
"github.com/ZeroHawkeye/wordZero/pkg/document"
"github.com/ZeroHawkeye/wordZero/pkg/style"
)
func main() {
// 1. Create a new document
doc := document.New()
// 2. Add title
title := doc.AddParagraph("My First WordZero Document")
title.SetStyle(style.StyleTitle)
// 3. Add subtitle
subtitle := doc.AddParagraph("Creating Word Documents with Go")
subtitle.SetStyle(style.StyleSubtitle)
// 4. Add body paragraph
content := doc.AddParagraph("This is my first Word document created with WordZero. WordZero is an easy-to-use Go library for Word document manipulation.")
content.SetStyle(style.StyleNormal)
// 5. Save the document
err := doc.SaveToFile("my-first-document.docx")
if err != nil {
log.Fatalf("Failed to save document: %v", err)
}
fmt.Println("Document created successfully!")
}
📁 Recommended Project Structure
When creating a new project, we recommend using the following structure:
your-project/
├── main.go # Main program file
├── go.mod # Go module file
├── docs/ # Generated documents directory
│ └── *.docx # Word document files
└── README.md # Project description
🔧 Basic Operation Flow
The basic workflow for using WordZero:
- Create Document: Use
document.New()
to create a new document - Add Content: Use
AddParagraph()
to add paragraphs - Set Styles: Use
SetStyle()
to apply styles - Save Document: Use
SaveToFile()
to save to file
💡 Common Styles
WordZero provides the following commonly used predefined styles:
style.StyleTitle
- Document titlestyle.StyleSubtitle
- Subtitlestyle.StyleHeading1
- Level 1 headingstyle.StyleHeading2
- Level 2 headingstyle.StyleHeading3
- Level 3 headingstyle.StyleNormal
- Body textstyle.StyleQuote
- Quote
⚠️ Important Notes
- File Extension: Ensure you use the
.docx
extension when saving files - Error Handling: Always check for errors returned by functions
- File Path: Ensure the save path exists and has write permissions
🎯 Practice Exercises
Try modifying the example above:
- Add more paragraphs
- Use different styles
- Change the document title
- Save to a different filename
- Add images to the document
- Try different image positions and sizes
Next Steps
Congratulations! You have successfully created your first WordZero document.
Next, you can continue learning:
- Basic Features - Learn more document manipulation functions
- Style System - Master document styling
- Text Formatting - Rich text formatting options
- Image Operations - Insert and manage images in documents
Start your WordZero journey!