nmjvk
(Nmjvk)
March 15, 2024, 1:04pm
1
Dear UiPathers
Is there a way to optimize this code so it runs faster? Right now it takes about 10 mins to go through all my rows and I have 1300 cells that needs to be written.
The code is not much but I would like to ehar if there are any better activities which can complete the same job but faster or any options you can tweak. Thanks in advance
Yours sincerely.
Khan. S
Matt67
(Matthieu LEVAL)
March 15, 2024, 1:14pm
2
Hello,
is tablecount number of rows of your excel file ?
I think you should first use read range workbook activity before the for each loop, and store the datatable.
Now you can loop through each row if it instead of creating collection from 0 to number of rows.
in your for each loop : update row item activity instead of writting cell directly, and update the needed field.
After loop : Write range workbook with entire datatable in Excel.
With this you update only one time Excel file, should be much faster.
kali
March 15, 2024, 1:16pm
3
Enumerable.Range(0,x) is fine, u dont need β.ToArray()β
Also work with dt in background and write one time would be quicker.
1 Like
ppr
(Peter Preuss)
March 15, 2024, 1:22pm
4
nmjvk:
Thanks in advance
Are you sure, that you want to write x times (x - rowcount) the same value into the same cell?
1 Like
nmjvk
(Nmjvk)
March 15, 2024, 1:38pm
5
Sorry, I fixed that, forgot to upload the new image. I am now writing to βBβ+(Convert.ToInt32(currentItem)).ToString
So you want to write the same value (βENS150121β) to 1300 cells?
ppr
(Peter Preuss)
March 15, 2024, 1:42pm
7
have a look here:
we write hello in one go to Range A3 - A9
So you can use the row count and can do it similar
As an alternate as mentioned by
kali:
work with dt
we can selectively update an Excel e.g. with a 1-Column only DataTable and using write range
1 Like
nmjvk
(Nmjvk)
March 15, 2024, 1:47pm
8
Dear Kali
Thanks, that worked just as I wanted. Thanks for pointing it out to me.
1 Like
nmjvk
(Nmjvk)
March 15, 2024, 1:47pm
9
Dear PPR
I see. It works much faster. I had to accept Kaliβs answer since he was the first, however, I thank you for also reaching out and helping! So thank you for that
1 Like
nmjvk
(Nmjvk)
March 15, 2024, 1:49pm
10
Dear ptrobot
Exactly, hwoever, I already got a solution. Haver a wonderful day forward :3
1 Like
system
(system)
Closed
March 18, 2024, 1:49pm
11
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.