f04959c

New Member
Hello,

I need to convert from 'System.Data.DataRow' to 'String'.

Reading datas from a collection, I need to use them to create a Pivot table with more elements in row item,

I wrote the code used to create it but it doesn't work. Blueprism return me the error:

Internal : Could not execute code stage because exception thrown by code stage: Unable to get the PivotFields property of the PivotTable class

Here below the code

Code:
Dim rng as Object
Dim i as Integer

Dim wb as Object = GetWorkbook(handle,workbookname)
Dim ws as Object = GetWorksheet(handle,workbookname,worksheetname,createifmissing)

sheetexists = ws IsNot Nothing

If sheetexists then ws.Activate()

rng = ws.UsedRange()  'Change this to include any specific range

Dim PCache as object = wb.PivotCaches.Create(SourceType:=1, SourceData:= rng).CreatePivotTable _
(TableDestination:=ws.Range("F2"), TableName:="PivotTable1")

i = 1
For Each strRow As String In Rows.Rows.ToString
    If Not String.IsNullorEmpty(strRow) Then
        With ws.PivotTables("PivotTable1").PivotFields(strRow)
        .Orientation = 1    'For Row field
        .Position = i
        End With
    End If
    i = i + 1
Next
i = 1
For Each strColumn As String In Columns.Rows.ToString
    If Not String.IsNullorEmpty(strColumn) Then
        With ws.PivotTables("PivotTable1").PivotFields(strColumn) 'Column
        .Orientation = 2    'For Column Field
        .Position = i
        End With
    End If
    i = i + 1
Next

With ws.PivotTables("PivotTable1").PivotFields(Value)
.Orientation = 4    'For Value Field
.Position = 1
End with

Thanks
 

f04959c

New Member
Hello,

I found the solution to my issue.

Change the code as below:

Code:
[...]

For Each row as datarow in Rows.Rows

[...]

For Each column as datarow in Columns.Rows

[...]

Thanks
 
Top