forked from p30928647/excelize
fix custom row height check issue
This commit is contained in:
parent
2fb135bc94
commit
30549c5e90
2
rows.go
2
rows.go
|
@ -290,7 +290,7 @@ func (f *File) GetRowHeight(sheet string, row int) (float64, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ht, err
|
return ht, err
|
||||||
}
|
}
|
||||||
if ws.SheetFormatPr != nil {
|
if ws.SheetFormatPr != nil && ws.SheetFormatPr.CustomHeight {
|
||||||
ht = ws.SheetFormatPr.DefaultRowHeight
|
ht = ws.SheetFormatPr.DefaultRowHeight
|
||||||
}
|
}
|
||||||
if row > len(ws.SheetData.Row) {
|
if row > len(ws.SheetData.Row) {
|
||||||
|
|
12
rows_test.go
12
rows_test.go
|
@ -126,6 +126,18 @@ func TestRowHeight(t *testing.T) {
|
||||||
_, err = f.GetRowHeight("SheetN", 3)
|
_, err = f.GetRowHeight("SheetN", 3)
|
||||||
assert.EqualError(t, err, "sheet SheetN is not exist")
|
assert.EqualError(t, err, "sheet SheetN is not exist")
|
||||||
|
|
||||||
|
// Test get row height with custom default row height.
|
||||||
|
assert.NoError(t, f.SetSheetFormatPr(sheet1,
|
||||||
|
DefaultRowHeight(30.0),
|
||||||
|
CustomHeight(true),
|
||||||
|
))
|
||||||
|
height, err = f.GetRowHeight(sheet1, 100)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, 30.0, height)
|
||||||
|
|
||||||
|
// Test set row height with custom default row height with prepare XML.
|
||||||
|
assert.NoError(t, f.SetCellValue(sheet1, "A10", "A10"))
|
||||||
|
|
||||||
err = f.SaveAs(filepath.Join("test", "TestRowHeight.xlsx"))
|
err = f.SaveAs(filepath.Join("test", "TestRowHeight.xlsx"))
|
||||||
if !assert.NoError(t, err) {
|
if !assert.NoError(t, err) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
|
|
10
sheet.go
10
sheet.go
|
@ -860,18 +860,18 @@ func (f *File) searchSheet(name, value string, regSearch bool) (result []string,
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
switch startElement := token.(type) {
|
switch xmlElement := token.(type) {
|
||||||
case xml.StartElement:
|
case xml.StartElement:
|
||||||
inElement = startElement.Name.Local
|
inElement = xmlElement.Name.Local
|
||||||
if inElement == "row" {
|
if inElement == "row" {
|
||||||
row, err = attrValToInt("r", startElement.Attr)
|
row, err = attrValToInt("r", xmlElement.Attr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if inElement == "c" {
|
if inElement == "c" {
|
||||||
colCell := xlsxC{}
|
colCell := xlsxC{}
|
||||||
_ = decoder.DecodeElement(&colCell, &startElement)
|
_ = decoder.DecodeElement(&colCell, &xmlElement)
|
||||||
val, _ := colCell.getValueFrom(f, d)
|
val, _ := colCell.getValueFrom(f, d)
|
||||||
if regSearch {
|
if regSearch {
|
||||||
regex := regexp.MustCompile(value)
|
regex := regexp.MustCompile(value)
|
||||||
|
@ -1745,7 +1745,7 @@ func prepareSheetXML(ws *xlsxWorksheet, col int, row int) {
|
||||||
sizeHint := 0
|
sizeHint := 0
|
||||||
var ht float64
|
var ht float64
|
||||||
var customHeight bool
|
var customHeight bool
|
||||||
if ws.SheetFormatPr != nil {
|
if ws.SheetFormatPr != nil && ws.SheetFormatPr.CustomHeight {
|
||||||
ht = ws.SheetFormatPr.DefaultRowHeight
|
ht = ws.SheetFormatPr.DefaultRowHeight
|
||||||
customHeight = true
|
customHeight = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,6 +169,7 @@ func (f *File) getSheetView(sheet string, viewIndex int) (*xlsxSheetView, error)
|
||||||
// ShowRowColHeaders(bool)
|
// ShowRowColHeaders(bool)
|
||||||
// ZoomScale(float64)
|
// ZoomScale(float64)
|
||||||
// TopLeftCell(string)
|
// TopLeftCell(string)
|
||||||
|
// ShowZeros(bool)
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
|
@ -198,6 +199,7 @@ func (f *File) SetSheetViewOptions(name string, viewIndex int, opts ...SheetView
|
||||||
// ShowRowColHeaders(bool)
|
// ShowRowColHeaders(bool)
|
||||||
// ZoomScale(float64)
|
// ZoomScale(float64)
|
||||||
// TopLeftCell(string)
|
// TopLeftCell(string)
|
||||||
|
// ShowZeros(bool)
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
|
|
|
@ -37,8 +37,9 @@ type StreamWriter struct {
|
||||||
// NewStreamWriter return stream writer struct by given worksheet name for
|
// NewStreamWriter return stream writer struct by given worksheet name for
|
||||||
// generate new worksheet with large amounts of data. Note that after set
|
// generate new worksheet with large amounts of data. Note that after set
|
||||||
// rows, you must call the 'Flush' method to end the streaming writing
|
// rows, you must call the 'Flush' method to end the streaming writing
|
||||||
// process and ensure that the order of line numbers is ascending. For
|
// process and ensure that the order of line numbers is ascending, the common
|
||||||
// example, set data for worksheet of size 102400 rows x 50 columns with
|
// API and stream API can't be work mixed to writing data on the worksheets.
|
||||||
|
// For example, set data for worksheet of size 102400 rows x 50 columns with
|
||||||
// numbers and style:
|
// numbers and style:
|
||||||
//
|
//
|
||||||
// file := excelize.NewFile()
|
// file := excelize.NewFile()
|
||||||
|
|
Loading…
Reference in New Issue