Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否可以使用java在excel xssf文档中查找文本并获取单元格索引,即[行号和列号]?_Java_Apache Poi - Fatal编程技术网

是否可以使用java在excel xssf文档中查找文本并获取单元格索引,即[行号和列号]?

是否可以使用java在excel xssf文档中查找文本并获取单元格索引,即[行号和列号]?,java,apache-poi,Java,Apache Poi,使用java查找并获取该文本的列和行值。 在Xssf文档中 使用java查找在excel文件中搜索的文本的位置这在中有介绍,建议您阅读 具体来说,在 根据那里的代码和您的需要,我们得到: String toFind = "needle in haystack"; Workbook wb = WorkbookFactory.create(new File("input.xlsx")); DataFormatter formatter = new DataFormatter(); Sheet sh

使用java查找并获取该文本的列和行值。 在Xssf文档中

使用java查找在excel文件中搜索的文本的位置这在中有介绍,建议您阅读

具体来说,在

根据那里的代码和您的需要,我们得到:

String toFind = "needle in haystack";

Workbook wb = WorkbookFactory.create(new File("input.xlsx"));
DataFormatter formatter = new DataFormatter();
Sheet sheet1 = wb.getSheetAt(0);
for (Row row : sheet1) {
    for (Cell cell : row) {
        CellReference cellRef = new CellReference(row.getRowNum(), cell.getColumnIndex());

        // get the text that appears in the cell by getting the cell value and applying any data formats (Date, 0.00, 1.23e9, $1.23, etc)
        String text = formatter.formatCellValue(cell);

        // is it an exact match?
        if (toFind.equals(text)) {
           System.out.println("Text matched at " + cellRef.formatAsString());
        }
        // is it a partial match?
        else if (text.contains(toFind)) {
           System.out.println("Text found as part of " + cellRef.formatAsString());
        }
    }
}

你试过什么吗?这是问题还是陈述?cell=objSheet.getRow34.getCell7;这样我可以设置内容..但我不知道要检索的确切位置,因为文本位置不固定文本位置更改。我需要像在windows中一样使用CTRL+F查找和替换文本,并使用查找文本替换所有行和单元格上的itLoop,然后使用?xssf工作簿objWorkbook=new检查单元格内容XSSFWorkbookobjFileInputStream;XSSFSheet objSheet=objWorkbook.getSheetAt0;XSSFCellStyle=objWorkbook.createCellStyle;DataFormatter Formatter 1=新的DataFormatter;工作很好,兄弟!!使用相同的代码在XSSF上尝试。。。