summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2018-12-19 23:32:12 +0800
committerGitHub <noreply@github.com>2018-12-19 23:32:12 +0800
commit3ca3156d453076d5423b15cb47bfc8f027ebe95d (patch)
tree1b834d6351ffedc86b420e1e1d3b6f41a02d1bb9 /excelize.go
parent90221bd98fab0ce85a177d955d79a964bb4b66b2 (diff)
parent3012df08eb81756704a8e3f47fff59d0a6bf693b (diff)
Merge pull request #313 from sairoutine/feature/get_merge_cells
Add GetMergeCells
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/excelize.go b/excelize.go
index 309a8d8..4b4aa32 100644
--- a/excelize.go
+++ b/excelize.go
@@ -411,3 +411,43 @@ func (f *File) adjustAutoFilterHelper(xlsx *xlsxWorksheet, column, rowIndex, off
}
}
}
+
+// GetMergeCells provides a function to get all merged cells from a worksheet currently.
+func (f *File) GetMergeCells(sheet string) []MergeCell {
+ mergeCells := []MergeCell{}
+
+ xlsx := f.workSheetReader(sheet)
+ if xlsx.MergeCells != nil {
+ for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
+ ref := xlsx.MergeCells.Cells[i].Ref
+ axis := strings.Split(ref, ":")[0]
+ mergeCells = append(mergeCells, []string{ref, f.GetCellValue(sheet, axis)})
+ }
+ }
+
+ return mergeCells
+}
+
+// MergeCell define a merged cell data.
+// It consists of the following structure.
+// example: []string{"D4:E10", "cell value"}
+type MergeCell []string
+
+// GetCellValue returns merged cell value.
+func (m *MergeCell) GetCellValue() string {
+ return (*m)[1]
+}
+
+// GetStartAxis returns the merge start axis.
+// example: "C2"
+func (m *MergeCell) GetStartAxis() string {
+ axis := strings.Split((*m)[0], ":")
+ return axis[0]
+}
+
+// GetEndAxis returns the merge end axis.
+// example: "D4"
+func (m *MergeCell) GetEndAxis() string {
+ axis := strings.Split((*m)[0], ":")
+ return axis[1]
+}