📄 excelsample7.java
字号:
package cn.com.chengang.myplugin.poi;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class ExcelSample7 {
public static void main(String[] args) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("sheet1");
HSSFRow row = sheet.createRow((short) 1);
// 创建一个字体对象
HSSFFont font = wb.createFont();
font.setFontHeightInPoints((short) 24);// 字体大小
font.setFontName("Courier New");
font.setItalic(true); // 斜体
font.setStrikeout(true); // 删除线
// 创建一个应用字体的式样
HSSFCellStyle style = wb.createCellStyle();
style.setFont(font);
// 创建一个使用以上式样的单元格
HSSFCell cell = row.createCell((short) 1);
cell.setCellValue("Hello World");
cell.setCellStyle(style);
// 写入文件
FileOutputStream fileOut = new FileOutputStream("c:\\workbook.xls");
wb.write(fileOut);
fileOut.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -