Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetCellType retunrned Cell type is different in xlsx created by Excel and LibreCalc #1041

Closed
CHANTXU64 opened this issue Oct 23, 2021 · 2 comments
Labels
wontfix This will not be worked on

Comments

@CHANTXU64
Copy link
Contributor

Description

在Excel或LibreOffice编辑的xlsx文件中,对数字或日期类型的数据使用GetCellType()但得到的结果不正确,且两个软件编辑的xlsx文件返回的结果还不一样。

Steps to reproduce the issue:

  1. 用Microsoft Excel新建testGetCellType.xlsx, 在A列写入:
A
1 100
2 abc
3 TRUE
4 2021-10-1
5 1000.1
6 =1/0
  1. 运行如下代码:
func main () {
  f, err := excelize.OpenFile("./testGetCellType.xlsx")
  if err != nil {
    fmt.Fprintln(os.Stderr, err)
    return
  }
  fmt.Println(f.GetCellType("Sheet1", "A1"))
  f.SetCellInt("Sheet1", "A1", 1)
  fmt.Println(f.GetCellType("Sheet1", "A1"))
  fmt.Println(f.GetCellType("Sheet1", "A2"))
  fmt.Println(f.GetCellType("Sheet1", "A3"))
  fmt.Println(f.GetCellType("Sheet1", "A4"))
  fmt.Println(f.GetCellType("Sheet1", "A5"))
  fmt.Println(f.GetCellType("Sheet1", "A6"))
  f.Close()
}
/*
const (
  CellTypeUnset CellType = iota
  CellTypeBool
  CellTypeDate
  CellTypeError
  CellTypeNumber
  CellTypeString
)
*/

Describe the results you received:

0 <nil>
0 <nil>
5 <nil>
1 <nil>
0 <nil>
0 <nil>
3 <nil>

当我不使用Excel而使用LibreOffice写入, 结果为:

4 <nil>
0 <nil>
5 <nil>
1 <nil>
4 <nil>
4 <nil>
3 <nil>

Describe the results you expected:

4 <nil>
4 <nil>
5 <nil>
1 <nil>
2 <nil>
4 <nil>
3 <nil>

Output of go version:

go version go1.17.1 darwin/arm64

Excelize version or commit ID:

5f907b78245a

Environment details (OS, Microsoft Excel™ version, physical, etc.):
macOS 11.6 (M1)
Microsoft Excel 16.54
LibreOffice 7.2.1.2 / LibreOffice Community (Build ID: 87b77fad49947c1441b67c559c339af8f3517e22)

@xuri
Copy link
Member

xuri commented Oct 23, 2021

Thanks for your issue. The type of the cell inner spreadsheet has some differences between Microsoft Excel and Libre Office Calc, the type of numeric cell value will be ignored sometimes in the Excel, so you will get the CellTypeUnset, and normally, the date/time will be stored as numeric in Excel and LibreCalc, the value will apply number format style and show as a date text when you're open the spreadsheet, so you will get the CellTypeUnset or CellTypeNumber for that. I think the GetCellType should return the original type of the cell, the developer can be cast the cell type by them selfs.

@CHANTXU64
Copy link
Contributor Author

谢谢

@xuri xuri changed the title 对数字或日期类型的数据使用GetCellType()但得到的结果不正确 GetCellType retunrned Cell type is different in xlsx created by Excel and LibreCalc Oct 24, 2021
@xuri xuri added the wontfix This will not be worked on label Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants