poi3.8 单元格显示短时间08:00,点击单元格显示长时间08:00:00,不显示日期
时间: 2024-01-26 08:04:01 浏览: 22
您可以使用单元格格式设置来实现这一目标。请按照以下步骤操作:
1. 选中您要设置格式的单元格,右键点击单元格,选择“格式单元格”。
2. 在弹出的“格式单元格”对话框中选择“自定义”类别。
3. 在“类型”文本框中输入以下格式代码:hh:mm:ss。
4. 点击“确定”按钮。
这样设置后,单元格将以短时间格式显示。当您单击该单元格时,Excel 会在公式栏中显示完整的日期时间格式,但单元格本身仍将以短时间格式显示。
相关问题
poi3.8 单元格显示短时间08:00,点击单元格在公式栏显示长时间08:00:00,不显示日期
您可以通过以下代码实现:
```java
// 创建工作簿
Workbook workbook = new HSSFWorkbook();
// 创建工作表
Sheet sheet = workbook.createSheet("Sheet1");
// 创建单元格样式
CellStyle shortTimeCellStyle = workbook.createCellStyle();
shortTimeCellStyle.setDataFormat(workbook.createDataFormat().getFormat("hh:mm"));
// 创建单元格
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellValue(new Date());
cell.setCellStyle(shortTimeCellStyle);
// 设置单元格点击后在公式栏中显示长时间格式
Hyperlink link = workbook.getCreationHelper().createHyperlink(HyperlinkType.URL);
link.setAddress("'");
link.setTooltip("Click for long time");
cell.setHyperlink(link);
// 保存工作簿
FileOutputStream out = new FileOutputStream("output.xls");
workbook.write(out);
out.close();
workbook.close();
```
该代码创建一个短时间格式的单元格,并设置单元格样式为hh:mm格式。同时,设置单元格点击后在公式栏中显示长时间格式,但不显示日期。
请注意,这里使用了`HSSFWorkbook`作为工作簿,如果您使用的是`.xlsx`格式的工作簿,则应该使用`XSSFWorkbook`。另外,您需要根据实际情况修改输出文件路径。
poi3.8 XSSFWorkbook 单元格显示时间08:00,点击单元格在公式栏显示时间08:00:00,不显示日期
这种情况可能是由于单元格的格式设置不正确导致的。你可以尝试在代码中设置单元格的格式为时间格式,同时指定时间格式中不包含日期部分,这样就可以解决这个问题。具体的代码如下:
```java
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("Sheet1");
XSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setDataFormat(workbook.createDataFormat().getFormat("h:mm"));
XSSFRow row = sheet.createRow(0);
XSSFCell cell = row.createCell(0);
cell.setCellValue(new Date());
cell.setCellStyle(cellStyle);
```
在上面的代码中,我们创建了一个时间格式的单元格,并将其设置为08:00,同时指定时间格式中不包含日期部分。你可以根据你的实际需求修改代码中的时间格式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)