|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"archive/zip"
|
|
|
|
"archive/zip"
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
|
|
|
"encoding/xml"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -35,6 +34,20 @@ func OpenFile(filename string) (*File, error) {
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SetCellValue provide function to set int or string type value of a cell
|
|
|
|
|
|
|
|
func (f *File) SetCellValue(sheet string, axis string, value interface{}) {
|
|
|
|
|
|
|
|
switch t := value.(type) {
|
|
|
|
|
|
|
|
case int, int8, int16, int32, int64, float32, float64:
|
|
|
|
|
|
|
|
f.SetCellInt(sheet, axis, value.(int))
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
|
|
|
f.SetCellStr(sheet, axis, t)
|
|
|
|
|
|
|
|
case []byte:
|
|
|
|
|
|
|
|
f.SetCellStr(sheet, axis, string(t))
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
f.SetCellStr(sheet, axis, ``)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// SetCellInt provide function to set int type value of a cell
|
|
|
|
// SetCellInt provide function to set int type value of a cell
|
|
|
|
func (f *File) SetCellInt(sheet string, axis string, value int) {
|
|
|
|
func (f *File) SetCellInt(sheet string, axis string, value int) {
|
|
|
|
axis = strings.ToUpper(axis)
|
|
|
|
axis = strings.ToUpper(axis)
|
|
|
@ -56,10 +69,7 @@ func (f *File) SetCellInt(sheet string, axis string, value int) {
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
|
|
|
|
|
|
|
|
|
|
|
|
output, err := xml.Marshal(xlsx)
|
|
|
|
output, _ := xml.Marshal(xlsx)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f.saveFileList(name, replaceRelationshipsID(replaceWorkSheetsRelationshipsNameSpace(string(output))))
|
|
|
|
f.saveFileList(name, replaceRelationshipsID(replaceWorkSheetsRelationshipsNameSpace(string(output))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -81,13 +91,10 @@ func (f *File) SetCellStr(sheet string, axis string, value string) {
|
|
|
|
xlsx = completeRow(xlsx, rows, cell)
|
|
|
|
xlsx = completeRow(xlsx, rows, cell)
|
|
|
|
xlsx = completeCol(xlsx, rows, cell)
|
|
|
|
xlsx = completeCol(xlsx, rows, cell)
|
|
|
|
|
|
|
|
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].T = `str`
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
|
|
|
|
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
|
|
|
|
|
|
|
|
|
|
|
|
output, err := xml.Marshal(xlsx)
|
|
|
|
output, _ := xml.Marshal(xlsx)
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
f.saveFileList(name, replaceRelationshipsID(replaceWorkSheetsRelationshipsNameSpace(string(output))))
|
|
|
|
f.saveFileList(name, replaceRelationshipsID(replaceWorkSheetsRelationshipsNameSpace(string(output))))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|