poi3.8 xlsx cell.setCellFormula 隐藏等于号
时间: 2024-02-29 11:55:36 浏览: 44
如果您使用 `cell.setCellFormula` 方法设置单元格公式,那么等号会自动显示在单元格中。如果您不想显示等号,可以使用 `setCellValue` 方法设置公式结果,而不是设置公式本身。例如,如果您想在单元格中显示 `SUM(A1:A10)`,则可以将其设置为 `cell.setCellValue("=SUM(A1:A10)")`。这将在单元格中显示 `SUM(A1:A10)`,而不是 `=SUM(A1:A10)`。
相关问题
poi3.8 xlsx 怎么设置CellFormatType.Date
你可以使用Apache POI 3.8中的CellStyle类来设置单元格的日期格式。可以按照以下步骤进行设置:
1. 创建一个CellStyle对象:
```
CellStyle style = workbook.createCellStyle();
```
2. 设置单元格的日期格式:
```
style.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("yyyy/mm/dd"));
```
3. 将CellStyle对象应用于单元格:
```
cell.setCellStyle(style);
```
这将使单元格以日期格式显示。你可以根据需要调整日期格式的样式。
poi3.8 xlsx 设置公式栏格式
您可以使用 `org.apache.poi.ss.usermodel.Cell.setCellFormula` 方法设置单元格的公式,使用 `org.apache.poi.ss.usermodel.CellStyle.setDataFormat` 方法设置单元格的格式。以下是示例代码:
```
// 创建工作簿和工作表
Workbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet("Sheet1");
// 创建单元格样式
CellStyle style = wb.createCellStyle();
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
// 创建公式单元格,并设置公式和样式
Cell cell = sheet.createRow(0).createCell(0);
cell.setCellFormula("A1+B1");
cell.setCellStyle(style);
// 创建数据单元格,并设置值和样式
Cell cell2 = sheet.createRow(1).createCell(0);
cell2.setCellValue(123.456);
cell2.setCellStyle(style);
// 保存工作簿
FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
wb.write(fileOut);
fileOut.close();
```
在上述代码中,我们创建了一个格式为 "0.00" 的 `CellStyle` 对象,并将其应用于公式单元格和数据单元格。然后,我们设置公式单元格的公式为 "A1+B1",设置数据单元格的值为 123.456。最后,我们将工作簿保存为 xlsx 文件格式。
请注意,在设置公式时,需要使用 Excel 中的单元格引用格式(例如,"A1"、"B1"),而不是 Java 中的数组下标格式(例如,0、1)。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)