-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When converting a cell value to date(time.Time) the resulting file doesn't work in Excel.
Steps to reproduce the issue:
- Open a file with Excelice
- Read a cell value and convert it to time.Time. Then save the resulting time to cell.
- Save file and try to open it with Excel.
Describe the results you received:
Excel warns: "We found a problem with some content."
Describe the results you expected:
Valid xlsx-file.
Output of go version:
go version go1.20 darwin/amd64
Excelize version or commit ID:
v.2.7.0
Environment details (OS, Microsoft Excel™ version, physical, etc.):
OS: MacOS Ventura 13.2
Code to reproduce
package main
import (
"fmt"
"log"
"strconv"
"time"
"github.com/xuri/excelize/v2"
)
func main() {
f, err := excelize.OpenFile("_tests/test.xlsx")
if err != nil {
fmt.Println(err)
return
}
defer func() {
// Close the spreadsheet.
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
const column = "A"
const sheet = "Sheet1"
row := 2
for {
cell := column + strconv.Itoa(row)
value, err := f.GetCellValue(sheet, cell)
if err != nil {
log.Println(err)
return
}
if value == "" {
break
}
date, err := time.Parse("January 02 2006", value)
if err != nil {
log.Println(err)
row++
continue
}
if err := f.SetCellValue(sheet, cell, date); err != nil {
log.Println(err)
return
}
row++
}
err = f.SaveAs("_tests/testDateFixed.xlsx")
if err != nil {
log.Println(err)
return
}
}
ps. Thank you for an amazing library!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working