2012-03-13 12 views
0

`誰かが私にこの問題を助けたり、別の方法で助けてくれるのだろうかと思います。私はtestNGフレームワークを使用してJavaでコーディングするセレンwebdriverを使用しています。arraylistsを含む関数から複数の文字列値を抽出するには

基本的に、私はExcelからデータを抽出し、それらをarraylistsとして保存する方法を持っています。したがって、たとえば、私は

この種のデータを持っている:

Region  Text1 Text2 Text3 
UK   uk_t1 uk_t2 uk_t3 
usa   usa_t1 usa_t2 usa_t3 
russ  rus_t1 rus_t2 rus_t3 

私の方法は、列名

例 -

Arraylist<String>region = new ArrayList<String>(); 
Arraylist<String>text1 = new ArrayList<String>(); 
Arraylist<String>text2 = new ArrayList<String>(); 
Arraylist<String>text3 = new ArrayList<String>(); 


ArrayList<String> mydatacells = dataFromExcel(xlspath) // the method on the right is the one with the excel function 

String xlspath = "example/mylocation"; 


int uk = 4; //location of the cell that contains the string uk 
int usa = 8; //location of the cell that contains the string usa 
int russ = 12; //location of the cell that contains the string russ 
に基づいてExcelとのArrayListに格納するからすべての情報を抽出し、

次に、以下のようにして、地域固有のデータを抽出します。

for(uk=4; uk<usa; uk++){ 

region.add(mydatacells.get(uk)); 
text1.add(mydatacells.get(uk)); 
text2.add(mydatacells.get(uk)); 
text3.add(mydatacells.get(uk)); 

} //the code assigns the value for uk 

私の問題は、私は別の方法でこれらの値を使用する必要があり、私はすべてのデータを取得する必要があることです。

これを行う方法やこれを効率的に行う方法を知っている人はいますか?

おかげ

答えて

1

それはマップ内のデータを持っている方が簡単です - 私が想定し、最初のカラムの値がユニークであり、キー(インデックス)として使用することができます。それから私は、単一の行の値を保持するクラスを記述します

public class Location { 
    public String region; 
    public String text1; 
    public String text2; 
    public String text3; 
} 

を今、私はExcelシート

  • から行を読む
    1. をいただきたい場所
    2. のインスタンスを作成します
    3. このインスタンスをマップに配置するには、key:location.region、value:location
  • +0

    ありがとう。私はそれを試して、それがどうなるか見てみましょう。 –

    +0

    私はarraylistの代わりにマップを使用しようとしましたが、私はこれを行いました: –

    +0

    Map map = dataFromExcel(xlsPath) –

    関連する問題