- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正忙于开发一个从 MS Excel (2016) 文件导入数据的组件。该组件使用 MS OpenXML SDK2.5 库。 MS Excel 的最终用户安装基于荷兰国家/地区设置。该文件包含一列财务数据(数字)等。该列的位置事先未知。
为了确定单元格是否包含数字数据,我评估属性 Cell.DataType(类型为 CellValues,是一个枚举)。乍一看,这个属性似乎是确定这一点的完美候选者。 CellValues 的可能值为: bool 值、数字、错误、共享字符串、字符串、内联字符串或日期。所以我希望 Cell.DataType 设置为 CellValues.Number。经过一些调试后,我发现当单元格包含数字数据时,Cell.DataType 为 null。
在互联网上搜索解释时,我发现了以下 MSDN 文章: https://msdn.microsoft.com/en-us/library/office/hh298534.aspx
这篇文章准确地描述了我在调试过程中发现的内容:
The Cell type provides a DataType property that indicates the type of the data within the cell. The value of the DataType property is null for numeric and date types.
有人知道为什么 Cell.DataType 没有分别用 CellValues.Number 或 CellValues.Date 初始化吗?
确定单元格是否包含数值的最佳方法是什么?
最佳答案
Does anybody know why Cell.DataType is not initialized with respectively CellValues.Number or CellValues.Date?
从here看ECMA-376标准,Cell
的(缩写)XSD 如下所示:
<xsd:complexType name="CT_Cell">
...
<xsd:attribute name="t" type="ST_CellType" use="optional" default="n"/>
...
</xsd:complexType>
该属性代表类型。请注意,它是可选的,默认值为“n”
。第 18.18.11 节 ST_CellType(单元类型)列出了该类型的有效值:
b - boolean
d - date
e - error
inlineStr - an inline string
n - number (the default)
s - a shared string str - a formula string
您可以看到“n”
代表一个数字
。
What is the best way to determine if a cell contains a numeric value?
从上面看来,您可以检查 Cell.DataType
或 Cell.DataType
为 CellValues.Number
来判断一个单元格是否包含数字,但事情并不那么简单 - 大问题是日期。
日期的原始存储机制似乎是使用数字并依靠样式来知道该数字是否实际上是数字或者该数字是否代表日期。
令人困惑的是,规范已更新为包含 Date
类型,但并非所有日期都会使用日期类型。 Date
类型意味着单元格包含 ISO 8601 格式的日期,但它对于将日期存储为具有正确样式的数字来说是完全有效的。例如,以下 XML 代码段以 Number
和 Date
格式显示相同的日期(2017 年 2 月 1 日):
<sheetData>
<row r="1" spans="1:1" x14ac:dyDescent="0.25">
<c r="A1" s="1">
<v>42767</v>
</c>
</row>
<row r="2" spans="1:1" x14ac:dyDescent="0.25">
<c r="A2" s="1" t="d">
<v>2017-02-01</v>
</c>
</row>
</sheetData>
在 Excel 中打开时如下所示:
如果您需要区分日期和数字,那么您将需要查找任何数字(空 Cell.DataType
或 CellValues 的
),然后检查这些单元格的样式以确保它们是数字而不是伪装成数字的日期。Cell.DataType
)。 Number
关于c# - OpenXML SDK2.5(Excel): How to determine if a cell contains a numeric value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42390713/
我很难找到正确的搜索语法:) 作为作业的一部分,我正在为 Android 开发一个国际象棋游戏。 我想使用按钮。 我画了棋盘,可以选择一个按钮(即我要移动的棋子)。 我可以点击一 block (按钮)
我有两个类,一个依赖于硬件,一个不依赖于硬件(我们分别称它们为 HardwareDependent 和 HardwareIndependent)。硬件相关类扩展了硬件独立类。现在我有另一个类,它至少必
在这里得到一个 Hibernate MappingException,我不知道为什么。 这是我得到的错误: 2014/01/13 23:58:38 [] ERROR GrailsContextLoad
我想了解 RODBC 如何确定新创建的 (Access) 表的列类型? sqlSave 的 R 文档非常神秘:“类型是通过咨询参数 varTypes 和 typeInfo 来选择的”。并且没有这个论点
我有一个具有定义高度的 div,并且 overflow:scroll; 。它的内容太长,因此出现滚动条。 现在是发痒的部分。它的一些内部 HTML 总是奇怪地出现(准确地说,是 tableFilter
场景 某些 SQL 代理作业计划全天每隔几分钟运行一次。 在某些情况下,它会错过下一个计划,因为它仍在按照上一个计划运行。 每隔一段时间,作业可能会“挂起”。这不会产生失败(因为作业尚未停止)。发生这
目前我使用这个解决方案来加载资源: URL url = MyClass.class.getClassLoader().getResource("documents/"+path); if(url ==
我正在尝试使用nRoomAllocationId在房间传输和房间部门映射类上实现多对一和一对多双向映射。 房间转移类 @Entity @Table(name="roomtransfer") publi
我有一个来自类的 print 方法: public void print(EditorPanePrinter epp) { try { PrinterJob pj=Printe
确定文件所在目录的好方法是什么?我会使用 realpath(),但这会返回符号链接(symbolic link)指向的文件或目录的绝对路径。 例如,如果参数是文件的基名,并且 lstat() 返回 0
我有一个名为 account 的抽象类,如下所示 - abstract class Account { private int number; private String owner
我一直在编写一个打开 Firebird 数据库的小型 Python 应用程序。 为了实现此目标,我使用嵌入的 Firebird 2.5.7.27050,64 位。 尽管如此,无论何时我尝试使用 Pyt
我有一个非常有趣的(至少对我而言)问题要解决(而且,不,这不是家庭作业)。它等同于:您需要确定用户在他的计算机前进行的“ session ”和“ session 开始和结束时间”。 您将获得进行任何用
从 iOS8 开始,您需要注册并提示用户使用本地通知。因此,我想实现一种方法来仔细检查这些权限。 如何检查本地通知设置是否未确定/未设置?到目前为止,我只知道如何检查本地通知是否被granted 或d
在我的应用程序中,我使用 Google In-app Billing Version 3 API 实现应用内购买。在我的应用程序的日志中,我看到: D/Finsky (26024): [1204]
我的小部件有几个 ImageButtons,为它们设置 onClicked 事件,我使用 PendingIntent: Intent intent = new Intent(context, Upda
推送到 github 工作正常。我认为当我从 github checkout 一个分支时,这个问题就开始了。我该如何解决?当我现在尝试推送到 github 时,出现错误“无法确定当前分支。” 此外,我
我正在尝试使用表数据导入向导工具将一个 csv 文件导入到我的数据库中,导入到只有一个属性(它的 ID VARCHAR(10))的表中,导入失败并向我显示此错误:error我检查了 csv 文件以查找
我正在尝试将一些随机生成的数字“合并”在我之前拥有的值向量中的相邻值之间定义的间隔之间。所以基本上,我有以下几点: vectorA包含从 101 到 0 的 101 个值。 我生成一个名为 x 的随机
我要执行一个脚本file.R使用 Rscript .在 file.R ,我使用包dplyr . # file.R df outputFile.Rout 2>&1 但是,如果我添加 default-p
我是一名优秀的程序员,十分优秀!