I have a case, where I have to copy/convert all Excel Files in one folder to CSV files. The sheets and names should remain in the CSV file. Currently every Excel file contains one sheet, but every sheet has a different name.
I have seen the solutions for similar cases, but no one with exact this case and I am wondering whether anybody had made this experience.
Hi @Anaskra ,
Convert Excel to CSV you can flow Step
-for each file in folder
-read range to get data table
-write csv to convert to CSV file
Regards,
LNV
For Each File in Folder (with filter *.xlsx)
** Excel Process Scope
*** Use Excel File (source file is from For Each File in Folder property)
**** For Each Sheet
***** Read Range
***** Write CSV (filename generated based on sheet name)
=> Use for each file in folder activity to iterate the files in the folder. In the filter by option give like “*xlsx”.
=> Inside for each Insert the Use excel file activity and pass the CurrentFile.toString in the Path of file.
=> Inside for each activity take an assign activity to store the file name create a variable called FileName (String Datatype).
Assign → FileName = CurrentFile.Name (Which stores the excel file name)
=> Take for each excel sheet activity to iterate the sheets in the excel. Output - CurrentSheet
=> Inside for each excel sheet activity insert the Read range activity to read the CurrentSheet data and store in to a datatable variable called dtExcelData.
=> After Read range activity place the Write CSV activity to write the datatable data to csv file.
In Write from field give the dtExcelData Variable.
In Write to what file give the Path of the csv file and give the name of excel name to csv.
Path - “C:\Users\Downloads"+FileName+”.csv"
In the Path give the csv path. FileName is the variable which stored the Excel file name.
Check the below workflow for better understanding.
Actually, let’s change this to avoid repeatedly executing the Excel Process Scope:
Excel Process Scope
** For Each File in Folder (with filter *.xlsx)
*** Use Excel File (source file is from For Each File in Folder property)
**** For Each Sheet
***** Read Range
***** Write CSV (filename generated based on sheet name)
Is this solution is working for you. If yes let me know and Make mark it as solution to close the loop.
If getting any issues with it then we are ready to solve the issues.
For Each
→ item in Files
→ assign FileName = Path.GetFileNameWithoutExtension(item.ToString)
→ Excel Application scope for item → Read Range FileName (output: DataTable)
→ Write CSV from Data Table to TargetFolder+FileName+“.csv”
The only issue I am facing is that this isn’t working for huge excel files. Does anybody know how to solve that?
Quick tip, you don’t have to create a variable and assign the GetFiles out put to it. You can just put your GetFiles expression directly into the For Each. This is simpler and eliminates the need for the extra variable and Assign activity.