我想从我的类数据源中读取一个参数:
public class Datasource {
public final static String M = "M";
public final static String M_SHEET ="Config";
public final static String M_LOC = "C6";
public final static int M_DEFAULT = 2; // default value
...
}
通过使用方法changeParameters:
public static void changeParameter(String param, double value) {
String parameter = param.toUpperCase(); // uppercase to match the final variable from Datasource
InputStream inp = new FileInputStream(Datasource.EXCELFILENAME);
// Excelconnection
Workbook wb = WorkbookFactory.create(inp);
String sheetName = "Datasource." + parameter + "_SHEET";
Sheet sheet = wb.getSheet(sheetName);
String excelCell = "Datasource." + parameter + "_LOC";
int rowInt = getRow(excelCell);
Row row = sheet.getRow(rowInt);
int cellInt = getCell(excelCell);
Cell cell = row.createCell(cellInt);
cell.setCellValue(value);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(Datasource. EXCELFILENAME);
wb.write(fileOut);
fileOut.close();
}
getRow 和 getCell 都以字符串作为参数来获取 Excelrow 和 Excelcolumn。有谁知道我如何才能知道字符串 sheetName 和 excelCell 不被视为字符串,而是作为对来自数据源的字符串的引用(例如,访问“C6”而不是“Datasource.M_LOC”?