gpt4 book ai didi

vb.net - 如何使用 openxml 2.0 创建日期单元格

转载 作者:行者123 更新时间:2023-12-01 14:37:46 24 4
gpt4 key购买 nike

尝试使用 openXML 2.0 库创建日期单元格。在某些情况下,会显示日期,但 Excel 在打开文件时会出错。如果我删除日期单元格,它会毫无错误地打开。有人知道怎么回事吗?

Protected Function CreateCell(columnIndex As Integer, rowIndex As Integer, value As DateTime) As Cell

Dim cell As New Cell()
cell.DataType = CellValues.Date
Dim v As CellValue = New CellValue()
v.Text = value.ToString()
cell.CellValue = v
Return cell

End Function

Protected Function CreateCell(columnIndex As Integer, rowIndex As Integer, value As Double) As Cell
Dim cell As New Cell()

cell.DataType = CellValues.Number
'cell.CellReference = getColumnName(columnIndex) & rowIndex
cell.CellValue = New CellValue()
cell.CellValue.Text = value.ToString()
Return cell
End Function

最佳答案

如果您从 this article 下载代码并查看 ExcelInterface.vb,您会看到一些代码,这些代码基于 (ECMA-376 Part 1, 18.8.30) 检测日期的隐式单元格格式。您也应该能够对此进行调整以设置它们。另请参阅将 Excel 日期和时间与 .NET 相互转换的例程,因为您需要将 Excel(电子表格)日期值放入日期格式的单元格中。

关于vb.net - 如何使用 openxml 2.0 创建日期单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11249610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com