代码拉取完成,页面将自动刷新
package excelize
import (
"archive/zip"
"bytes"
"fmt"
"io"
"os"
)
// NewFile provides function to create new file by default template. For
// example:
//
// xlsx := NewFile()
//
func NewFile() *File {
file := make(map[string]string)
file["_rels/.rels"] = XMLHeader + templateRels
file["docProps/app.xml"] = XMLHeader + templateDocpropsApp
file["docProps/core.xml"] = XMLHeader + templateDocpropsCore
file["xl/_rels/workbook.xml.rels"] = XMLHeader + templateWorkbookRels
file["xl/theme/theme1.xml"] = XMLHeader + templateTheme
file["xl/worksheets/sheet1.xml"] = XMLHeader + templateSheet
file["xl/styles.xml"] = XMLHeader + templateStyles
file["xl/workbook.xml"] = XMLHeader + templateWorkbook
file["[Content_Types].xml"] = XMLHeader + templateContentTypes
f := &File{
sheetMap: make(map[string]string),
Sheet: make(map[string]*xlsxWorksheet),
SheetCount: 1,
XLSX: file,
}
f.ContentTypes = f.contentTypesReader()
f.Styles = f.stylesReader()
f.WorkBook = f.workbookReader()
f.WorkBookRels = f.workbookRelsReader()
f.Sheet["xl/worksheets/sheet1.xml"] = f.workSheetReader("Sheet1")
f.sheetMap["Sheet1"] = "xl/worksheets/sheet1.xml"
return f
}
// Save provides function to override the xlsx file with origin path.
func (f *File) Save() error {
if f.Path == "" {
return fmt.Errorf("No path defined for file, consider File.WriteTo or File.Write")
}
return f.SaveAs(f.Path)
}
// SaveAs provides function to create or update to an xlsx file at the provided
// path.
func (f *File) SaveAs(name string) error {
file, err := os.OpenFile(name, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil {
return err
}
defer file.Close()
return f.Write(file)
}
// Write provides function to write to an io.Writer.
func (f *File) Write(w io.Writer) error {
buf := new(bytes.Buffer)
zw := zip.NewWriter(buf)
f.contentTypesWriter()
f.workbookWriter()
f.workbookRelsWriter()
f.worksheetWriter()
f.styleSheetWriter()
for path, content := range f.XLSX {
fi, err := zw.Create(path)
if err != nil {
return err
}
_, err = fi.Write([]byte(content))
if err != nil {
return err
}
}
err := zw.Close()
if err != nil {
return err
}
if _, err := buf.WriteTo(w); err != nil {
return err
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。