summaryrefslogtreecommitdiff
path: root/rows.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2021-08-17 00:01:44 +0800
committerxuri <xuri.me@gmail.com>2021-08-17 00:01:44 +0800
commita55f354eb3d0c6c1b9a543ff8ff98227aa6063a6 (patch)
treeb8832692047821630388ce55b9323d5b2a17bb55 /rows.go
parentb02f864eab5edb2155601b9dd640f99fbd442cb3 (diff)
This closes #989, closes #990
New API: `SetRowStyle` support for set style for the rows Update documentation for the `GetRows`, `SetCellStyle` and `SetColStyle`
Diffstat (limited to 'rows.go')
-rw-r--r--rows.go42
1 files changed, 40 insertions, 2 deletions
diff --git a/rows.go b/rows.go
index 5fa2cb4..fb03bba 100644
--- a/rows.go
+++ b/rows.go
@@ -23,8 +23,9 @@ import (
"github.com/mohae/deepcopy"
)
-// GetRows return all the rows in a sheet by given worksheet name (case
-// sensitive). For example:
+// GetRows return all the rows in a sheet by given worksheet name
+// (case sensitive). GetRows fetched the rows with value or formula cells,
+// the tail continuously empty cell will be skipped. For example:
//
// rows, err := f.GetRows("Sheet1")
// if err != nil {
@@ -719,6 +720,43 @@ func checkRow(ws *xlsxWorksheet) error {
return nil
}
+// SetRowStyle provides a function to set style of rows by given worksheet
+// name, row range and style ID. Note that this will overwrite the existing
+// styles for the cell, it won't append or merge style with existing styles.
+//
+// For example set style of row 1 on Sheet1:
+//
+// err = f.SetRowStyle("Sheet1", 1, style)
+//
+// Set style of rows 1 to 10 on Sheet1:
+//
+// err = f.SetRowStyle("Sheet1", 1, 10, style)
+//
+func (f *File) SetRowStyle(sheet string, start, end, styleID int) error {
+ if end < start {
+ start, end = end, start
+ }
+ if start < 1 {
+ return newInvalidRowNumberError(start)
+ }
+ if end > TotalRows {
+ return ErrMaxRows
+ }
+ if styleID < 0 {
+ return newInvalidStyleID(styleID)
+ }
+ ws, err := f.workSheetReader(sheet)
+ if err != nil {
+ return err
+ }
+ prepareSheetXML(ws, 0, end)
+ for row := start - 1; row < end; row++ {
+ ws.SheetData.Row[row].S = styleID
+ ws.SheetData.Row[row].CustomFormat = true
+ }
+ return nil
+}
+
// convertRowHeightToPixels provides a function to convert the height of a
// cell from user's units to pixels. If the height hasn't been set by the user
// we use the default value. If the row is hidden it has a value of zero.