首页 技术 正文
技术 2022年11月13日
0 收藏 675 点赞 4,809 浏览 1956 个字

【0】写在前面


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));
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,983
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,500
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,344
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,127
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,761
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,838