I wanted to insert an objects into excel file using c# code.
Scenario is like:
Folder 1 : Contains below file
1. Abc_input.txt
2. Xyz_input.txt
Folder 2 : Contains Below file
1. Abc_output.txt
2. Xyz_output.txt
And the excel should looks like
| File Mask | Input | Output |
| Abc | Abc_input.txt | Abc_output.txt |
| Xyz | Xyz_input.txt | Xyz_output.txt |
Input and output data will be file objects from above folder.
Please advice on this structure.
Thanks in advance.
Regards,
Sagar

Anupam SinghRank #643 · 3.7K reputationPosted Jul 18, 2014, 11:37 PM EDT
Richard Porter34 reputationPosted Feb 27, 2015, 1:13 AM EST
string folder1 = @"C:\Folder 1"; string folder2 = @"C:\Folder 2"; ExcelFile excelFile = new ExcelFile(); ExcelWorksheet excelSheet = excelFile.Worksheets.Add("Sheet1"); excelSheet.Cells[0, 0].Value = "File Mask"; excelSheet.Cells[0, 1].Value = "Input"; excelSheet.Cells[0, 2].Value = "Output"; string[] textFiles = Directory.GetFiles(folder1, "*.txt"); for (int i = 0; i Path.GetFileNameWithoutExtension(textFiles[i]).Replace("_input", ""); excelSheet.Cells[1 + i, 1].Value = Path.GetFileName(textFiles[i]); } textFiles = Directory.GetFiles(folder2, "*.txt"); for (int i = 0; i Path.GetFileName(textFiles[i]); excelFile.Save(@"C:\Book1.xlsx");Note that I used this .NET component for excel files and as you may notice it has an easy to use interface for creating an excel's workbook with C#.