Write Range: two datatable to one Excel

Hi,

I need write two different data table to one Excel file. For now, I am using write range activity and give two different starting cell parameter (one started from A6, another started form J6), but the second data table will overwrite the first one.

Could anyone provide other solution? Thank you.

Did u use the append range activity for the second datatable

Hi,

No, because I need write two data tables side by side, both of them should started form 6th row.

Hi @Astor

I have used like this sometime back and it didn’t overwrite for me,have use tried write range under workbook instead of using write range under excel.

Thanks

1 Like

Hi

Welcome back to UiPath forum

It won’t overwrite
The reason is you have any how specified the cell start like A6 and J6
But make sure that you don’t have more than J with first datatable
Only then it will overwrite the next time when you are writing from J6

So it should be fine

And we can do this with simple WRITE RANGE activity itself

Cheers @Astor

1 Like

Hi @Astor

It should work if you have only 9 columns in the first data table because if you have more than 9 columns in a first data table that comes under J6 also and if again you try to write the data using the second data table from J6 it will over right only those data of first data table which comes under J6 column.

So try to look at your column of the first data table and then create a dynamic range for your Second data table to write
Thanks

Hi @Palaniyappan @Gopal_Tewari1,

Both of them only have 3 columns, and actually I have already created dynamic range for both data table to write. In my case, the second data table always overwrite the first one (which is on the left side of Excel).
I have set a break point when first data table was written. It looks fine, but after continue write second data table and open the file again, a part of left side, which is the first data table’s content, is gone.

For example, If dt 1 contains 30 rows and dt 2 contains 15 rows, after write range dt 2, the 1st row ~ 15th row of dt 1 will be disappear.

Hi @prasath_S ,

Yes, I am using write range under workbook, but still have same situation. Thank you.

Hi @Astor
If possible could you please share the sample files with us as i am able to simulate your scenario and its working fine for me .
Please find the attached screen shot
Dt2
image

DT1
image

image

Final result

Fine

Let’s take like you have two datatable named dt1 and dt2

Now dt1 has five rows and three columns
And dt2 has seven rows and five columns

Let’s take like it is keep changing

  1. Use a assign activity like this

dt1_colcount = dt1.Columns.Count

Where dt1_colcount is a int32 variable

  1. Same for dt2 like this
    dt2_colcount = dt2.Columns.Count

  2. Now use a WRITE RANGE activity and mention the input as dt1 and cell range as
    “A1”

  3. And for dt2 use another write range and mention dt2 as input and cell range as

Convert.ToChar(65+dt2_colcount).Tostring+(“1”).ToString

This will write dt2 from very last column of dt1
As we have mentioned the start cell range with column count

Hope this would help you resolve this
Cheers @Astor

Hi, @prasath_S , @Gopal_Tewari1 , @Palaniyappan

I finally tried to change activity from write range “under workbook” to “under excel”, and… it works…
It still confuse me, I even did not modify any parameter… but, finally, I can move to next step. Thank you for your time and kindly reply.

2 Likes

@Astor glad your issue resolved, please mark the appropriate topic as solution and close the thread so it may be useful to others in the future.

Thanks

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