handle the cell without r attribute in a row element
This commit is contained in:
parent
1fe660df64
commit
2285d4dc71
16
rows.go
16
rows.go
|
@ -593,6 +593,22 @@ func checkRow(xlsx *xlsxWorksheet) error {
|
|||
if colCount == 0 {
|
||||
continue
|
||||
}
|
||||
// check and fill the cell without r attribute in a row element
|
||||
rCount := 0
|
||||
for idx, cell := range rowData.C {
|
||||
rCount++
|
||||
if cell.R != "" {
|
||||
lastR, _, err := CellNameToCoordinates(cell.R)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lastR > rCount {
|
||||
rCount = lastR
|
||||
}
|
||||
continue
|
||||
}
|
||||
rowData.C[idx].R, _ = CoordinatesToCellName(rCount, rowIdx+1)
|
||||
}
|
||||
lastCol, _, err := CellNameToCoordinates(rowData.C[colCount-1].R)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
11
rows_test.go
11
rows_test.go
|
@ -831,6 +831,17 @@ func TestErrSheetNotExistError(t *testing.T) {
|
|||
assert.EqualValues(t, err.Error(), "sheet Sheet1 is not exist")
|
||||
}
|
||||
|
||||
func TestCheckRow(t *testing.T) {
|
||||
f := NewFile()
|
||||
f.XLSX["xl/worksheets/sheet1.xml"] = []byte(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" ><sheetData><row r="2"><c><v>1</v></c><c r="F2"><v>2</v></c><c><v>3</v></c><c><v>4</v></c><c r="M2"><v>5</v></c></row></sheetData></worksheet>`)
|
||||
_, err := f.GetRows("Sheet1")
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, f.SetCellValue("Sheet1", "A1", false))
|
||||
f = NewFile()
|
||||
f.XLSX["xl/worksheets/sheet1.xml"] = []byte(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" ><sheetData><row r="2"><c><v>1</v></c><c r="-"><v>2</v></c><c><v>3</v></c><c><v>4</v></c><c r="M2"><v>5</v></c></row></sheetData></worksheet>`)
|
||||
assert.EqualError(t, f.SetCellValue("Sheet1", "A1", false), `cannot convert cell "-" to coordinates: invalid cell name "-"`)
|
||||
}
|
||||
|
||||
func BenchmarkRows(b *testing.B) {
|
||||
f, _ := OpenFile(filepath.Join("test", "Book1.xlsx"))
|
||||
for i := 0; i < b.N; i++ {
|
||||
|
|
10
sheet.go
10
sheet.go
|
@ -237,7 +237,7 @@ func (f *File) SetActiveSheet(index int) {
|
|||
for idx, name := range f.GetSheetList() {
|
||||
xlsx, err := f.workSheetReader(name)
|
||||
if err != nil {
|
||||
// Chartsheet
|
||||
// Chartsheet or dialogsheet
|
||||
return
|
||||
}
|
||||
if xlsx.SheetViews == nil {
|
||||
|
@ -365,8 +365,8 @@ func (f *File) GetSheetIndex(name string) int {
|
|||
return idx
|
||||
}
|
||||
|
||||
// GetSheetMap provides a function to get worksheet and chartsheet name and
|
||||
// ID map of XLSX. For example:
|
||||
// GetSheetMap provides a function to get worksheet, chartsheet and
|
||||
// dialogsheet ID and name map of XLSX. For example:
|
||||
//
|
||||
// f, err := excelize.OpenFile("Book1.xlsx")
|
||||
// if err != nil {
|
||||
|
@ -387,8 +387,8 @@ func (f *File) GetSheetMap() map[int]string {
|
|||
return sheetMap
|
||||
}
|
||||
|
||||
// GetSheetList provides a function to get worksheet and chartsheet name list
|
||||
// of workbook.
|
||||
// GetSheetList provides a function to get worksheet, chartsheet and
|
||||
// dialogsheet name list of workbook.
|
||||
func (f *File) GetSheetList() (list []string) {
|
||||
wb := f.workbookReader()
|
||||
if wb != nil {
|
||||
|
|
|
@ -23,6 +23,7 @@ const (
|
|||
SourceRelationshipHyperLink = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
|
||||
SourceRelationshipWorkSheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"
|
||||
SourceRelationshipChartsheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chartsheet"
|
||||
SourceRelationshipDialogsheet = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/dialogsheet"
|
||||
SourceRelationshipPivotTable = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotTable"
|
||||
SourceRelationshipPivotCache = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
|
||||
SourceRelationshipSharedStrings = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
||||
|
|
Loading…
Reference in New Issue