My current approach to write a DataTable into an Excel file looks like this:
private void TestFunction(DataTable dataTable)
{
var tempFilePath = CreateTempFilePath("test.xlsx");
Log("Creating Excel file: " + tempFilePath);
var sequence = new System.Activities.Statements.Sequence();
var excelScope = new UiPath.Excel.Activities.ExcelApplicationScope() {
CreateNewFile = true,
WorkbookPath = tempFilePath
};
var writeRange = new UiPath.Excel.Activities.WriteRange() {
AddHeaders = true,
WorkbookPath = tempFilePath,
SheetName = "Sheet",
DataTable = dataTable
};
sequence.Activities.Add(excelScope);
sequence.Activities.Add(writeRange);
var workflowInvoker = new System.Activities.WorkflowInvoker(sequence);
workflowInvoker.Invoke();
}
However, the following Exception is thrown on execution:
The following errors were encountered while processing the workflow tree:
âLiteralâ: Literal only supports value types and the immutable type System.String. The type System.Data.DataTable cannot be used as a literal.
// Define the workflow application and the required activities
var sequence = new System.Activities.Statements.Sequence();
// Create an Excel scope activity
var excelScope = new UiPath.Excel.Activities.ExcelApplicationScope()
{
CreateNewFile = true,
WorkbookPath = tempFilePath
};
// Create a WriteRange activity and configure it to use a variable for the DataTable
var writeRange = new UiPath.Excel.Activities.WriteRange()
{
AddHeaders = true,
WorkbookPath = tempFilePath,
SheetName = "Sheet",
DataTable = new System.Activities.Variable<System.Data.DataTable>() { Default = dataTable }
};
// Add the Excel scope to the sequence
sequence.Activities.Add(excelScope);
// Inside the Excel scope, add the WriteRange activity
excelScope.Body = new System.Activities.Statements.ActivityAction()
{
Handler = writeRange
};
// Create a workflow invoker and execute the sequence
var workflowInvoker = new System.Activities.WorkflowInvoker(sequence);
workflowInvoker.Invoke();
excelScope.Body = new System.Activities.ActivityAction<UiPath.Excel.WorkbookApplication>() { Handler = writeRange };
vs
excelScope.Body = new System.Activities.Statements.ActivityAction<UiPath.Excel.WorkbookApplication>() { Handler = writeRange };
which doesnât compile ("CS0234 The type or namespace name 'ActivityAction<>' does not exist in the namespace 'System.Activities.Statements' (are you missing an assembly reference?)")
Thanks for pointing me to the GitHub repo! I didnât know that at all and itâs a very useful resource!
I tried to use the code from the examples but for me even some of the namespaces arenât recognized by UiPath (e.g. UiPath.Excel.Activities.API).
The example projects json contains "studioVersion": "24.4.0.0" but my version is 23.10.4. Maybe my version is too old? If so, where can I get the 2024 version? The product lifecycle page doesnât contain it yet.