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

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

问题描述

我们旁边的情况:我们的系统具有数据导出XLS格式,这是许多行和列巨大的文件。
而用户下载并打开文件后,他见滚动到最后一列,上一个S- preadsheet标签。这是很烦人的,更好的将焦点设置第一个标签和第一个单元格上。我做了简单的测试code,看看它是如何工作的:

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天全站免登陆