This commit is contained in:
parent
fcbc7e3f88
commit
843bd24e56
11
lib.go
11
lib.go
|
@ -20,7 +20,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReadZipReader can be used to read the spreadsheet in memory without touching the
|
// ReadZipReader can be used to read the spreadsheet in memory without touching the
|
||||||
|
@ -251,17 +250,11 @@ func namespaceStrictToTransitional(content []byte) []byte {
|
||||||
StrictNameSpaceSpreadSheet: NameSpaceSpreadSheet.Value,
|
StrictNameSpaceSpreadSheet: NameSpaceSpreadSheet.Value,
|
||||||
}
|
}
|
||||||
for s, n := range namespaceTranslationDic {
|
for s, n := range namespaceTranslationDic {
|
||||||
content = bytesReplace(content, stringToBytes(s), stringToBytes(n), -1)
|
content = bytesReplace(content, []byte(s), []byte(n), -1)
|
||||||
}
|
}
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
// stringToBytes cast a string to bytes pointer and assign the value of this
|
|
||||||
// pointer.
|
|
||||||
func stringToBytes(s string) []byte {
|
|
||||||
return *(*[]byte)(unsafe.Pointer(&s))
|
|
||||||
}
|
|
||||||
|
|
||||||
// bytesReplace replace old bytes with given new.
|
// bytesReplace replace old bytes with given new.
|
||||||
func bytesReplace(s, old, new []byte, n int) []byte {
|
func bytesReplace(s, old, new []byte, n int) []byte {
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
|
@ -366,7 +359,7 @@ func getXMLNamespace(space string, attr []xml.Attr) string {
|
||||||
// replaceNameSpaceBytes provides a function to replace the XML root element
|
// replaceNameSpaceBytes provides a function to replace the XML root element
|
||||||
// attribute by the given component part path and XML content.
|
// attribute by the given component part path and XML content.
|
||||||
func (f *File) replaceNameSpaceBytes(path string, contentMarshal []byte) []byte {
|
func (f *File) replaceNameSpaceBytes(path string, contentMarshal []byte) []byte {
|
||||||
var oldXmlns = stringToBytes(`xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`)
|
var oldXmlns = []byte(`xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">`)
|
||||||
var newXmlns = []byte(templateNamespaceIDMap)
|
var newXmlns = []byte(templateNamespaceIDMap)
|
||||||
if attr, ok := f.xmlAttr[path]; ok {
|
if attr, ok := f.xmlAttr[path]; ok {
|
||||||
newXmlns = []byte(genXMLNamespace(attr))
|
newXmlns = []byte(genXMLNamespace(attr))
|
||||||
|
|
4
sheet.go
4
sheet.go
|
@ -213,8 +213,8 @@ func (f *File) setAppXML() {
|
||||||
// strict requirements about the structure of the input XML. This function is
|
// strict requirements about the structure of the input XML. This function is
|
||||||
// a horrible hack to fix that after the XML marshalling is completed.
|
// a horrible hack to fix that after the XML marshalling is completed.
|
||||||
func replaceRelationshipsBytes(content []byte) []byte {
|
func replaceRelationshipsBytes(content []byte) []byte {
|
||||||
oldXmlns := stringToBytes(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
|
oldXmlns := []byte(`xmlns:relationships="http://schemas.openxmlformats.org/officeDocument/2006/relationships" relationships`)
|
||||||
newXmlns := stringToBytes("r")
|
newXmlns := []byte("r")
|
||||||
return bytesReplace(content, oldXmlns, newXmlns, -1)
|
return bytesReplace(content, oldXmlns, newXmlns, -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -367,7 +367,7 @@ func writeCell(buf *bufferedWriter, c xlsxC) {
|
||||||
buf.WriteString(`>`)
|
buf.WriteString(`>`)
|
||||||
if c.V != "" {
|
if c.V != "" {
|
||||||
buf.WriteString(`<v>`)
|
buf.WriteString(`<v>`)
|
||||||
xml.EscapeText(buf, stringToBytes(c.V))
|
xml.EscapeText(buf, []byte(c.V))
|
||||||
buf.WriteString(`</v>`)
|
buf.WriteString(`</v>`)
|
||||||
}
|
}
|
||||||
buf.WriteString(`</c>`)
|
buf.WriteString(`</c>`)
|
||||||
|
|
Loading…
Reference in New Issue