2019-07-25 19:43:46 +03:00
|
|
|
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
2017-08-31 19:28:11 -05:00
|
|
|
//
|
2020-08-08 01:01:05 +00:00
|
|
|
// Use of this software package and source code is governed by the terms of the
|
|
|
|
// UniDoc End User License Agreement (EULA) that is available at:
|
|
|
|
// https://unidoc.io/eula/
|
|
|
|
// A trial license code for evaluation can be obtained at https://unidoc.io.
|
2017-08-31 19:28:11 -05:00
|
|
|
|
|
|
|
package document
|
|
|
|
|
2017-10-03 08:03:39 -05:00
|
|
|
import (
|
2019-05-04 11:18:06 +03:00
|
|
|
"github.com/unidoc/unioffice"
|
|
|
|
"github.com/unidoc/unioffice/color"
|
|
|
|
"github.com/unidoc/unioffice/measurement"
|
|
|
|
"github.com/unidoc/unioffice/schema/soo/wml"
|
2017-10-03 08:03:39 -05:00
|
|
|
)
|
2017-08-31 19:28:11 -05:00
|
|
|
|
|
|
|
// CellProperties are a table cells properties within a document.
|
|
|
|
type CellProperties struct {
|
|
|
|
x *wml.CT_TcPr
|
|
|
|
}
|
|
|
|
|
|
|
|
// X returns the inner wrapped XML type.
|
|
|
|
func (c CellProperties) X() *wml.CT_TcPr {
|
|
|
|
return c.x
|
|
|
|
}
|
|
|
|
|
2017-12-05 19:29:07 -06:00
|
|
|
// SetColumnSpan sets the number of Grid Columns Spanned by the Cell. This is used
|
|
|
|
// to give the appearance of merged cells.
|
2017-08-31 19:28:11 -05:00
|
|
|
func (c CellProperties) SetColumnSpan(cols int) {
|
|
|
|
if cols == 0 {
|
|
|
|
c.x.GridSpan = nil
|
|
|
|
} else {
|
|
|
|
c.x.GridSpan = wml.NewCT_DecimalNumber()
|
|
|
|
c.x.GridSpan.ValAttr = int64(cols)
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 08:03:39 -05:00
|
|
|
|
2018-03-13 08:14:22 -05:00
|
|
|
// SetVerticalMerge controls the vertical merging of cells.
|
|
|
|
func (c CellProperties) SetVerticalMerge(mergeVal wml.ST_Merge) {
|
|
|
|
if mergeVal == wml.ST_MergeUnset {
|
|
|
|
c.x.VMerge = nil
|
|
|
|
} else {
|
|
|
|
c.x.VMerge = wml.NewCT_VMerge()
|
|
|
|
c.x.VMerge.ValAttr = mergeVal
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-10 12:04:40 -05:00
|
|
|
// SetWidthAuto sets the the cell width to automatic.
|
|
|
|
func (c CellProperties) SetWidthAuto() {
|
|
|
|
c.x.TcW = wml.NewCT_TblWidth()
|
|
|
|
c.x.TcW.TypeAttr = wml.ST_TblWidthAuto
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWidthPercent sets the cell to a width percentage.
|
|
|
|
func (c CellProperties) SetWidthPercent(pct float64) {
|
|
|
|
c.x.TcW = wml.NewCT_TblWidth()
|
|
|
|
c.x.TcW.TypeAttr = wml.ST_TblWidthPct
|
|
|
|
c.x.TcW.WAttr = &wml.ST_MeasurementOrPercent{}
|
|
|
|
c.x.TcW.WAttr.ST_DecimalNumberOrPercent = &wml.ST_DecimalNumberOrPercent{}
|
|
|
|
// percent value is measured in 1/50'th of a percent
|
2019-05-04 13:54:29 +00:00
|
|
|
c.x.TcW.WAttr.ST_DecimalNumberOrPercent.ST_UnqualifiedPercentage = unioffice.Int64(int64(pct * 50))
|
2017-10-10 12:04:40 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetWidth sets the cell width to a specified width.
|
|
|
|
func (c CellProperties) SetWidth(d measurement.Distance) {
|
|
|
|
c.x.TcW = wml.NewCT_TblWidth()
|
|
|
|
c.x.TcW.TypeAttr = wml.ST_TblWidthDxa
|
|
|
|
c.x.TcW.WAttr = &wml.ST_MeasurementOrPercent{}
|
|
|
|
c.x.TcW.WAttr.ST_DecimalNumberOrPercent = &wml.ST_DecimalNumberOrPercent{}
|
2019-05-04 13:54:29 +00:00
|
|
|
c.x.TcW.WAttr.ST_DecimalNumberOrPercent.ST_UnqualifiedPercentage = unioffice.Int64(int64(d / measurement.Twips))
|
2017-10-10 12:04:40 -05:00
|
|
|
}
|
|
|
|
|
2017-10-03 08:03:39 -05:00
|
|
|
// SetShading controls the cell shading.
|
|
|
|
func (c CellProperties) SetShading(shd wml.ST_Shd, foreground, fill color.Color) {
|
|
|
|
if shd == wml.ST_ShdUnset {
|
|
|
|
c.x.Shd = nil
|
|
|
|
} else {
|
|
|
|
c.x.Shd = wml.NewCT_Shd()
|
|
|
|
c.x.Shd.ValAttr = shd
|
|
|
|
c.x.Shd.ColorAttr = &wml.ST_HexColor{}
|
|
|
|
if foreground.IsAuto() {
|
|
|
|
c.x.Shd.ColorAttr.ST_HexColorAuto = wml.ST_HexColorAutoAuto
|
|
|
|
} else {
|
|
|
|
c.x.Shd.ColorAttr.ST_HexColorRGB = foreground.AsRGBString()
|
|
|
|
}
|
|
|
|
c.x.Shd.FillAttr = &wml.ST_HexColor{}
|
|
|
|
if fill.IsAuto() {
|
|
|
|
c.x.Shd.FillAttr.ST_HexColorAuto = wml.ST_HexColorAutoAuto
|
|
|
|
} else {
|
|
|
|
c.x.Shd.FillAttr.ST_HexColorRGB = fill.AsRGBString()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 07:40:44 -05:00
|
|
|
|
|
|
|
// SetVerticalAlignment sets the vertical alignment of content within a table cell.
|
|
|
|
func (c CellProperties) SetVerticalAlignment(align wml.ST_VerticalJc) {
|
|
|
|
if align == wml.ST_VerticalJcUnset {
|
|
|
|
c.x.VAlign = nil
|
|
|
|
} else {
|
|
|
|
c.x.VAlign = wml.NewCT_VerticalJc()
|
|
|
|
c.x.VAlign.ValAttr = align
|
|
|
|
}
|
|
|
|
}
|
2017-12-06 17:54:24 -06:00
|
|
|
|
|
|
|
// Borders allows controlling individual cell borders.
|
|
|
|
func (c CellProperties) Borders() CellBorders {
|
|
|
|
if c.x.TcBorders == nil {
|
|
|
|
c.x.TcBorders = wml.NewCT_TcBorders()
|
|
|
|
}
|
|
|
|
return CellBorders{c.x.TcBorders}
|
|
|
|
}
|
2018-09-26 20:01:52 -05:00
|
|
|
|
|
|
|
// Margins allows controlling individual cell margins.
|
|
|
|
func (c CellProperties) Margins() CellMargins {
|
|
|
|
if c.x.TcMar == nil {
|
|
|
|
c.x.TcMar = wml.NewCT_TcMar()
|
|
|
|
}
|
|
|
|
return CellMargins{c.x.TcMar}
|
|
|
|
}
|