summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2018-04-02 10:59:15 +0800
committerRi Xu <xuri.me@gmail.com>2018-04-02 10:59:15 +0800
commita6fc5a721dfcb4974342603ebff8a4032c58a797 (patch)
tree7090c69a65ee1b4f1221a4f2e75d68c6b72ff99f
parentdcbde4b8311b5cb48731fbaf23eee58d994dac61 (diff)
- Make row index consistent in function `SetRowHeight` and `GetRowHeight`, fix issue #205;
- go test and godoc has been updated
-rw-r--r--excelize_test.go6
-rw-r--r--rows.go30
-rw-r--r--[-rwxr-xr-x]test/SharedStrings.xlsxbin6462 -> 6462 bytes
3 files changed, 17 insertions, 19 deletions
diff --git a/excelize_test.go b/excelize_test.go
index f266250..efffe8c 100644
--- a/excelize_test.go
+++ b/excelize_test.go
@@ -226,10 +226,10 @@ func TestColWidth(t *testing.T) {
func TestRowHeight(t *testing.T) {
xlsx := NewFile()
- xlsx.SetRowHeight("Sheet1", 0, 50)
- xlsx.SetRowHeight("Sheet1", 3, 90)
+ xlsx.SetRowHeight("Sheet1", 1, 50)
+ xlsx.SetRowHeight("Sheet1", 4, 90)
t.Log(xlsx.GetRowHeight("Sheet1", 1))
- t.Log(xlsx.GetRowHeight("Sheet1", 3))
+ t.Log(xlsx.GetRowHeight("Sheet1", 0))
err := xlsx.SaveAs("./test/Book5.xlsx")
if err != nil {
t.Log(err)
diff --git a/rows.go b/rows.go
index 405717c..f7ae7f9 100644
--- a/rows.go
+++ b/rows.go
@@ -99,23 +99,18 @@ func (f *File) getTotalRowsCols(name string) (int, int) {
return tr, tc
}
-// SetRowHeight provides a function to set the height of a single row.
-// For example:
+// SetRowHeight provides a function to set the height of a single row. For
+// example, set the height of the first row in Sheet1:
//
-// xlsx := excelize.NewFile()
-// xlsx.SetRowHeight("Sheet1", 0, 50)
-// err := xlsx.Save()
-// if err != nil {
-// fmt.Println(err)
-// }
+// xlsx.SetRowHeight("Sheet1", 1, 50)
//
-func (f *File) SetRowHeight(sheet string, rowIndex int, height float64) {
+func (f *File) SetRowHeight(sheet string, row int, height float64) {
xlsx := f.workSheetReader(sheet)
- rows := rowIndex + 1
cells := 0
- completeRow(xlsx, rows, cells)
- xlsx.SheetData.Row[rowIndex].Ht = height
- xlsx.SheetData.Row[rowIndex].CustomHeight = true
+ rowIdx := row - 1
+ completeRow(xlsx, row, cells)
+ xlsx.SheetData.Row[rowIdx].Ht = height
+ xlsx.SheetData.Row[rowIdx].CustomHeight = true
}
// getRowHeight provides function to get row height in pixels by given sheet
@@ -131,12 +126,15 @@ func (f *File) getRowHeight(sheet string, row int) int {
return int(defaultRowHeightPixels)
}
-// GetRowHeight provides function to get row height by given worksheet name and
-// row index.
+// GetRowHeight provides function to get row height by given worksheet name
+// and row index. For example, get the height of the first row in Sheet1:
+//
+// xlsx.GetRowHeight("Sheet1", 1)
+//
func (f *File) GetRowHeight(sheet string, row int) float64 {
xlsx := f.workSheetReader(sheet)
for _, v := range xlsx.SheetData.Row {
- if v.R == row+1 && v.Ht != 0 {
+ if v.R == row && v.Ht != 0 {
return v.Ht
}
}
diff --git a/test/SharedStrings.xlsx b/test/SharedStrings.xlsx
index 7b722d9..7b722d9 100755..100644
--- a/test/SharedStrings.xlsx
+++ b/test/SharedStrings.xlsx
Binary files differ