Get single or multiple columns in a new datatable, Where the separating denominator is a empty column

i was just wondering how can we get single or multiple columns data and add them into a new datatabale based on separated empty columns in between

Sample Dummy Data

image

here there will be three Sheets / Datatable

Sheet1

ghg
hg

Sheet2

tytyt | jh
fgf | jj

Sheet3

74
741

can you share the expected output
@indiedev91

Output :Col(0) as new Datatable Col(2) and Col(3) as new datatale and Col(5) as new Datatable

@indiedev91

Datatable1=datatable.defaultview.totable(false,“column0”)

Datatable2=datatable.defaultview.totable(false,“column1”,“column2”)

Datatable3=datatable.defaultview.totable(false,“column3”)

Here datatable is your input datatable varaible

Try this

Cheers

that is static , i knew defaultvalue can be used for this , but i want a dynamic logic that pairs coulmn and create a new datatble based on the sepration

you need to create the separate separately excel files with columns name or

in single ExcelFile only with different column names

@indiedev91

Try this Xaml

Xaml :- random data.zip (2.5 KB)

it will write in single ExcelFile with different sheets names based on the columns

@indiedev91

it will write in separate separately Excel files with based on columns names

Xaml : - random data.zip (2.4 KB)

@indiedev91

didnt understand , where is the empty column as seprator

hi @indiedev91
Please check This
Forum.zip (2.5 KB)

it Helps!

@indiedev91

Check the xaml which dinesh has shared
@Dinesh_Guptil
Cheers

1 Like

Thank you, Dinesh, for providing the solution. However, I’m also interested in comprehending the underlying logic. As I mentioned, this isn’t a business scenario; I devised it to construct a workflow and gain a better understanding of it.

My approach was to iterate through the columns as follows:

For each column in the datatable:
If the current column is null,
Collect all the columns to the left of the null column and add them to a new datatable.
Remove the null column and the collected columns from the original datatable.
For example:

Let’s say the current column is Col(0) and it contains data. The loop proceeds to the next column, Col(1), which is null. In this case, we gather all the columns to the left of Col(1), which is just Col(0). We then create a new datatable with only Col(0) and delete Col(0) and Col(1) from the original datatable.

For the next iteration, we move to Col(2) and Col(3), both of which have data, so no action is taken. We then move on to Col(4), which is null. Again, we collect the columns to the left of Col(4), which are Col(2) and Col(3), because Col(0) and Col(1) were already deleted in the previous iteration. We create a new datatable with Col(2) and Col(3), and subsequently, delete Col(2), Col(3), and Col(4).

Now, only Col(5) remains. This is where a problem arises, as it’s the last column with data. It gets skipped, and the loop proceeds to a non-existent column, concluding the execution with one column remaining.

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