Java 如何直接从属性文件中包含键的Excel工作表中获取值

Java 如何直接从属性文件中包含键的Excel工作表中获取值,java,excel,Java,Excel,通过使用Java代码,如何直接从属性文件中包含键的Excel工作表中获取值?我的问题是: 我有一个xyz_en_US.properties文件。此属性文件包含英语语言的键和值。 现在,我还有一个Excel表格,其中包含键和值(即仅值转换为西班牙语,键仍为英语) 告诉我如何在eclipse中编写(java)实用程序源代码,以将西班牙语值检索到相应的英语键,我需要将该键和值存储在名为resourcebundle.java的separate文件中 是否可以使用arraylist和hashmap..?读

通过使用Java代码,如何直接从属性文件中包含键的Excel工作表中获取值?我的问题是:

我有一个xyz_en_US.properties文件。此属性文件包含英语语言的键和值。 现在,我还有一个Excel表格,其中包含键和值(即仅值转换为西班牙语,键仍为英语)

告诉我如何在eclipse中编写(java)实用程序源代码,以将西班牙语值检索到相应的英语键,我需要将该键和值存储在名为resourcebundle.java的separate文件中

是否可以使用arraylist和hashmap..?

读取excel文件。这是一个帮助您解决问题的代码片段

try {

    FileInputStream file = new FileInputStream(new File("C:\\test.xls"));

    //Get the workbook instance for XLS file 
    HSSFWorkbook workbook = new HSSFWorkbook(file);

    //Get first sheet from the workbook
    HSSFSheet sheet = workbook.getSheetAt(0);

    //Iterate through each rows from first sheet
    Iterator<Row> rowIterator = sheet.iterator();
    while(rowIterator.hasNext()) {
        Row row = rowIterator.next();

        //For each row, iterate through each columns
        Iterator<Cell> cellIterator = row.cellIterator();
        while(cellIterator.hasNext()) {

            Cell cell = cellIterator.next();

            switch(cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:
                    System.out.print(cell.getBooleanCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "\t\t");
                    break;
            }
        }
        System.out.println("");
    }
    file.close();
    FileOutputStream out = 
        new FileOutputStream(new File("C:\\test.xls"));
    workbook.write(out);
    out.close();

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
试试看{
FileInputStream文件=新的FileInputStream(新文件(“C:\\test.xls”);
//获取XLS文件的工作簿实例
HSSF工作簿=新的HSSF工作簿(文件);
//从工作簿中获取第一张工作表
HSSFSheet sheet=工作簿。getSheetAt(0);
//从第一张图纸开始遍历每行
迭代器rowIterator=sheet.Iterator();
while(roweiterator.hasNext()){
行=行迭代器。下一步();
//对于每一行,遍历每一列
迭代器cellIterator=row.cellIterator();
while(cellIterator.hasNext()){
Cell=cellIterator.next();
开关(cell.getCellType()){
case Cell.Cell\u类型\u布尔值:
System.out.print(cell.getBooleanCellValue()+“\t\t”);
打破
case Cell.Cell\u类型\u数值:
System.out.print(cell.getNumericCellValue()+“\t\t”);
打破
case Cell.Cell\u类型\u字符串:
System.out.print(cell.getStringCellValue()+“\t\t”);
打破
}
}
System.out.println(“”);
}
file.close();
FileOutputStream out=
新文件输出流(新文件(“C:\\test.xls”);
练习册。写(出);
out.close();
}catch(filenotfounde异常){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}

顺便说一句,居里夫妇想知道为什么excel工作表适用于i18n,我相信这是有原因的。在我看来,你可以自己使用属性文件。比如xyz______________________________。看看。

是的,这是可能的。您是在开发web应用程序、移动应用程序还是控制台应用程序?请告诉我怎么做?@user2511966:这里有一个建议。1) 将excel转换为csv 2)导入数据库3)请选择queryya先生,您是对的。!我也通过引用这些主题来编写代码。但我觉得将proeperty文件转换为西班牙语是手动完成的。然后使用getbundle()检索西班牙包;但是我不想像bcoz 1000那样做(我的上级也不希望这样),所以我想把en_US键映射到es_es(西班牙语)值,然后映射新的键值parir存储在新文件resourcebundle.java中。你给出的代码就像只检索excel工作表中的所有键值一样。没有对en_US属性和Excelsheet文件进行映射。请告诉我如何将它们放入arraylist或hashmap?您能告诉我如何获取Excelsheet中与属性文件的keyvalues匹配的每个值吗。