1 Star 0 Fork 0

墙外行人/gooxml

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
richtextrun.go 2.03 KB
一键复制 编辑 原始数据 按行查看 历史
墙外行人 提交于 2025-09-23 22:17 +08:00 . 替换
// Copyright 2017 Baliance. All rights reserved.
//
// Use of this source code is governed by the terms of the Affero GNU General
// Public License version 3.0 as published by the Free Software Foundation and
// appearing in the file LICENSE included in the packaging of this file. A
// commercial license can be purchased by contacting sales@baliance.com.
package spreadsheet
import (
"gitee.com/qwxren/gooxml"
"gitee.com/qwxren/gooxml/color"
"gitee.com/qwxren/gooxml/measurement"
"gitee.com/qwxren/gooxml/schema/soo/sml"
)
// RichTextRun is a segment of text within a cell that is directly formatted.
type RichTextRun struct {
x *sml.CT_RElt
}
// X returns the inner wrapped XML type.
func (r RichTextRun) X() *sml.CT_RElt {
return r.x
}
// SetText sets the text to be displayed.
func (r RichTextRun) SetText(s string) {
r.x.T = s
}
func (r RichTextRun) ensureRpr() {
if r.x.RPr == nil {
r.x.RPr = sml.NewCT_RPrElt()
}
}
// SetBold causes the text to be displayed in bold.
func (r RichTextRun) SetBold(b bool) {
r.ensureRpr()
r.x.RPr.B = sml.NewCT_BooleanProperty()
r.x.RPr.B.ValAttr = gooxml.Bool(b)
}
// SetColor sets the text color.
func (r RichTextRun) SetColor(c color.Color) {
r.ensureRpr()
r.x.RPr.Color = sml.NewCT_Color()
r.x.RPr.Color.RgbAttr = c.AsRGBString()
}
// SetItalic causes the text to be displayed in italic.
func (r RichTextRun) SetItalic(b bool) {
r.ensureRpr()
r.x.RPr.I = sml.NewCT_BooleanProperty()
r.x.RPr.I.ValAttr = gooxml.Bool(b)
}
// SetUnderline controls if the run is underlined.
func (r RichTextRun) SetUnderline(u sml.ST_UnderlineValues) {
r.ensureRpr()
r.x.RPr.U = sml.NewCT_UnderlineProperty()
r.x.RPr.U.ValAttr = u
}
// SetSize sets the text size for a rich text run.
func (r RichTextRun) SetSize(m measurement.Distance) {
r.ensureRpr()
r.x.RPr.Sz = sml.NewCT_FontSize()
r.x.RPr.Sz.ValAttr = float64(m / measurement.Point)
}
// SetFont sets the font name for a rich text run.
func (r RichTextRun) SetFont(s string) {
r.ensureRpr()
r.x.RPr.RFont = sml.NewCT_FontName()
r.x.RPr.RFont.ValAttr = s
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/qwxren/gooxml.git
git@gitee.com:qwxren/gooxml.git
qwxren
gooxml
gooxml
v1.0.17-alpha

搜索帮助