Skip to main content
added 212 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace the String[] rows by Object[] and store the cell content as objects of type String, Integer, Double or Date. You can also implement a speficic class CellContent and store your rows as CellContent[] arrays, if you have specific requirements and a need to implement specific behaviour or methods for a content element.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace the String[] rows by Object[] and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace the String[] rows by Object[] and store the cell content as objects of type String, Integer, Double or Date. You can also implement a speficic class CellContent and store your rows as CellContent[] arrays, if you have specific requirements and a need to implement specific behaviour or methods for a content element.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

added 13 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace the StringString[] rows by ObjectObject[] and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace String by Object and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace the String[] rows by Object[] and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

added 41 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace String by Object and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace String by Object and store the cell content as objects of type String, Integer, Double or Date.

Assumed you need a generic solution, where the program is not tied to a specific column structure at run time, you can use an ArrayList of rows, where each row is a string array String[]. You will need an additional HashTable<String,int> to store the mapping of the column name to the column index (a HashMap will probably work, either). So if you have

 HashTable<String,int> columnMapping;
 ArrayList<String[]> tableValues;

you can implement getColumnValue by

 String getColumnValue(String columnName, int indexOfValue)
 {
     return tableValues.get(columnMapping.get(columnName))[indexOfValue];
 }

You may consider to add some error handling here, some code which determines the column names and some more code which reads the excel rows into the String arrays with one entry per column. If you need the values in a typed form, consider to replace String by Object and store the cell content as objects of type String, Integer, Double or Date.

Note this is a rough scetch of a general purpose solution. One can modify this and create different variants, for more specific requirements.

If you need a less generic variant, because your program expects a specific column structure, best solution is probably to create a specific DTO class MyRowType for holding the specific values of a row, and use a variable like ArrayList<MyRowType> tableValues for storing the table content.

added 41 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623
Loading
added 41 characters in body
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623
Loading
Source Link
Doc Brown
  • 220.3k
  • 35
  • 410
  • 623
Loading