java org 写excel
2021/7/8 20:16:16
本文主要是介绍java org 写excel,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
java org 写excel
java org 写excelpackage com.csland.workflow.business;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
public class ylexcel {
public ylexcel() {
}
private static void createCellTitle(HSSFWorkbook wb, HSSFRow row, int column,
String value) {
HSSFCell cell = row.createCell((short)column);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
HSSFFont font = wb.createFont();
font.setFontHeightInPoints( (short) 11); ;
font.setFontName("宋体");
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue(value);
}
private static void createFile(String outputFile) {
try {
// Create a New XL Document
HSSFWorkbook wb = new HSSFWorkbook();
// Make a worksheet in the XL document created
HSSFSheet sheet = wb.createSheet();
// Create row at index zero ( Top Row)
HSSFRow row = sheet.createRow( (short) 0);
for (int i = 0; i < 10; i++) {
createCellTitle(wb, row, i, "gisoracle" + i);
}
// The Output file is where the xls will be created
FileOutputStream fOut = new FileOutputStream(outputFile);
// Write the XL sheet
wb.write(fOut);
fOut.flush();
// Done Deal..
fOut.close();
System.out.println("File Created ..");
}
catch (Exception e) {
System.out.println("!!BANG!! xlCreate() : " + e);
}
}
public static void ylb(String ym) {
System.out.println("poi");
createFile("c:/test.xls");
System.out.println("==============");
}
}
这篇关于java org 写excel的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南
- 2024-09-30Dnd-Kit学习:新手快速入门指南