国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

采用POI創建Excel文件

2019-11-18 11:24:43
字體:
來源:轉載
供稿:網友

import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.usermodel.*;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;

public class ExcelCreate
{
 public static void main(String[] args)throws IOException
 {
  
  HSSFWorkbook wb = new HSSFWorkbook();//建立新HSSFWorkbook對象
  HSSFSheet sheet = wb.createSheet("new sheet");//建立新的sheet對象
  
  
  // Create a row and put some cells in it. Rows are 0 based.
  HSSFRow row = sheet.createRow((short)0);//建立新行
  
  // Create a cell and put a value in it.
  HSSFCell cell = row.createCell((short)0);//建立新cell
  cell.setCellValue(1);//設置cell的整數類型的值
  
  
  // Or do it on one line.
  row.createCell((short)1).setCellValue(1.2);//設置cell浮點類型的值
  row.createCell((short)2).setCellValue("test");//設置cell字符類型的值
  row.createCell((short)3).setCellValue(true);//設置cell布爾類型的值
  HSSFCellStyle cellStyle = wb.createCellStyle();//建立新的cell樣式
  Workbook workBook = new Workbook();
  HSSFDataFormat hSSFDataFormat = new HSSFDataFormat(workBook);
  cellStyle.setDataFormat(hSSFDataFormat.getFormat("m/d/yy h:mm"));//設置cell樣式為定制的日期格式
  HSSFCell dCell =row.createCell((short)4);
  dCell.setCellValue(new Date());//設置cell為日期類型的值
  dCell.setCellStyle(cellStyle); //設置該cell日期的顯示格式
  HSSFCell csCell =row.createCell((short)5);
  csCell.setEncoding(HSSFCell.ENCODING_UTF_16);//設置cell編碼解決中文高位字節截斷
  csCell.setCellValue("中文測試_Chinese Words Test");//設置中西文結合字符串
  row.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_ERROR);//建立錯誤cell
  
  // Write the output to a file
  FileOutputStream fileOut = new FileOutputStream("c:/workbook.xls");
  wb.write(fileOut);
  fileOut.close();
  
 }
}

 



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南阳市| 怀远县| 广河县| 湘乡市| 潜江市| 铜陵市| 区。| 道孚县| 江津市| 双城市| 北海市| 宜兰市| 长岭县| 新平| 邯郸市| 金坛市| 吉林省| 苍梧县| 清新县| 古丈县| 博湖县| 彭阳县| 临安市| 阳泉市| 盐津县| 岱山县| 普兰县| 吕梁市| 怀远县| 东至县| 江阴市| 沐川县| 新绛县| 赣榆县| 军事| 当雄县| 高清| 汽车| 临泉县| 唐河县| 宜丰县|