Focus on first cell in excel

对着背影说爱祢 提交于 2019-12-10 21:59:54

问题


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(); 

I am using above code for taking focus to first cell (when I open excel first cell shouldd be selected). It is opening the excel correctly because of showInPane, but selecting the first cell is not working.


回答1:


Something like this

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);



回答2:


I recently stumbled on the same problem using POI 3.14. For me this worked:

sheet.setActiveCell(new CellAddress(0, 0));



来源:https://stackoverflow.com/questions/5964598/focus-on-first-cell-in-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!