I need to separate each duplicate row based on column into their own excel file based on the query from a database.
Example of the data are:
I want them to be separated like below:
Any idea how?
Perhaps you could use a Linq query and group by the invoice number.
Please check Linq query for groupby and sum - #3 by GBK
For File 1 you can use below group by code, @Seungwan
Dt.AsEnumerable.GroupBy(Function(x) x(“ColumnName”).ToString.Trim).Select(Function(s) s(0)).CopyToDataTable()
lets assume following input:
and following variables:
first we group the data and find out the longest group:
(From d In dtData.AsEnumerable
Group d By k=d(0).toString.Trim Into grp=Group
`Groups.Max(Function (x) x.Count)`
Prepare a list of empty Datatables:
(From i In Enumerable.Range(0,MaxGroupCount)
Select tbl = dtData.Clone).toList
Iterate over the groups, iterate over the group members and add the member based on its occurence to the corresponding datatable from the tablelist:
With iterating over the list of datatables the datatables can be written to Excel as common with a write range
Find starter help here:
SplitGroups_1Col_toGrpCountSegment.xaml (10.1 KB)
Thanks for the long explanation for the solution, it works like a charm!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.