Skip to content

Commit

Permalink
spreadsheet: support rotated cells
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaliance committed Dec 19, 2018
1 parent 08d318b commit 15d7d72
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
31 changes: 31 additions & 0 deletions _examples/spreadsheet/rotated-cells/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2017 Baliance. All rights reserved.
package main

import (
"log"

"baliance.com/gooxml/spreadsheet"
)

var lorem = `Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin lobortis, lectus dictum feugiat tempus, sem neque finibus enim, sed eleifend sem nunc ac diam. Vestibulum tempus sagittis elementum`

func main() {
ss := spreadsheet.New()
// add a single sheet
sheet := ss.AddSheet()

row := sheet.AddRow()
cell := row.AddCell()

rotated := ss.StyleSheet.AddCellStyle()
rotated.SetRotation(45)

cell.SetString(lorem)
cell.SetStyle(rotated)

if err := ss.Validate(); err != nil {
log.Fatalf("error validating sheet: %s", err)
}

ss.SaveToFile("rotated.xlsx")
}
Binary file added _examples/spreadsheet/rotated-cells/rotated.xlsx
Binary file not shown.
9 changes: 9 additions & 0 deletions spreadsheet/cellstyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ func (cs CellStyle) SetHorizontalAlignment(a sml.ST_HorizontalAlignment) {
cs.xf.ApplyAlignmentAttr = gooxml.Bool(true)
}

// SetRotation configures the cell to be rotated.
func (cs CellStyle) SetRotation(deg uint8) {
if cs.xf.Alignment == nil {
cs.xf.Alignment = sml.NewCT_CellAlignment()
}
cs.xf.ApplyAlignmentAttr = gooxml.Bool(true)
cs.xf.Alignment.TextRotationAttr = gooxml.Uint8(deg)
}

// SetVerticalAlignment sets the vertical alignment of a cell style.
func (cs CellStyle) SetVerticalAlignment(a sml.ST_VerticalAlignment) {
if cs.xf.Alignment == nil {
Expand Down

0 comments on commit 15d7d72

Please sign in to comment.