wangchao.org
添加收藏 | 博客
 
购物视频论坛IT业界自然风光美女图片王朝网络小游戏BT下载生活百科编程设计手机图铃小说
 
笑话 | 水库 | 娱乐 | 体育 | 英语 | 宠物 | 美食 | 旅游 | 养生 | 手机 | 数码 | 汽车 | 珠宝 | 美容 | 装修 | 厨房 | 科普 | 动物 | 植物 | 影音 | 百科 | 知道 | 词典
  
 
 您好! 您现在位于: 王朝网络 → 编程设计 → 《采用POI创建Excel文件返回上一页 
 
1楼 

采用POI创建Excel文件

  网上购物、在线购物、购物搜索 欢迎光临本站购买图书、影视、音乐、数码、百货,手机等商品。

  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();
  
  }
  }

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(); } }

 
标签: Excel  POI  创建  文件  采用  
 
您可以将本页贴到其他网站
UBB代码HTML代码
 
 
 
 
 
 
 更多内容
 ·Java Learning Path (一)、工具 ·Java Learning Path(二)、书籍 ·Java Learning Path(三)过程篇 ·Java Learning Path(五)资源篇
 ·根据IP找地址的java实现 ·引入Mock类的简单方法 ·JAVA mail应用 - 用JAVA SWING写 ·配置shark与mysql的连接
 ·Jive 源代码探索 ·struts标签复选框的使用 ·java、J2EE基础问题汇总 ·Struts中logic:iterate标记的使用
 ·好习惯利学习 ·java工具之javadoc和jar浅学 ·APPFUSE中使用CLOB类型 ·提取英文中的单词
 ·当MySQL集群时, JDBC路径的使用方 ·初学Eclipse,完全沒接觸過eclip ·2004年11月11日 ·native2ascii命令的一种用法!
 ·jdbc 不得不说的几句话 ·eclipse技巧 --熱鍵篇 ·(转贴)Java的数据库应用 ·多附件、带有预览功能的HTML页面
 
 
最新评论  点此查看所有评论
 
 
 
 
发表评论(支持UBB码)


验证码:  
 
 
 
© 2005- 王朝网络 版权所有