【问题标题】:How to use fieldinfo parameter in text to column code using blue prism如何使用蓝色棱镜将文本中的 fieldinfo 参数用于列代码
【发布时间】:2020-04-20 12:50:04
【问题描述】:

我正在尝试使用蓝色棱镜代码阶段使用文本到列代码, 我设法以一种很好的方式做到了,但我的结果是 xlGeneralFormat 但我希望它们是文本格式

Dim wb, ws As Object
Dim excel, sheet, range As Object



Try


wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)

wb.Activate()
ws.Activate()
excel = ws.Application
sheet = excel.ActiveSheet
range = sheet.Range(Reference)
range.Select()

excel.selection.TextToColumns (DataType:=1,ConsecutiveDelimiter:=True,Other:=True,OtherChar:="_",fieldinfo:= "Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(4, 2), Array(5, 2))")

Success = True

Catch e As Exception
    Success = False
    Message = e.Message
Finally
    wb = Nothing
    ws = Nothing
    excel = Nothing
    sheet = Nothing
    range = Nothing
End Try

但它不起作用!

注意。没有fieldinfo:= "Array(Array(1, 2), Array(2, 2), Array(3, 2), Array(4, 2), Array(5, 2), Array(6, 2), Array(7, 2), Array(8, 2), Array(9, 2), Array(4, 2), Array(5, 2))",代码运行良好

但它是 xlGeneralFormat

有人可以帮忙解决这个案子吗?

【问题讨论】:

    标签: arrays excel vb.net blueprism


    【解决方案1】:

    也许您可以在之后更改列格式?喜欢这个:

    sheet.Columns("A:B").NumberFormat = "@"
    

    您将短语“A:B”更改为要格式化的列。或者你可以用一个范围来做到这一点:

    range.NumberFormat = "@"
    

    注意:“@”是文本格式的代码。

    【讨论】:

    • 我想在文本到列转换期间更改格式的原因是,当它在一般模式下(默认)转换时,长数字近似为022207175820010645000 became 22207175820010600000
    • 哦,我明白了。我对 TextToColumns 方法不是很熟悉,但是经过一些阅读了解到,这些数组元组中的第一个参数,如 Array(1, 2) 应该是要读取的字段的第一个字符的位置,所以你可能无法使用数组 Array(4, 2), Array(5, 2) 两次。也许您不想只提取一个字符字段。
    【解决方案2】:

    你可以像这样创建一个整数矩阵。

    Dim matrix = New Integer(6, 1) {{1, 1}, {2, 1}, {3, 9}, {4, 1}, {5, 1}, {6, 1}, {7, 1}}
    

    并将其用作 FieldInfo 的参数

    FieldInfo:=matrix
    

    完整代码如下:

    Dim wb, ws As Object
    Dim excel, sheet, range As Object
    Dim matrix = New Integer(6, 1) {{1, 1}, {2, 1}, {3, 9}, {4, 1}, {5, 1}, {6, 1}, {7, 1}}
    
    Try
    
    wb = GetWorkbook(Handle, Workbook)
    ws = GetWorksheet(Handle, Workbook, Worksheet)
    
    wb.Activate()
    ws.Activate()
    excel = ws.Application
    
    excel.Selection.TextToColumns (Destination:=excel.Range(Cell_Reference), DataType:=1, _
            TextQualifier:=-4142, ConsecutiveDelimiter:=False, Tab:=False, _
            Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _      
            :=Delimiter, FieldInfo:=matrix, TrailingMinusNumbers:=True)
    
    Success = True
    
    Catch e As Exception
        Success = False
        Message = e.Message
    Finally
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多