poi3.8 单元格显示时间hh:mm,需要点击单元格时在公式栏显示时间hh:mm:ss,setDataFormat,cell.setAsActiveCell()不会立刻生效,setForceFormulaRecalculation也不会立刻生效,evaluateFormulaCell,setactivecell也没用,还是需要双击才会生效
时间: 2024-02-28 19:57:35 浏览: 20
您好,关于您提出的问题,您可以尝试使用以下代码来设置单元格的格式,并在单元格上添加双击事件,用于触发公式栏的显示:
``` java
CellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(workbook.createDataFormat().getFormat("hh:mm"));
cell.setCellStyle(cellStyle);
// 单元格双击事件
Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, cell.getColumnIndex(), cell.getRowIndex(), cell.getColumnIndex(), cell.getRowIndex());
Comment comment = drawing.createCellComment(anchor);
comment.setString(new XSSFRichTextString(cell.getStringCellValue()));
comment.setVisible(false);
comment.setAuthor("author");
((XSSFComment) comment).setAddress(new CellAddress(cell.getAddress()));
// 在单元格中添加公式
cell.setCellFormula("TEXT(A1,\"hh:mm:ss\")");
```
这样,当您双击单元格时,公式栏中将会显示单元格中的时间值,格式为hh:mm:ss。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)