今天简单的学习了一下POI,一下是所使用到的jar,这些jar可以到apache去下载

下面简单的说一下里面的一些类和一些作用:

package com.test.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
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.ss.usermodel.Font;

public class OutPutExcelTest {

public static void outputExcel(){

//创建一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();
        //创建一个sheet
        HSSFSheet sheet = wb.createSheet("用户信息");
        sheet.setColumnWidth(0, 5000); //设置第一列的宽度
        sheet.setColumnWidth(1, 5000); //设置第二列的宽度
        sheet.setColumnWidth(2, 5000); //设置第三列的宽度
        
        
        //创建单元格样式对象
        HSSFCellStyle style = wb.createCellStyle();
        style.setVerticalAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        style.setFillBackgroundColor((short)8);
        
        //创建字体对象
        Font font = wb.createFont();
        font.setBoldweight(Font.BOLDWEIGHT_BOLD);  //字体宽度
        font.setFontName("宋体");  //设置字体类型
        font.setItalic(false); //这只是否为斜体
        //设置字体样式
        style.setFont(font);
        
        
        //创建一行
        HSSFRow row0 = sheet.createRow(0);
        //设置行样式
        row0.setRowStyle(style);
        
        HSSFCell cell0_0 = row0.createCell(0);
        cell0_0.setCellStyle(style); //设置单元格样式
        cell0_0.setCellValue("姓名");
        HSSFCell cell0_1 = row0.createCell(1);
        cell0_1.setCellValue("性别");
        HSSFCell cell0_2 = row0.createCell(2);
        cell0_2.setCellValue("住址");
        
        for(int i = 1; i < 100; i ++){
            //创建行
            HSSFRow row = sheet.createRow(i);
            for(int j = 0; j < 10; j++){
                HSSFCell cell = row.createCell(j);
                cell.setCellValue("这是第"+(i+1)+"行,第"+(j+1)+"列");
            }
        }
        
        
        
        
        
        FileOutputStream fos  = null;
        try {
            fos = new FileOutputStream(new File("D:\\未命名.xls"));
            wb.write(fos);
            
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally{
            if(fos != null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        
    }
    
    public static void main(String[] args) {

  //测试文件
        OutPutExcelTest.outputExcel();
    }
}
该代码能够直接的执行,复制粘贴可以直接运行,只是简单的做了一个输出,这个只要明白了,做数据的输出应该也不是问题。

poi实现将数据输出到Excel表格当中的更多相关文章

  1. Java POI读取Excel数据,将数据写入到Excel表格

    1.准备 首先需要导入poi相应的jar包,包括: 下载地址:http://pan.baidu.com/s/1bpoxdz5 所需要的包的所在位置包括: 2.读取Excel数据代码 package S ...

  2. 数据导出为excel表格

    ---恢复内容开始--- 方式一: 通过request和response中携带的数据导出表格,导出的结果会将页面中展示的内容全部导出.代码如下: //调出保存框,下载页面所有内容 String fil ...

  3. asp.net数据导出到excel表格,并设置表格样式

    1.首先在项目中添加引用

  4. 使用apache的poi来实现数据导出到excel的功能——方式二

    此次,介绍利用poi与layui table结合导出excel.这次不需要从数据库中查询出来的数据进行每一行的拼接那么麻烦,我们这次将标题定义一个id值,对应从数据库中查找出来的字段名即可. 1.po ...

  5. 使用apache的poi来实现数据导出到excel的功能——方式一

    利用poi导出复杂样式的excel表格的实现. 我们要实现的效果是: 我们利用提前设计好模板样式,再在模板中填充数据的方式. 首先,pom.xml引入poi. <dependency> & ...

  6. springboot2.0数据制作为excel表格

    注意:由于公司需要大量导出数据成excel表格,因此在网上找了方法,亲测有效. 声明:该博客参考于https://blog.csdn.net/long530439142/article/details ...

  7. 从数据库将数据导出到excel表格

    public class JxlExcel { public static void main(String[] args) { //创建Excel文件 String[] title= {" ...

  8. Java利用Apache POI将数据库数据导出为excel

    将数据库中的数据导出为excel文件,供其他人查看 public class POITest { public static void main(String[] args) { POITest te ...

  9. java将数据库中查询到的数据导入到Excel表格

    1.Maven需要的依赖 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> ...

随机推荐

  1. [Java线程] Java线程池ExecutorService

    示例 import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.u ...

  2. Bluetooth in Android 4.2 and 4.3(一):综述

    从Android 4.2开始,Bluetooth stack发生了重大改变:从Bluez换成了由Google和Broadcom联合开发的Bluedroid(当然,核心的部分还是Broadcom的,Go ...

  3. 使用servlet实现文件上传

    package com.zhanghaobo.fileupload; import java.io.File; import java.io.IOException; import java.util ...

  4. 玩转变量、环境变量以及数学运算(shell)

    变量和环境变量    var=value  给变量赋值,输出语句:$ echo $var或者是$ echo ${var},记住中间有个空格 例如:name="coffee" age ...

  5. Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd

    http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...

  6. ARM architectures

    https://gitorious.org/freebsd/freebsd/raw/56c5165837bf08f50ca4a08c6b2da91f73852960:sys/arm/include/a ...

  7. The IAR Archive Tool—iarchive

    The IAR Archive Tool—iarchive—creates and manipulates a library (anarchive) of several ELF object fi ...

  8. 转载 C++常用库函数atoi,itoa,strcpy,strcmp的实现

    C++常用库函数atoi,itoa,strcpy,strcmp的实现 C语言字符串操作函数 1. 字符串反转 - strRev2. 字符串复制 - strcpy3. 字符串转化为整数 - atoi4. ...

  9. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  10. Android 手机设置CMWAP 接入点

    Android 手机设置CMWAP 接入点 设置--- 无限控件---移动网络设置---接入点名称----再按菜单---选择新apn 第一步,设置CMNET 上网APN 新建 APN 1.名称:cmn ...