diff --git a/rows.go b/rows.go index 8f000b344ed96cd244ff69e82541a8bd7583ee58..6a676727ed4c6d75fbded5d934b89d2c24d35f41 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 e5f0524d075273ba4935327c3a28c5f99422374b..fd7196d05c36f4b119e4d99cc250e77fb7c1f625 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 50081e8814ce2df1af8cc36631b0764294125658..8c7f754677228957bad989d2e4d1f4405a05fc39 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 191631b03fb431e22ec3d6ae130d2de75a549128..a5e43a1cbc72ccd2ac0f1ea011a5e4bcd03ef24d 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"