poi 设置宋体9.5
时间: 2023-11-17 17:05:33 浏览: 39
您可以使用Apache POI设置字体为宋体,大小为9.5,示例代码如下:
```
CellStyle style = workbook.createCellStyle(); // 创建单元格样式
Font font = workbook.createFont(); // 创建字体对象
font.setFontName("宋体"); // 设置字体名称
font.setFontHeightInPoints((short)9.5); // 设置字体大小
style.setFont(font); // 将字体对象设置到样式对象中
cell.setCellStyle(style); // 将样式应用到单元格中
```
其中,`workbook`为`Workbook`对象,`cell`为要设置样式的单元格对象。
相关问题
poi 导出word设置宋体9.5
您可以使用Apache POI将数据导出到Word,并设置字体为宋体,大小为9.5,实现代码如下:
```java
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
XWPFRun run = paragraph.createRun();
run.setText("Hello, World!");
run.setFontFamily("宋体");
run.setFontSize(9.5f);
FileOutputStream out = new FileOutputStream("output.docx");
document.write(out);
out.close();
```
其中,`XWPFDocument`、`XWPFParagraph`和`XWPFRun`是Apache POI提供的Word处理类,`setFontFamily()`方法设置字体名称为宋体,`setFontSize()`方法设置字体大小为9.5。最后将文档输出到文件中。
需要注意的是,导出Word需要在本地安装Microsoft Office或者使用OpenOffice等开源软件。
poi设置字体为宋体
您可以使用Apache POI中的Font对象来设置字体样式,具体步骤如下:
1. 创建一个Workbook对象
```java
Workbook wb = new HSSFWorkbook(); //或者是XSSFWorkbook()
```
2. 创建一个CellStyle对象,并设置字体
```java
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setFontName("宋体"); //设置字体为宋体
style.setFont(font); //将字体样式应用到CellStyle对象中
```
3. 在单元格中应用CellStyle对象
```java
Sheet sheet = wb.createSheet("Sheet1");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Hello World");
cell.setCellStyle(style); //将CellStyle对象应用到单元格中
```
通过这样的方式,您可以将字体设置为宋体。
相关推荐
![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)