go-office

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: BSD-3-Clause

README

go-office

golang的开源办公套件生成器(非编辑器),支持列表如下:

  • Word(段落⭕、表格⭕、页头页脚⭕、基础样式⭕、公式❌、图表❌)
  • Excel(基本数据设置⭕、样式❌、公式❌、图表❌)
  • PowerPoint(❌)

安装

go get -u github.com/wangcan-null/go-office

使用

可以在example目录下查看更多示例

import (
    "github.com/wangcan-null/go-office/docx"
    "github.com/wangcan-null/go-office/docx/paragraph"
)

// 创建一个新的文档
doc := docx.New()

// 设置文档属性
doc.GetSection().GetPageSize().SetWidth(10000).SetHeight(200000)

// 设置默认段落属性
doc.GetProperties().GetDefaultParagraphProperties().GetSpacing().SetSpace(360)

// 添加一个段落
p1 := doc.AddParagraph()

// 设置段落属性
p1.GetProperties().SetHorizontalAlignment(paragraph.HorizontalAlignmentCenter)

// 添加一个文本段
r1 := p1.AddRun()

// 设置文本段属性
r1.GetProperties().GetBackground().SetBackgroundColor("FF0000")

// 在文本段内添加文本
r1.AddText("hello")
r1.AddText(" ")
r1.AddText("word")

// 保存文档
doc.Save("example.docx")

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL