Browse Source

Add core.xml

Geoffrey J. Teale 11 years ago
parent
commit
f0f4c17408
2 changed files with 19 additions and 7 deletions
  1. 4 0
      file.go
  2. 15 7
      file_test.go

+ 4 - 0
file.go

@@ -85,6 +85,10 @@ sheetIndex++
   <Application>Go XLSX</Application>
   <Application>Go XLSX</Application>
 </Properties>`
 </Properties>`
 
 
+	// TODO - do this properly, modification and revision information
+	parts["docProps/core.xml"] = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></cp:coreProperties>`
+
 	xSST := refTable.makeXLSXSST()
 	xSST := refTable.makeXLSXSST()
 	parts["xl/sharedStrings.xml"], err = marshal(xSST)
 	parts["xl/sharedStrings.xml"], err = marshal(xSST)
 	sheetId := fmt.Sprintf("rId%d", sheetIndex)
 	sheetId := fmt.Sprintf("rId%d", sheetIndex)

+ 15 - 7
file_test.go

@@ -74,7 +74,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	cell2.Value = "A cell!"
 	cell2.Value = "A cell!"
 	parts, err := f.MarshallParts()
 	parts, err := f.MarshallParts()
 	c.Assert(err, IsNil)
 	c.Assert(err, IsNil)
-	c.Assert(len(parts), Equals, 6)
+	c.Assert(len(parts), Equals, 7)
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <dimension ref="A1:A1"></dimension>
@@ -88,12 +88,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
   </worksheet>`
   </worksheet>`
 	c.Assert(parts["worksheets/sheet1.xml"], Equals, expectedSheet)
 	c.Assert(parts["worksheets/sheet1.xml"], Equals, expectedSheet)
 	c.Assert(parts["worksheets/sheet2.xml"], Equals, expectedSheet)
 	c.Assert(parts["worksheets/sheet2.xml"], Equals, expectedSheet)
-	expectedXLSXSST := `<?xml version="1.0" encoding="UTF-8"?>
-  <sst count="1" uniqueCount="1">
-    <si>
-      <t>A cell!</t>
-    </si>
-  </sst>`
+
 	expectedRels := `<?xml version="1.0" encoding="UTF-8"?>
 	expectedRels := `<?xml version="1.0" encoding="UTF-8"?>
 <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
 <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
   <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
   <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
@@ -101,13 +96,26 @@ func (l *FileSuite) TestMarshalFile(c *C) {
   <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
   <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
 </Relationships>`
 </Relationships>`
 	c.Assert(parts[".rels"], Equals, expectedRels)
 	c.Assert(parts[".rels"], Equals, expectedRels)
+
 	expectedApp := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 	expectedApp := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
 <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
   <TotalTime>0</TotalTime>
   <TotalTime>0</TotalTime>
   <Application>Go XLSX</Application>
   <Application>Go XLSX</Application>
 </Properties>`
 </Properties>`
 	c.Assert(parts["docProps/app.xml"], Equals, expectedApp)
 	c.Assert(parts["docProps/app.xml"], Equals, expectedApp)
+
+	expectedCore := `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></cp:coreProperties>`
+	c.Assert(parts["docProps/core.xml"], Equals, expectedCore)
+
+	expectedXLSXSST := `<?xml version="1.0" encoding="UTF-8"?>
+  <sst count="1" uniqueCount="1">
+    <si>
+      <t>A cell!</t>
+    </si>
+  </sst>`
 	c.Assert(parts["xl/sharedStrings.xml"], Equals, expectedXLSXSST)
 	c.Assert(parts["xl/sharedStrings.xml"], Equals, expectedXLSXSST)
+
 	expectedXLSXWorkbookRels := `<?xml version="1.0" encoding="UTF-8"?>
 	expectedXLSXWorkbookRels := `<?xml version="1.0" encoding="UTF-8"?>
   <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
   <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
     <Relationship Id="rId1" Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"></Relationship>
     <Relationship Id="rId1" Target="worksheets/sheet1.xml" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"></Relationship>