Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I'm looking for a suggestion. So let me explain my project :

I'm getting some values from multiple excel files. There isn't any count of excel files. It could be just 1 file or could be 100 files.

I'm getting values from them: report number and this report numbers value
In excel file could be just 1 report number and value or could be 1000 report numbers and values.

Here is a sample excel file : ( Of course it's not clear like this sample, I'm digging to get this values )

Excel 1 :

Report Number ( Column 0 ) | Value ( Column 1 ) // This line is header
Report_No_1 (Column 0 ) | 1,253 (Column 1) // row 1
Report_No_4 (Column 0 ) | 12 (Column 1) // row 2
Report_No_2 (Column 0 ) | 323 (Column 1) // row 3
Report_No_28 (Column 0 ) | 7653 (Column 1) // row 4
Report_No_12 (Column 0 ) | 53 (Column 1) // row 5
...


I need to get all this data from this excels and create a new excel like this :

New Excel :

Excel Name (Column 0 ) | Report_No_1 | Report_No_2 |Report_No_3 |Report_No_4 // this line is header
Excel 1 | 1,253 | 323 | None | 12
Excel 2 | None | None| 45 | 762
Excel 3 ...
Excel 4 ...
...

According to these samples, my goals are :

- Get all data from all excels
- Sort all report numbers from 1 to highest report number
- Add a column for each report number
- Write every report value to correct cell ( excel x report number )

I'm thinking to create a 3D Array or list ( i don't know this, is it possible for a list ? ) like this : [ excel name, report number, value ]
Then I will sort them according to report number and write this report numbers to headers. And finally fill the cells with values, verifying with the excel name and report number.

I want to ask, is it possible to create a 3D list? I will open all excels with a foreach loop.
And how many values can I add to an array? In this project, I need to min. 10000.
Is it a good way to use a 10000 values in an array ? Or is it takes time during to running ?

Do you have any other way suggestion to get values?

Thank you.

What I have tried:

Just looking for a suggestion.
Posted
Updated 25-Dec-18 19:47pm

1 solution

You probably don't want to create a 3D array or list: the output data isn't "3D" from what you show, so probably you just want a 2D array, or (maybe better) a List of Lists (possibly a List of Dictionaries would be better.)
Create the header "row" separately - it's the "total list" of all columns from all sheets - just check and add to that as new items come up.
The data itself:
C#
List<Dictionary<string, YourDataType>> sheets = new List<Dictionary<string, YourDataType>> ();
For each sheet, create a new Dictionary:
C#
Dictionary<string, YourDataType> sheet = new Dictionary<string, YourDataType>();

Add your sheet data to that (adding new columns to the header as required) and add the sheet to the sheets collection.
To create the output, iterate through the sheets and check each header: if it's in the sheet Diction, use the value, otherwise use "None".

Make sense?
 
Share this answer
 
Comments
kozmikadam 26-Dec-18 12:29pm    
Thank you for that information! I never heard about it actually. Looking at some samples now and trying to get what you saying. Will try this one now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900