基于Apache POI 向xlsx写入数据
【0】写在前面
- 0.1) these codes are from 基于Apache POI 的向xlsx写入数据
- 0.2) this idea is from http://cwind.iteye.com/blog/2187670 , adding some comments for easy understanding proves to be my work.
package com.cwind.poi;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
/**
* @author Billy Chen
*/
public class SimpleDatasheetWriter {
private static final String[] titles = {
"姓名", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
//sample data to fill the sheet.
private static final String[][] data = {
{"AngelaBaby", "跑了", "跑了", "跑了", "跑了", "跑了"},
{"邓超", "跑了", "跑了", "没跑", "跑了", "跑了" },
{"王祖蓝", "没跑", "没跑", "没跑", "跑了", "跑了" },
{"王宝强", "跑了", "跑了", "跑了", "跑了", "跑了" },
{"郑恺", "跑了", "跑了", "跑了", "跑了", "跑了" }
};
public static void main(String[] args) throws Exception {
Workbook wb;
//创建工作簿
if(args.length > 0 && args[0].equals("-xls"))
wb = new HSSFWorkbook();
else
wb = new XSSFWorkbook();
//创建名为 Running Man 的纸张
Sheet sheet = wb.createSheet("Running Man");
//创建行坐标为0的行(为什么管它叫坐标,不把它叫做行,呵呵)
Row headerRow = sheet.createRow(0);
//设置行高
headerRow.setHeightInPoints(12.75f);
for (int i = 0; i < titles.length; i++) {
//创建行坐标为0的单元格,且其列坐标为i;
Cell cell = headerRow.createCell(i);
//设置单元格的value
cell.setCellValue(titles[i]);
}
Row row;
Cell cell;
int rownum = 1;
for (int i = 0; i < data.length; i++, rownum++) {
//创建行坐标为rownum 的行
row = sheet.createRow(rownum);
if(data[i] == null) continue;
for (int j = 0; j < data[i].length; j++) {
// 为行创建单元格;
cell = row.createCell(j);
// 设置单元格的value
cell.setCellValue(data[i][j]);
}
}
System.out.println("Default column width: " + sheet.getRow(0).getLastCellNum());
System.out.println("Default column width: " + sheet.getRow(0).getPhysicalNumberOfCells());
// Write the output to a file
String file = "E:/bench-cluster/temp-resource/RunningMan.xlsx";
if(wb instanceof XSSFWorkbook) file += "x";
FileOutputStream out = new FileOutputStream(file);
wb.write(out);
out.close();
// BufferedWriter bw = new BufferedWriter(new FileWriter(file));
}
}
基于Apache POI 向xlsx写入数据的更多相关文章
- 基于Apache POI 从xlsx读出数据
[0]写在前面 0.1) these codes are from 基于Apache POI 的从xlsx读出数据 0.2) this idea is from http://cwind.iteye. ...
- Java导出数据行写入到Excel表格:基于Apache POI
Java导出数据行写入到Excel表格:基于Apache POI import java.io.File; import java.io.FileOutputStream; import org.ap ...
- 项目一:第四天 1、快递员的条件分页查询-noSession,条件查询 2、快递员删除(逻辑删除) 3、基于Apache POI实现批量导入区域数据 a)Jquery OCUpload上传文件插件使用 b)Apache POI读取excel文件数据
1. 快递员的条件分页查询-noSession,条件查询 2. 快递员删除(逻辑删除) 3. 基于Apache POI实现批量导入区域数据 a) Jquery OCUpload上传文件插件使用 b) ...
- 基于Apache Thrift的公路涵洞数据交互实现原理
基于Apache Thrift的公路涵洞数据交互实现原理 Apache Thrift简介 Apache Thrift(以下简称为“Thrift”) 是 Facebook 实现的一种高效的.支持多种编程 ...
- 用 Apache POI 读取 XLSX 数据
最近因为项目的原因,需要从一些 Microsoft Office Excel 文件读取数据并加载到数据库. Google了一下方法,发现其实可以用的 Java 第三方库很多,最著名的是 Apache ...
- 利用poi向excle写入数据
import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import org ...
- apache poi 读取xlsx并导出为json(没考虑xls)
1.用到的jar包:fastjson-1.2.9.poi(poi-3.15.poi-ooxml-3.15.poi-ooxml-schemas-3.15.xmlbeans-2.6.0.commons-c ...
- Java 使用Apache POI读取和写入Excel表格
1,引入所用的包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxm ...
- 基于Apache Hudi构建分析型数据湖
为了有机地发展业务,每个组织都在迅速采用分析. 在分析过程的帮助下,产品团队正在接收来自用户的反馈,并能够以更快的速度交付新功能. 通过分析提供的对用户的更深入了解,营销团队能够调整他们的活动以针对特 ...
随机推荐
- 基址重定位表&.reloc节区
第16-17章 - 基址重定位表&.reloc节区 @date: 2016/11/31 @author: dlive 0x01 PE重定位 若加载的是DLL.SYS文件,且在ImageBase ...
- Qualcomm 專業名詞
APSS Application processor subsystem software BAM Bus Access Manager blsp BAM low speed peripheral T ...
- python日期时间相关
参考: http://www.coder4.com/archives/2239 http://www.cnblogs.com/lhj588/archive/2012/04/23/2466653.htm ...
- pip源配置
1.使用配置文件配置文件[global]trusted-host=mirrors.aliyun.comindex-url=http://mirrors.aliyun.com/pypi/simple/ ...
- Scrapy笔记:日志的使用
scrapy的日志记录有两种方式: spider.logger.xx()和python标准库中的logger = logging.get_Logger('log information') 向日志对象 ...
- maven更换阿里云仓库
本来不想写,网上到处都是,不过好多到我这不行,自己记录下,省的到处找 D:\apache-maven-3.6.1\conf目录下setting.xml文件(这是我的解压的位置) <mirrors ...
- BZOJ1088(SCOI2005)
枚举第一行第一个格子的状态(有雷或者无雷,0或1),然后根据第一个格子推出后面所有格子的状态.推出之后判断解是否可行即可. #include <bits/stdc++.h> using n ...
- Oracle SID爆破工具SidGuess
Oracle SID爆破工具SidGuess 在Oracle中,SID是System IDentifier的缩写.SID是一个数据库的唯一标识符.当用户希望远程连接Oracle数据库时,则需要知道 ...
- Jenkins introduction
http://birdinroom.blog.51cto.com/7740375/1342897 https://www.ibm.com/developerworks/cn/java/j-lo-jen ...
- Linux基础学习3
鸟哥私房菜第十一章 read 用来读取键盘输入的变量,常被用在shell script的交互当中 [root@www ~]# read [-pt] variable 选项不参数: -p :后面可以 ...