forked from unidoc/unioffice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
spreadsheet: add support for column formatting
- Loading branch information
Showing
3 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 [email protected]. | ||
|
||
package spreadsheet | ||
|
||
import ( | ||
"baliance.com/gooxml" | ||
"baliance.com/gooxml/measurement" | ||
sml "baliance.com/gooxml/schema/schemas.openxmlformats.org/spreadsheetml" | ||
) | ||
|
||
// Column represents a column within a sheet. It's only used for formatting | ||
// purposes, so it's possible to construct a sheet without configuring columns. | ||
type Column struct { | ||
x *sml.CT_Col | ||
} | ||
|
||
// X returns the inner wrapped XML type. | ||
func (c Column) X() *sml.CT_Col { | ||
return c.x | ||
} | ||
|
||
// SetWidth controls the width of a column. | ||
func (c Column) SetWidth(w measurement.Distance) { | ||
c.x.WidthAttr = gooxml.Float64(float64(w / measurement.Character)) | ||
} | ||
|
||
// SetBestFit controls if the column width should be 'best fit'. | ||
func (c Column) SetBestFit(b bool) { | ||
if !b { | ||
c.x.BestFitAttr = nil | ||
} else { | ||
c.x.BestFitAttr = gooxml.Bool(true) | ||
} | ||
} | ||
|
||
// SetStyle sets the cell style for an entire column. | ||
func (c Column) SetStyle(cs CellStyle) { | ||
c.x.StyleAttr = gooxml.Uint32(cs.Index()) | ||
} | ||
|
||
// SetHidden controls the visibility of a column. | ||
func (c Column) SetHidden(b bool) { | ||
if !b { | ||
c.x.HiddenAttr = nil | ||
} else { | ||
c.x.HiddenAttr = gooxml.Bool(true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters