Browse Source

Test create a File and add a Sheet to the file.

Geoffrey J. Teale 11 years ago
parent
commit
5d401e01ed
2 changed files with 26 additions and 2 deletions
  1. 14 2
      lib.go
  2. 12 0
      lib_test.go

+ 14 - 2
lib.go

@@ -592,6 +592,18 @@ func ReadZipReader(r *zip.Reader) (*File, error) {
 }
 
 
-func NewFile() *File {
-	return &File{};
+// Create a new File
+func NewFile() (file *File) {
+	file = &File{};
+	file.Sheets = make([]*Sheet, 0, 100)
+	file.Sheet = make(map[string]*Sheet)
+	return
+}
+
+// Add a new Sheet, with the provided name, to a File
+func (f *File) AddSheet(sheetName string) (sheet *Sheet) {
+	sheet = &Sheet{}
+	f.Sheets = append(f.Sheets, sheet)
+	f.Sheet[sheetName] = sheet
+	return sheet
 }

+ 12 - 0
lib_test.go

@@ -55,6 +55,18 @@ func (l *LibSuite) TestCreateSheet(c *C) {
 	c.Assert(cellstring, Equals, "Foo")
 }
 
+// Test that we can add a sheet to a File
+func (l *LibSuite) TestAddSheet(c *C) {
+	var f *File
+	f = NewFile()
+	sheet := f.AddSheet("MySheet")
+	c.Assert(sheet, NotNil)
+	c.Assert(len(f.Sheets), Equals, 1)
+	c.Assert(f.Sheets[0], Equals, sheet)
+	c.Assert(len(f.Sheet), Equals, 1)
+	c.Assert(f.Sheet["MySheet"], Equals, sheet)
+}
+
 // Test that GetStyle correctly converts the xlsxStyle.Fonts.
 func (l *LibSuite) TestGetStyleWithFonts(c *C) {
 	var cell *Cell