如何使用Apache POI从Excel获取货币代码?

时间:2017-04-04 08:27:09

标签: java excel apache-poi

我正在使用POI来解析Excel文件和reg。用于检测NumericCellValue中的货币的表达式。我在Excel文件中有2个字段,有2种差异货币(100美元和100欧元),我需要获取他们的货币代码(“USD”,“EUR”)。

case Cell.CELL_TYPE_NUMERIC: {
    Pattern p = Pattern.compile(currencyFilter);
    Matcher m = p.matcher(dataFormat);
    if (m.find()) {
         BigDecimal aCurrency = currentCell.getNumericCellValue();
         //I need to pass my currency code from cell field to money instance
         Money money = new Money(aCurrency, "USD");
    }
}

1 个答案:

答案 0 :(得分:1)

String currencyCode = "";
if (dataFormat.contains("$$")) {
    currencyCode = "USD";
}
else if (dataFormat.contains("$€")) {
    currencyCode = "EUR";
}
moneyCurrency = new Money(bd, currencyCode);