.net - 如何指定正确的列?

标签 .net spreadsheet openxml-sdk

我需要根据数据所在的字段(列)执行不同的操作。

            For Each row As DocumentFormat.OpenXml.Spreadsheet.Row In
                worksheet.Descendants(Of DocumentFormat.OpenXml.Spreadsheet.Row)
                    For Each cell As DocumentFormat.OpenXml.Spreadsheet.Cell In row
                        Select Case True
                            Case cell.CellReference.Value Like "C*"
                                'if this cell is in column C
                            Case cell.CellReference.Value Like "A*"
                                'if this cell is in column A
                            Case Else
                        End Select
                    Next
            Next

只要给定电子表格中的字段不超过 26 个,此方法就非常有效。

如何确保我的 Like "A*" 不会对 AA、AB 等列使用react?

请记住,OpenXML SDK 始终返回 .cellreference.value 的完整单元格引用,而不仅仅是列。 我需要指定,我并不是试图批量丢弃任何大于 26 的列,但我试图确保指定特定的列。受审查的列最终可能是 AA 或 AB,具体取决于创建特定源表的公司。我希望有一个属性,或者除此之外,其他人如何学会引用 openxml 中的特定列。

最佳答案

在您尝试匹配的列字母后面添加一个#将告诉匹配器该字母后面必须有一个数字。如果列实际上是 AA,这将阻止您检查 A 匹配。

Select Case True
    Case cell.CellReference.Value Like "C#*"
    'if this cell is in column C
    Case cell.CellReference.Value Like "A#*"
    'if this cell is in column A
    Case cell.CellReference.Value Like "AA#*"
    'if this cell is in column AA
    Case Else
End Select

来自documentation# 将匹配“任何单个数字 (0–9)”。

关于.net - 如何指定正确的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40243604/

相关文章:

csv - emacs 的电子表格模式,用于制表符分隔的文本文件

c# - 使用 OpenXML SDK 2.0 对来自 tableCell 的文本进行对齐

.net - 如何在 Windows 10 上安装 OpenXML SDK 生产力工具 2.5

excel-2007 - 如何使用 Open XML SDK 2.0 向 Excel 2007 中的单元格添加注释?

.net - System.Net.ServicePointManager 单例的范围是什么

sublimetext2 - 在 Sublime Text 中将多行文本列组合在一起

.net - 是否有用于保存文件系统路径的类?

java.lang.ClassCastException : com. google.gdata.data.TextContent 无法转换为 com.google.gdata.data.OutOfLineContent

c# - 将处理程序添加到我的组件父窗体的所有控件

c# - 通过 .Net Socket 发送/接收为串行通信构建的消息