使用多维数组 [英] Working with multi dimentional arrays

查看:82
本文介绍了使用多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在寻找建议。所以让我解释一下我的项目:



我从多个excel文件中获取了一些值。没有任何excel文件数。它可能只有1个文件,也可能是100个文件。



我从中获取值:报告编号和此报告编号< b>值

在Excel文件中,可能只有1个报告编号和值,或者可能是1000个报告编号和值。



这是一个示例excel文件:(当然不像这个样本,我正在挖掘得到这个值)



Excel 1:



报告编号(第0栏)|值(第1列)//此行是标题

Report_No_1(第0列)| 1,253(第1栏)//第1行

Report_No_4(第0栏)| 12(第1列)//第2行

Report_No_2(第0列)| 323(第1栏)//第3行

Report_No_28(第0栏)| 7653(第1栏)//第4行

Report_No_12(第0栏)| 53(第1列)//第5行

...





我需要得到所有这些来自这里的数据擅长并创建一个这样的新excel:



新Excel:



Excel名称(第0列|) Report_No_1 | Report_No_2 | Report_No_3 | Report_No_4 //此行是标题

Excel 1 | 1,253 | 323 |没有| 12

Excel 2 |没有|无| 45 | 762

Excel 3 ...

Excel 4 ...

...



根据这些样本,我的目标是:



- 从所有excels获取所有数据

- 对所有报告编号进行排序1到最高报告编号

- 为每个报告编号添加一列

- 将每个报告值写入正确的单元格(excel x报告编号)



我正在考虑创建一个3D数组或列表(我不知道这个,列表是否可能?),如下所示:[excel name,report number,value]

然后我会根据报告编号对它们进行排序,并将此报告编号写入标题。最后用值填充单元格,用excel名称和报告编号进行验证。



我想问一下,是否可以创建3D列表?我将使用foreach循环打开所有excel。

我可以将多少个值添加到数组中?在这个项目中,我需要分钟。 10000.

这是在数组中使用10000个值的好方法吗?或者跑步需要时间吗?



你还有其他建议可以获得价值吗?



谢谢。



我的尝试:



只是寻找建议。

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.

推荐答案

您可能不想创建3D数组或列表:输出数据不是你所显示的3D,所以你可能只想要一个2D数组,或者(或许更好)一个列表列表(可能是一个字典列表会更好。)

分别创建标题row - 它是所有工作表中所有列的总列表 - 只需检查并添加到新项目中。

数据本身:

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:
List<Dictionary<string, YourDataType>> sheets = new List<Dictionary<string, YourDataType>> ();

对于每张工作表,创建一个新的词典:

For each sheet, create a new Dictionary:

Dictionary<string, YourDataType> sheet = new Dictionary<string, YourDataType>();



将工作表数据添加到其中(添加新的根据需要将标题列添加到标题中并将添加到集合中。

要创建输出,请遍历并检查每个标题:如果它在 Diction中,请使用该值,否则使用无。



有意义吗?


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?


这篇关于使用多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆