diff --git a/rows.go b/rows.go index 8f000b3..6a67672 100644 --- a/rows.go +++ b/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 diff --git a/rows_test.go b/rows_test.go index e5f0524..fd7196d 100644 --- a/rows_test.go +++ b/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(`12345`) + _, 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(`12345`) + 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++ { diff --git a/sheet.go b/sheet.go index 50081e8..8c7f754 100644 --- a/sheet.go +++ b/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 { diff --git a/xmlDrawing.go b/xmlDrawing.go index 191631b..a5e43a1 100644 --- a/xmlDrawing.go +++ b/xmlDrawing.go @@ -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"