- 浏览: 675808 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
Hippyqq:
谢谢很有用,
java中遍历MAP的几种方法 -
XSoftlab:
超详细。。。Java map 详解 - 用法、遍历、排序、常用 ...
java中遍历MAP的几种方法 -
bobo22:
importnet.sf.fmj.ui.application ...
java来调用电脑视频摄像头拍照进行截图 -
qq981378640:
#include <stdio.h>
int ...
c语言中unsigned类型和普通类型间的转换 -
qq981378640:
楼主你这样有点复杂了,直接这样写更好更方便
#include ...
c语言中unsigned类型和普通类型间的转换
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.poi.hssf.util.Region;
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.HSSFHeader;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.cf.BorderFormatting;
public class CreateSimpleExcelToDisk
{
/**
* @功能:手工构建一个简单格式的Excel
*/
private static List<Student> getStudent() throws Exception
{
List list = new ArrayList();
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
Student user1 = new Student(1, "张三", 16, df.parse("1997-03-12"));
Student user2 = new Student(2, "李四", 17, df.parse("1996-08-12"));
Student user3 = new Student(3, "王五", 26, df.parse("1985-11-12"));
list.add(user1);
list.add(user2);
list.add(user3);
return list;
}
public static void main(String[] args) throws Exception
{
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String createDate = format.format(new Date());
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("学生表一");
sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 5));//合并第0行第0列至第0行第9列
sheet.addMergedRegion(new Region(1, (short) 0, 1, (short) 5));//合并第0行第0列至第0行第9列
sheet.addMergedRegion(new Region(2, (short) 0, 2, (short) 5));//合并第0行第0列至第0行第9列
HSSFRow row = sheet.createRow((int)0);
HSSFCell cell = row.createCell((short)0);
HSSFCellStyle headerstyle = wb.createCellStyle();
headerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
cell.setCellValue("回访结果统计表");
cell.setCellStyle(headerstyle);
HSSFFont headerFont = wb.createFont();
headerFont.setFontName("宋体");
headerFont.setFontHeightInPoints((short)22);
headerstyle.setFont(headerFont);
cell.setCellStyle(headerstyle);
row = sheet.createRow((int)1);
cell = row.createCell((short)0);
headerstyle = wb.createCellStyle();
headerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
cell.setCellValue("生成时间 :"+createDate);
cell.setCellStyle(headerstyle);
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
row = sheet.createRow((int)3);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
cell = row.createCell((short) 0);
cell.setCellValue("学号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("姓名");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("年龄");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("生日");
cell.setCellStyle(style);
// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
List list = CreateSimpleExcelToDisk.getStudent();
for (int i = 0; i < list.size(); i++)
{
row = sheet.createRow((int) i + 4);
Student stu = (Student) list.get(i);
// 第四步,创建单元格,并设置值
row.createCell((short) 0).setCellValue((double) stu.getId());
row.createCell((short) 1).setCellValue(stu.getName());
row.createCell((short) 2).setCellValue((double) stu.getAge());
cell = row.createCell((short) 3);
cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu
.getBirth()));
}
// 第六步,将文件存到指定位置
try
{
FileOutputStream fout = new FileOutputStream("E:/students.xls");
wb.write(fout);
fout.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.poi.hssf.util.Region;
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.HSSFHeader;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.record.cf.BorderFormatting;
public class CreateSimpleExcelToDisk
{
/**
* @功能:手工构建一个简单格式的Excel
*/
private static List<Student> getStudent() throws Exception
{
List list = new ArrayList();
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
Student user1 = new Student(1, "张三", 16, df.parse("1997-03-12"));
Student user2 = new Student(2, "李四", 17, df.parse("1996-08-12"));
Student user3 = new Student(3, "王五", 26, df.parse("1985-11-12"));
list.add(user1);
list.add(user2);
list.add(user3);
return list;
}
public static void main(String[] args) throws Exception
{
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
String createDate = format.format(new Date());
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("学生表一");
sheet.addMergedRegion(new Region(0, (short) 0, 0, (short) 5));//合并第0行第0列至第0行第9列
sheet.addMergedRegion(new Region(1, (short) 0, 1, (short) 5));//合并第0行第0列至第0行第9列
sheet.addMergedRegion(new Region(2, (short) 0, 2, (short) 5));//合并第0行第0列至第0行第9列
HSSFRow row = sheet.createRow((int)0);
HSSFCell cell = row.createCell((short)0);
HSSFCellStyle headerstyle = wb.createCellStyle();
headerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
cell.setCellValue("回访结果统计表");
cell.setCellStyle(headerstyle);
HSSFFont headerFont = wb.createFont();
headerFont.setFontName("宋体");
headerFont.setFontHeightInPoints((short)22);
headerstyle.setFont(headerFont);
cell.setCellStyle(headerstyle);
row = sheet.createRow((int)1);
cell = row.createCell((short)0);
headerstyle = wb.createCellStyle();
headerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
cell.setCellValue("生成时间 :"+createDate);
cell.setCellStyle(headerstyle);
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
row = sheet.createRow((int)3);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
cell = row.createCell((short) 0);
cell.setCellValue("学号");
cell.setCellStyle(style);
cell = row.createCell((short) 1);
cell.setCellValue("姓名");
cell.setCellStyle(style);
cell = row.createCell((short) 2);
cell.setCellValue("年龄");
cell.setCellStyle(style);
cell = row.createCell((short) 3);
cell.setCellValue("生日");
cell.setCellStyle(style);
// 第五步,写入实体数据 实际应用中这些数据从数据库得到,
List list = CreateSimpleExcelToDisk.getStudent();
for (int i = 0; i < list.size(); i++)
{
row = sheet.createRow((int) i + 4);
Student stu = (Student) list.get(i);
// 第四步,创建单元格,并设置值
row.createCell((short) 0).setCellValue((double) stu.getId());
row.createCell((short) 1).setCellValue(stu.getName());
row.createCell((short) 2).setCellValue((double) stu.getAge());
cell = row.createCell((short) 3);
cell.setCellValue(new SimpleDateFormat("yyyy-mm-dd").format(stu
.getBirth()));
}
// 第六步,将文件存到指定位置
try
{
FileOutputStream fout = new FileOutputStream("E:/students.xls");
wb.write(fout);
fout.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
发表评论
-
java应用CPU占用100%内存泄漏分析总结
2017-11-28 08:46 514转; http://www.blogjava.net/hank ... -
Java Mysql存取Blob数据
2014-10-21 12:54 1488当数据库字段为blob类型时 ,我们如果使用PreparedS ... -
关于日志的等级 的配置
2014-07-02 16:49 608#这里定义能显示到的最低级别,若定义到INFO级别,则看不到D ... -
Extjs中如何在一行textfield后面加几个字
2014-04-14 16:38 1483{ fieldLabel : '输入框', xtype : ' ... -
数据库中图片的操作(字节流的操作)
2013-12-09 17:26 795package com.fww.util; import j ... -
java 获得本地ip
2013-11-28 18:04 857Enumeration allNetInterfaces = ... -
java多线程下载的例子代码
2013-09-09 16:16 0java多线程下载的例子代码 import java.io.I ... -
java来调用电脑视频摄像头拍照进行截图
2013-09-09 15:34 10343packagecom.pengo.capture; i ... -
java中lucene解析word工具类
2013-09-09 15:32 1015java中lucene解析word工具类(读取word文档并查 ... -
Java 向oracle插入百万数据
2013-09-09 15:30 1522这里的表是没加索引的 ... -
list 排序
2013-06-20 20:43 1027import java.util.Collections; i ... -
java抓取网络图片放到本地
2013-05-07 10:39 4235import java.io.BufferedInputStr ... -
java代码发送JSON格式的httpPOST请求
2013-05-06 13:41 20279package com.test; import java. ... -
java操作excel(HSSF样式) .
2013-04-15 15:06 1911java操作excel(HSSF样式一) import ja ... -
JAVA+Ftpclient操作
2013-03-07 16:35 6523最近再做个ftp上传、下载的项目,用到的包是sun.net.f ... -
自动消除文本框中的空格;js清除空格问题,去除空格问题
2013-03-01 11:22 6277自动消除文本框中的空格;js清除空格问题,去除空格问题 要完成 ... -
java执行Linux命令 .
2012-12-26 09:29 1228/** * 修改Linux目录权限 * @param ... -
UUID生成类
2012-12-16 18:18 2415import java.net.InetAddress; im ... -
java反射获得类的字段和值
2012-12-10 17:26 1598import java.util.HashMap; impo ... -
jquery UI
2012-11-20 22:46 1276jQuery ui 是基于 jquery 基础类库开发的开源的 ...
相关推荐
java读写excel文件,新手参考高手绕道。
ExcelDemo_Excel导出_下载_POI读excel_JXL读写excel_java读写excel_列宽_读取合并或拆分单元格内容
含java读写excel所需的jar包,含有读写示例程序
非常简洁的java读写Excel文件的源代码,非常简单,还赠送个JXL的包,这么简单的代码你再看不明白,干脆你该行算了!!
java 写excel 实例 ,有详细的注释,一看就懂,下载可运行
使用java写excel文件
java读写excel包括utf8转码为可识别汉字gbk,jxl方式读取excel,生成一个新的excel
java 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写exceljava 读写excel
java读写Excel,POI.JAR,Word内容读取
Java读写excel Java读写excel Java读写excel
java将list数据写入指定文件名的excel文档中
java读写excel
Java读写Excel,希望可以和帮助有需要的同学,同事可以和大家一起探讨!demo已经经过测试,真实可用!
java 写excel jar包。
自己封装的java读写excel2010的库,拿来直接用!操作更简单!样例请查看:http://blog.ijustyce.com/?post=359
Java 操作Excel poi读写excel,所需要的jar包 https://blog.csdn.net/u014646662/article/details/83217382
Java读写Excel 里面有jar和代码,已经过自测没有问题 。
读写Excel组件.....读取服务器端excel