Excel file to CSV creation with column value as file name

I have an excel with different types of produce like apples, grapes etc.
I have to create a csv file if the produce equal to Apples and create a file with that name.



I am able to create the files. But inside the file it is writing as follows:
image
image
So I have to have only the records of Apples-MISC if the file is Apples-MISC, if the file is Citrus-Orange I should only have Citrus-Orange inside but not other records. How can I achieve this. Appreciate all the help.

Thanks

Hi,

Can you share specific input files? it’s no problem if dummy data.

Regards,

Hi Yochi,
Please find the attached file. Sorry for the delayed reply.
Sampledata.xls (53 KB)

thanks

Hi,

If i understood your requirement correctly, the following will work. Can you try this?

dict = dt.AsEnumerable.GroupBy(Function(r) r("CATEGORY_NAME").ToString).ToDictionary(Function(g) g.Key,Function(g) g.CopyToDataTable)

Sample20230131-1L.zip (19.7 KB)

note: CSV files wll be created under result folder.

Regards,

Hi Yochi,

Thanks for the response, I am getting the error below when I run your code:

Use Excel File: Excel appears to be busy. Please check that you are not editing a value and that no dialog windows are opened.

Thanks,

Please ignore the error message I have given. Thanks for the solution. It is working and would you mind elaborating the following and can you also please tell me why did we use dictionary here:

dt.AsEnumerable.GroupBy(Function(r) r(“CATEGORY_NAME”).ToString).ToDictionary(Function(g) g.Key,Function(g) g.CopyToDataTable)

TIA

Hi,

As the CSV data will be written by WrtiteCSV, it would be better to manage the data by a pair of category_name = file names and DataTable, I think.

image

Regards,

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