|
|
@ -18,7 +18,6 @@ import (
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -33,8 +32,6 @@ const (
|
|
|
|
STCellFormulaTypeShared = "shared"
|
|
|
|
STCellFormulaTypeShared = "shared"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var rwMutex sync.RWMutex
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetCellValue provides a function to get formatted value from cell by given
|
|
|
|
// GetCellValue provides a function to get formatted value from cell by given
|
|
|
|
// worksheet name and axis in XLSX file. If it is possible to apply a format
|
|
|
|
// worksheet name and axis in XLSX file. If it is possible to apply a format
|
|
|
|
// to the cell value, it will do so, if not then an error will be returned,
|
|
|
|
// to the cell value, it will do so, if not then an error will be returned,
|
|
|
@ -181,8 +178,6 @@ func setCellDuration(value time.Duration) (t string, v string) {
|
|
|
|
// SetCellInt provides a function to set int type value of a cell by given
|
|
|
|
// SetCellInt provides a function to set int type value of a cell by given
|
|
|
|
// worksheet name, cell coordinates and cell value.
|
|
|
|
// worksheet name, cell coordinates and cell value.
|
|
|
|
func (f *File) SetCellInt(sheet, axis string, value int) error {
|
|
|
|
func (f *File) SetCellInt(sheet, axis string, value int) error {
|
|
|
|
rwMutex.Lock()
|
|
|
|
|
|
|
|
defer rwMutex.Unlock()
|
|
|
|
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -204,8 +199,6 @@ func setCellInt(value int) (t string, v string) {
|
|
|
|
// SetCellBool provides a function to set bool type value of a cell by given
|
|
|
|
// SetCellBool provides a function to set bool type value of a cell by given
|
|
|
|
// worksheet name, cell name and cell value.
|
|
|
|
// worksheet name, cell name and cell value.
|
|
|
|
func (f *File) SetCellBool(sheet, axis string, value bool) error {
|
|
|
|
func (f *File) SetCellBool(sheet, axis string, value bool) error {
|
|
|
|
rwMutex.Lock()
|
|
|
|
|
|
|
|
defer rwMutex.Unlock()
|
|
|
|
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -239,8 +232,6 @@ func setCellBool(value bool) (t string, v string) {
|
|
|
|
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
|
|
|
|
// f.SetCellFloat("Sheet1", "A1", float64(x), 2, 32)
|
|
|
|
//
|
|
|
|
//
|
|
|
|
func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) error {
|
|
|
|
func (f *File) SetCellFloat(sheet, axis string, value float64, prec, bitSize int) error {
|
|
|
|
rwMutex.Lock()
|
|
|
|
|
|
|
|
defer rwMutex.Unlock()
|
|
|
|
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -262,8 +253,6 @@ func setCellFloat(value float64, prec, bitSize int) (t string, v string) {
|
|
|
|
// SetCellStr provides a function to set string type value of a cell. Total
|
|
|
|
// SetCellStr provides a function to set string type value of a cell. Total
|
|
|
|
// number of characters that a cell can contain 32767 characters.
|
|
|
|
// number of characters that a cell can contain 32767 characters.
|
|
|
|
func (f *File) SetCellStr(sheet, axis, value string) error {
|
|
|
|
func (f *File) SetCellStr(sheet, axis, value string) error {
|
|
|
|
rwMutex.Lock()
|
|
|
|
|
|
|
|
defer rwMutex.Unlock()
|
|
|
|
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -291,6 +280,8 @@ func (f *File) setCellString(value string) (t string, v string) {
|
|
|
|
// setSharedString provides a function to add string to the share string table.
|
|
|
|
// setSharedString provides a function to add string to the share string table.
|
|
|
|
func (f *File) setSharedString(val string) int {
|
|
|
|
func (f *File) setSharedString(val string) int {
|
|
|
|
sst := f.sharedStringsReader()
|
|
|
|
sst := f.sharedStringsReader()
|
|
|
|
|
|
|
|
f.Lock()
|
|
|
|
|
|
|
|
defer f.Unlock()
|
|
|
|
if i, ok := f.sharedStringsMap[val]; ok {
|
|
|
|
if i, ok := f.sharedStringsMap[val]; ok {
|
|
|
|
return i
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -371,8 +362,6 @@ type FormulaOpts struct {
|
|
|
|
// SetCellFormula provides a function to set cell formula by given string and
|
|
|
|
// SetCellFormula provides a function to set cell formula by given string and
|
|
|
|
// worksheet name.
|
|
|
|
// worksheet name.
|
|
|
|
func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error {
|
|
|
|
func (f *File) SetCellFormula(sheet, axis, formula string, opts ...FormulaOpts) error {
|
|
|
|
rwMutex.Lock()
|
|
|
|
|
|
|
|
defer rwMutex.Unlock()
|
|
|
|
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
xlsx, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
@ -697,6 +686,8 @@ func (f *File) SetSheetRow(sheet, axis string, slice interface{}) error {
|
|
|
|
|
|
|
|
|
|
|
|
// getCellInfo does common preparation for all SetCell* methods.
|
|
|
|
// getCellInfo does common preparation for all SetCell* methods.
|
|
|
|
func (f *File) prepareCell(xlsx *xlsxWorksheet, sheet, cell string) (*xlsxC, int, int, error) {
|
|
|
|
func (f *File) prepareCell(xlsx *xlsxWorksheet, sheet, cell string) (*xlsxC, int, int, error) {
|
|
|
|
|
|
|
|
xlsx.Lock()
|
|
|
|
|
|
|
|
defer xlsx.Unlock()
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
cell, err = f.mergeCellsParser(xlsx, cell)
|
|
|
|
cell, err = f.mergeCellsParser(xlsx, cell)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -728,6 +719,9 @@ func (f *File) getCellStringFunc(sheet, axis string, fn func(x *xlsxWorksheet, c
|
|
|
|
return "", err
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xlsx.Lock()
|
|
|
|
|
|
|
|
defer xlsx.Unlock()
|
|
|
|
|
|
|
|
|
|
|
|
lastRowNum := 0
|
|
|
|
lastRowNum := 0
|
|
|
|
if l := len(xlsx.SheetData.Row); l > 0 {
|
|
|
|
if l := len(xlsx.SheetData.Row); l > 0 {
|
|
|
|
lastRowNum = xlsx.SheetData.Row[l-1].R
|
|
|
|
lastRowNum = xlsx.SheetData.Row[l-1].R
|
|
|
|