From a55f354eb3d0c6c1b9a543ff8ff98227aa6063a6 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 17 Aug 2021 00:01:44 +0800 Subject: This closes #989, closes #990 New API: `SetRowStyle` support for set style for the rows Update documentation for the `GetRows`, `SetCellStyle` and `SetColStyle` --- rows.go | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'rows.go') 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. -- cgit v1.2.1