Blue Prism excel

rohitsle

New Member
Hi All,

I have a scenario in which the original excel contains data like

1/1/2018 12:00:00 AM
1/1/2018 01:00:00 AM
.
.
.
1/1/2018 23:00:00 PM

Now sometimes we receives the file from source destination with missing data
example :
1/1/2018 12:00:00 AM
1/1/2018 01:00:00 AM
1/1/2018 02:00:00 AM (Missing in source file ).
1/1/2018 03:00:00 AM (Missing in source file ).
.
.
1/1/2018 16:00:00 PM (Missing in source file ).
.
.
1/1/2018 23:00:00 PM

now could you please help me in the logic to insert the missing value in the excel .

Please Note: I know how to create excel , copy data to excel from collection and vice versa

Thanks in advance !!
 

Attachments

  • orginal.png
    12.8 KB · Views: 42
  • new incoming data.png
    8.4 KB · Views: 39

VJR

Well-Known Member
Hi rohitsle,

If you want the data in the destination to be same as the source then why don't you simply do a copy paste of the source data to the destination? Simply overwrite the destination data with the source and both will be the same. Tell me more if there is more to your issue.
 

rohitsle

New Member
Hi @VJR ,

I have other calculations/modules to be completed before/after that expected result

Again my problem is :

new incoming data.png : is the file which we are getting from source system
orginal.png : is the expected result which i want to achieve

Thanks
 

VJR

Well-Known Member
Hi rohitsle,

There are multiple options to do this. You can choose an approach depending on what fits your situation based on how large the excel is, or whether you have more control on the Excel or on the Collection, etc.

i. You can extract the excel sheet into a collection. Then loop through the collection (lets call it Input Collection) where you compare the current row value with its previous row. You can use Date functions here.
As you navigate through each row, copy the same row into another collection (say Output Collection) based on the below conditions. You can use the Copy Row actions of the Collection VBO. Also take a look at the Append Collection action and use the one(s) that are feasible for this situation.

a. If there is a difference of 1 hr -> then it means it is correct -> Copy row to Output Collection -> Continue looping on Input Collection

b. If there is a difference of more than 1 hr -> then it means it is time to insert the missing row(s) -> insert a row to Output Collection by adding 1 hr to the previous row. Continue this till the time there is a gap of 1 hr between the current row of the Input Collection and the row that you just inserted into the Output Collection -> Once the timings are correct (meaning once you have added the yellow rows for one set) continue the loop on the Input Collection. Then the next yellow set and so on.

Handle the above logic appropriately for the 1st row in the collection while finding the 1 hr difference between current row and previous row as there will be no previous row.

Add 0 to the 'time in sec' column of the Output Collection for Step b.

When the loop on the Input Collection is over, the Output Collection will have the correct rows as per your requirement.
Its now up to you what you do with this collection. You can clear the old data and overwrite this Output collection onto the sheet.

ii. Another option is to make the changes directly on the excel sheet itself.
Use the same logic as No i. for comparing the data in the current row and the previous row, but this will involve a Code stage to loop through the data in the Excel sheet itself. Insert a row directly in the Excel sheet and update the data as needed.

iii. This approach will be without a Code stage but could be slower since you are reading once cell at a time.
Use the in built action Get cell value of the Excel VBO and read the its content.
Use a Counter data item and use it in the Get cell value; eg; "A & [Counter]" will give values of A1, A2, A3 as you increment the Counter using a Calc stage.
Use the same comparison logic as explained in approach no. i. above.
When its time to insert a row refer the Post #7 here
http://rpaforum.net/threads/how-to-insert-row-in-excel-sheet-using-ms-excel-vbo.7589/#post-13006
Make sure to handle the Counter accordingly when you add a new row.
Continue the Get cell value till you get a blank value indicating that you have reached one cell after the last row of the sheet.
 
Top