public class FileUtil {
public static void main(String[] args) throws FileNotFoundException, IOException {
String aaa = "D:\\test\\111.xlsx";
String[] title = {"username","password","phone"};
//创建工作簿
XSSFWorkbook workbook = new XSSFWorkbook();
//创建工作表
XSSFSheet sheet = workbook.createSheet();
//创建表中的第一行 索引为0
XSSFRow row = sheet.createRow(0);
//创建单元格
XSSFCell cell = null;
//在第一行插入单元格设置值
for(int i=0;i<title.length;i++){
cell = row.createCell(i);
cell.setCellValue(title[i]);
}
//创建一个文件
File file = new File(aaa);
//将Excel文件写入创建的file当中
OutputStream stream = new FileOutputStream(file);
workbook.write(stream);
//关闭流
stream.close();
}
}
使用POIX的jar包,2个不同的包。