Apache POI 在 xls 文档打开后设置选定的单元格 [英] Apache POI set selected cell after xls document opens

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

问题描述

我们有下一种情况:我们的系统有 xls 格式的数据导出,这是一个包含许多行和列的巨大文件.用户下载并打开文档后,他会看到文档滚动到最后一列和最后一个电子表格选项卡.这很烦人,最好将焦点设置在第一个选项卡和第一个单元格上.我做了简单的测试代码来看看它是如何工作的:

We have next situation: our system has data export in xls format, this is huge file with many rows and columns. And after user download and open document he see document scrolled to last column and last Spreadsheet tab. This is very annoying, better to set focus on first tab and first cell. I did simple test code to see how it works:

public class SelectionTest {
public static String file = "/usr/test/poi.test/src/main/resources/test";
@Test
public void test() throws FileNotFoundException, IOException {
    HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
    HSSFSheet s = wb.getSheetAt(0);
    s.setActive(true);
    HSSFRow row = s.getRow(0);
    HSSFCell cell = row.getCell(0);
    cell.setAsActiveCell();
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();
}
}

这行不通.

推荐答案

这是可行的解决方案,找到了这个 这里

Here is working solution, have found this here

    HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(file));
    HSSFSheet s = wb.getSheetAt(0);
    wb.setActiveSheet(0);
    s.showInPane(0, 0);
    FileOutputStream out = new FileOutputStream(file);
    wb.write(out);
    out.close();

这篇关于Apache POI 在 xls 文档打开后设置选定的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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