我想從我的類數據源讀取參數的引用閱讀字符串作爲一個變量
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都採用String作爲參數來獲取Excelrow和Excelcolumn。有誰知道我怎麼能達到這些字符串SHEETNAME和excelCell不被視爲一個字符串,但是從數據源的一個引用字符串(以便例如「C6」被訪問,而不是「Datasource.M_LOC」?
謝謝,這幫了我很多! – Lars