查找Excel单元格在Apache的POI文本 [英] Find Excel Cell by Text in Apache POI

查看:196
本文介绍了查找Excel单元格在Apache的POI文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到一个单元格在一个Excel工作表由它的文本。文字是一样的东西%T

  sheet.findCell(%T); //伪code,不工作

我的目标是使用户能够提供一种模板,其中数据被写入。颜色和字体,以及数据的位置可以通过在Excel文件中的用户进行配置。这%T 细胞是数据表的左上角。

其他的问题:有没有得到这份工作做得更优雅的方式。

修改我遍历行和单元格找到它。恐怕这不是真的有效,但它至今如下:

 公共静态细胞findCell(XSSFSheet片,字符串文本){
    对于(鳞次栉比:表){
        (电池单元:行){
            如果(text.equals(cell.getStringCellValue()))
                返回细胞;
        }
    }
    返回null;
}


解决方案

您可以通过表的单元格迭代和调查的内容。我不认为还有一个更简单的方法。

I'd like to find a cell in an Excel sheet by its text. The text is something like %t:

sheet.findCell("%t"); // pseudo-code, not working

My goal is to enable the user to provide kind of template, in which data is written. Colours and fonts, as well as data's position can be configured by the user in an Excel file. This %t cell is the top-left corner of the data table.

Additional question: Is there a more elegant way to get this job done?

EDIT I'm iterating over the rows and cells to find it. I'm afraid it's not really efficient, but it works so far:

public static Cell findCell(XSSFSheet sheet, String text) {     
    for(Row row : sheet) {          
        for(Cell cell : row) {              
            if(text.equals(cell.getStringCellValue()))
                return cell;
        }
    }       
    return null;
}

解决方案

You can iterate through the cells of the sheet and investigate the contents. I don't think there is an easier method.

这篇关于查找Excel单元格在Apache的POI文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆