如何用Apache POI读取Excel的单元格自定义名称的值。

Cute_Tiger 2012-12-10 03:34:08
如何用Apache POI读取Excel的单元格自定义名称的值所在位置。


我想根据Excel模板去生成一个带有数据的Excel文档,用单元格自定义名称为EMP_WEB所在位置来当做Excel单元格的坐标,而不是在代码中写死,如:1行,2列,如何用Apache POI读取Excel的名称框里的值呢?
...全文
761 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
孤岛盛世 2013-01-30
  • 打赏
  • 举报
回复
解决了,分析一下呀!
Cute_Tiger 2012-12-11
  • 打赏
  • 举报
回复
引用 1 楼 paopaoxiu 的回复:
没看明白,是想通过POI将数据库的数据读取到excel中,还是想读取excel中单元格所在值的坐标位置值?






如图,通过WEB_EMP去取得row ,cell,style等信息。
已经解决了。
yktd26 2012-12-10
  • 打赏
  • 举报
回复
poi 我和方面不是太方便 可以看看这一页http://poi.apache.org/spreadsheet/quick-guide.html#NamedRanges 要一个其中的例子

    // Setup code
    String cellName = "TestName";
    Workbook wb = getMyWorkbook(); // retrieve workbook

    // Retrieve the named range
    // Will be something like "$C$10,$D$12:$D$14";
    int namedCellIdx = wb.getNameIndex(cellName);
    Name aNamedCell = wb.getNameAt(namedCellIdx);

    // Retrieve the cell at the named range and test its contents
    // Will get back one AreaReference for C10, and
    //  another for D12 to D14
    AreaReference[] arefs = AreaReference.generateContiguous(aNamedCell.getRefersToFormula());
    for (int i=0; i<arefs.length; i++) {
        // Only get the corners of the Area
        // (use arefs[i].getAllReferencedCells() to get all cells)
        CellReference[] crefs = arefs[i].getCells();
        for (int j=0; j<crefs.length; j++) {
            // Check it turns into real stuff
            Sheet s = wb.getSheet(crefs[j].getSheetName());
            Row r = s.getRow(crefs[j].getRow());
            Cell c = r.getCell(crefs[j].getCol());
            // Do something with this corner cell
        }
    }
codelabs 2012-12-10
  • 打赏
  • 举报
回复
没看明白,是想通过POI将数据库的数据读取到excel中,还是想读取excel中单元格所在值的坐标位置值?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧