Skip to content

Commit

Permalink
Add SetRowHeight function
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolvs committed Feb 2, 2017
1 parent a1060e7 commit 8ce12b6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions excelize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,13 @@ func TestSMergeCell(t *testing.T) {
t.Log(err)
}
}

func TestSetRowHeight(t *testing.T) {
xlsx := CreateFile()
xlsx.SetRowHeight("Sheet1", 0, 50)
xlsx.SetRowHeight("Sheet1", 3, 90)
err := xlsx.WriteTo("./test/Workbook_5.xlsx")
if err != nil {
t.Log(err)
}
}
28 changes: 28 additions & 0 deletions rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,34 @@ func (f *File) GetRows(sheet string) [][]string {
return r
}

// SetRowHeight provides a function to set the height of a single row.
// For example:
//
// xlsx := excelize.CreateFile()
// xlsx.SetRowHeight("Sheet1", 0, 50)
// err := xlsx.Save()
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
//
func (f *File) SetRowHeight(sheet string, rowIndex int, height float64) {
xlsx := xlsxWorksheet{}
name := "xl/worksheets/" + strings.ToLower(sheet) + ".xml"
xml.Unmarshal([]byte(f.readXML(name)), &xlsx)

rows := rowIndex + 1
cells := 0

xlsx = completeRow(xlsx, rows, cells)

xlsx.SheetData.Row[rowIndex].Ht = strconv.FormatFloat(height, 'f', -1, 64)
xlsx.SheetData.Row[rowIndex].CustomHeight = true

output, _ := xml.Marshal(xlsx)
f.saveFileList(name, replaceWorkSheetsRelationshipsNameSpace(string(output)))
}

// readXMLSST read xmlSST simple function.
func readXMLSST(f *File) (xlsxSST, error) {
shardStrings := xlsxSST{}
Expand Down

0 comments on commit 8ce12b6

Please sign in to comment.