فهرست منبع

Write out the static .rels and app.xml

Geoffrey J. Teale 11 سال پیش
والد
کامیت
f7e6ad743b
2فایلهای تغییر یافته به همراه29 افزوده شده و 1 حذف شده
  1. 15 0
      file.go
  2. 14 1
      file_test.go

+ 15 - 0
file.go

@@ -56,6 +56,7 @@ func (f *File) MarshallParts() (map[string]string, error) {
 		return xml.Header + string(body), nil
 	}
 
+
 	parts = make(map[string]string)
 	sheetIndex := 1
 	// _ here is sheet name.
@@ -70,6 +71,20 @@ func (f *File) MarshallParts() (map[string]string, error) {
 		}
 sheetIndex++
 	}
+
+	parts[".rels"] = `<?xml version="1.0" encoding="UTF-8"?>
+<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="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
+  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
+</Relationships>`
+
+	parts["docProps/app.xml"] = `<?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">
+  <TotalTime>0</TotalTime>
+  <Application>Go XLSX</Application>
+</Properties>`
+
 	xSST := refTable.makeXLSXSST()
 	parts["xl/sharedStrings.xml"], err = marshal(xSST)
 	sheetId := fmt.Sprintf("rId%d", sheetIndex)

+ 14 - 1
file_test.go

@@ -74,7 +74,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	cell2.Value = "A cell!"
 	parts, err := f.MarshallParts()
 	c.Assert(err, IsNil)
-	c.Assert(len(parts), Equals, 4)
+	c.Assert(len(parts), Equals, 6)
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
@@ -94,6 +94,19 @@ func (l *FileSuite) TestMarshalFile(c *C) {
       <t>A cell!</t>
     </si>
   </sst>`
+	expectedRels := `<?xml version="1.0" encoding="UTF-8"?>
+<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="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
+  <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
+</Relationships>`
+	c.Assert(parts[".rels"], Equals, expectedRels)
+	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">
+  <TotalTime>0</TotalTime>
+  <Application>Go XLSX</Application>
+</Properties>`
+	c.Assert(parts["docProps/app.xml"], Equals, expectedApp)
 	c.Assert(parts["xl/sharedStrings.xml"], Equals, expectedXLSXSST)
 	expectedXLSXWorkbookRels := `<?xml version="1.0" encoding="UTF-8"?>
   <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">