已验证 提交 2285d4dc 编写于 作者: xurime's avatar xurime

handle the cell without r attribute in a row element

上级 1fe660df
......@@ -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
......
......@@ -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++ {
......
......@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册