Arrange the sheets from an excel file

Hello, Team!

I have an Excel file with multiple sheets named dd.MM.yyyy format. I want to use UiPath to arrange these sheets without using Excel Application Scope. Every day, new sheets are added, but instead of being arranged in order, they are placed after the last created sheet.

For example, i want the sheet “21.12.2023” to be after “20.12.2023”.

Can anyone help me, please?

Hi,

Can you try the following sample? This sorts sheet which name is dd.MM.yyyy style date without Excel.

Using wb As New ClosedXML.Excel.XLWorkbook(filename)
Dim sheets As ClosedXML.Excel.IXLWorksheets = wb.Worksheets
Dim arrSheetName  As String() = sheets.Select(Function(s) s.Name).OrderBy(Function(s) DateTime.ParseExact(s,"d.M.yyyy",System.Globalization.CultureInfo.InvariantCulture)).ToArray()
Dim i As int32 =1
For Each  s As String In arrSheetName
	wb.Worksheet(s).Position=i
	i=i+1
Next
wb.Save()
End Using

Please note that this sample assumes all the sheetname is dd.MM.yyyy style.

Sample
Sample20231208-2L.zip (9.4 KB)

Regards,

I have this error even the filename is declared


Hi,

Can you try to set argument of InvokeCode as the following?

Regards,

1 Like

GREAT!!!
Worked!
Thank you! :hugs: :pray:

1 Like

now, when i used read range workbook activity, I have the error; befor I use invoke code, the robot finction without error; but now I have the error:

“message”: “Read Range: Method not found: ‘Void ClosedXML.Excel.XLWorkbook…ctor(ClosedXML.Excel.XLEventTracking)’.”,
“level”: “Error”,

the entire message:

RemoteException wrapping System.MissingMethodException: Method not found: ‘Void ClosedXML.Excel.XLWorkbook…ctor(ClosedXML.Excel.XLEventTracking)’.
at UiPath.Excel.WorkbookFile…ctor(String workbookPath, String password, Boolean createNew)
at UiPath.Excel.Activities.WorkbookActivity1.ConstructWorkbook(String path, String password, Boolean createNew) at UiPath.Excel.Activities.WorkbookActivity1.BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Hi,

For now, can you try to upgrade UiPath.Excel.Activities package to the latest stable version?

Regards,

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.