Merged Cells
Short example is better any words
package code
import (
"github.com/plandem/xlsx"
"github.com/plandem/xlsx/format/styles"
)
func Example_mergedCells() {
xl := xlsx.New()
sheet := xl.AddSheet("")
//range 1
sheet.RangeByRef("B4:E4").Merge()
sheet.CellByRef("B4").SetValue("Merged Range 1")
sheet.CellByRef("B4").SetStyles(xl.AddStyles(
styles.New(
styles.Alignment.VAlign(styles.VAlignCenter),
styles.Alignment.HAlign(styles.HAlignCenter),
styles.Fill.Type(styles.PatternTypeSolid),
styles.Fill.Color("#FFFF00"),
),
))
//range 2
sheet.RangeByRef("B6:B9").Merge()
sheet.CellByRef("B6").SetValue("Merged Range 2")
sheet.CellByRef("B6").SetStyles(xl.AddStyles(
styles.New(
styles.Alignment.VAlign(styles.VAlignCenter),
styles.Alignment.HAlign(styles.HAlignCenter),
styles.Alignment.WrapText,
styles.Fill.Type(styles.PatternTypeSolid),
styles.Fill.Color("#EEAA00"),
),
))
//range 3
sheet.RangeByRef("D6:E9").Merge()
sheet.CellByRef("D6").SetValue("Merged Range 3")
sheet.CellByRef("D6").SetStyles(xl.AddStyles(
styles.New(
styles.Alignment.VAlign(styles.VAlignCenter),
styles.Alignment.HAlign(styles.HAlignCenter),
styles.Fill.Type(styles.PatternTypeSolid),
styles.Fill.Color("#FF7070"),
),
))
xl.SaveAs("./foo.xlsx")
}
To split previously merged cells:
sheet.RangeByRef("B4:E4").Split()
Merge Rows
In case if you need to merge few rows:
//Merge 1-9 rows, internally it uses range: [0, 1, ExcelRowLimit, 9]
sheet.MergeRows(1, 9)
//Split 1-9 rows
sheet.SplitRows(1, 9)
Merge Cols
In case if you need to merge few columns:
//Split 1-9 cols, internally it uses range: [1, 0, 9, ExcelColumnLimit]
sheet.MergeCols(1, 9)
//Split 1-9 cols
sheet.SplitCols(1, 9)
Columns and Rows limits
Excel has built-in limits for total number of rows and columns per sheet. Check Excel Limits for more information about built-in limits