2016-10-25 19 views
2

我需要做基于其字段(列)不同的事情的数据是。如何指定正确的列?

  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,等等?

记住的OpenXML的SDK始终返回.cellreference.value一个完整的单元格引用,而不是仅仅列。 而且我需要指定我不想批量抛出大于26的任何列,但我试图确保指定了特定的列。被审查的专栏有可能最终成为AA或AB,具体取决于创建具体来源表的公司。我希望有一个属性,或者除了那个,其他人已经学会了如何引用openxml中的特定列。

+0

你可以从单元格中获得列吗? – ChrisF

+0

@ChrisF谢谢。据我所知,获得列的唯一方法是使用'.cellreference.value',它返回一个字符串。如果存在另一种获取引用的方式(可能采用不同的格式),它似乎没有记录在MSDN中。 – CWilson

+0

我没有想到数据,只是获取参考的列部分。 – ChrisF

回答

2

添加列字母(S)你想匹配会告诉匹配,必须有字母后的数字后#。如果该列实际为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)”。

相关问题