1

有一个新的过程要实现,它涉及从 Excel 文件中写入和读取。为此,该过程需要一些属性来定义用于写入/读取值的工作表和单元格。根据我们可以说的类别,可以使用固定数量的属性。举个例子:

category1.sheet1=Customer Info
category1.cell1=A10
category1.cell2=B10
category1.cell3=A20

category2.sheet1=Customer Data
category2.cell1=A20
category2.cell2=B20
category2.cell3=A25

//more categories...

在此过程中,在某个步骤中,我决定了我正在使用的类别,然后我必须只使用该类别的属性。如何加载单个类别的属性?

目前,我有这种方法(简化代码以便更好地理解):

//get category1 or category2 based on some rules...
String category = getCurrentCategory();
//define the name of the properties to use
String sheet1 = category + "sheet1";
String cell1 = category + "cell1";
String cell2 = category + "cell2";
String cell3 = category + "cell3";
//use the properties...
String sheet1Value = getProperty(sheet1);
String cell1Value = getProperty(cell1);

//excelFileHandler is a custom interface to work with Excel files
//it serves as facade to communicate with Apache POI classes
excelFileHandler.goToSheet(sheet1Value).goToCell(cell1Value).setValue("some value");
excelFileHandler.goToCell(cell2Value).setValue("some value");

是否有另一种方法来解决此类问题,或者我应该保留这种设计?

注意:我处于设计阶段,所以我仍然可以改变方法。

4

1 回答 1

2

用于ExtendedProperties按属性前缀过滤。

请参阅Commons Collections ExtendedProperties#subset()

于 2013-08-07T16:06:14.633 回答