[英]How to use fieldinfo parameter in text to column code using blue prism
I am trying to use text to columns code using the blue prism code stage, I managed to do it in a good way but my results are in xlGeneralFormat but I want them in text format我正在尝试使用蓝色棱镜代码阶段的文本到列代码,我设法以一种很好的方式做到了,但我的结果是 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
but it doesn't work !但它不起作用!
NB.注意。 The code works well without 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))"
该代码在没有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))"
but it's in xlGeneralFormat但它是xlGeneralFormat
Anybody Can help about this case?任何人都可以帮助解决这个案例吗?
Maybe you could change the column format just afterwards?也许您可以在之后更改列格式? Like this one:像这个:
sheet.Columns("A:B").NumberFormat = "@"
where you change the phrase "A:B" with the columns you want to format.您可以在其中使用要格式化的列更改短语“A:B”。 Or you could do this with a range:或者你可以用一个范围来做到这一点:
range.NumberFormat = "@"
Note: "@" is the code for text format.注意:“@”是文本格式的代码。
You could create an Integer matrix like this.您可以像这样创建一个 Integer 矩阵。
Dim matrix = New Integer(6, 1) {{1, 1}, {2, 1}, {3, 9}, {4, 1}, {5, 1}, {6, 1}, {7, 1}}
And use that as the parameter for FieldInfo并将其用作 FieldInfo 的参数
FieldInfo:=matrix
Full Code like this:像这样的完整代码:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.