Browse Source

Add AddRow method to Sheet.

Geoffrey J. Teale 11 years ago
parent
commit
af335856af
2 changed files with 19 additions and 0 deletions
  1. 10 0
      lib.go
  2. 9 0
      lib_test.go

+ 10 - 0
lib.go

@@ -607,3 +607,13 @@ func (f *File) AddSheet(sheetName string) (sheet *Sheet) {
 	f.Sheet[sheetName] = sheet
 	return sheet
 }
+
+// Add a new Row to a Sheet
+func (s *Sheet) AddRow() *Row {
+	row := &Row{}
+	s.Rows = append(s.Rows, row)
+	if len(s.Rows) > s.MaxRow {
+		s.MaxRow = len(s.Rows)
+	}
+	return row
+}

+ 9 - 0
lib_test.go

@@ -67,6 +67,15 @@ func (l *LibSuite) TestAddSheet(c *C) {
 	c.Assert(f.Sheet["MySheet"], Equals, sheet)
 }
 
+func (l *LibSuite) TestAddRow(c *C) {
+	var f *File
+	f = NewFile()
+	sheet := f.AddSheet("MySheet")
+	row := sheet.AddRow()
+	c.Assert(row, NotNil)
+	c.Assert(len(sheet.Rows), Equals, 1)
+}
+
 // Test that GetStyle correctly converts the xlsxStyle.Fonts.
 func (l *LibSuite) TestGetStyleWithFonts(c *C) {
 	var cell *Cell