1.首先创建一个java项目

  完成效果如下图所示

2.导入以下jar包

3.代码如下

  其中行和列的操作是根据需求自动划分的

 public class auto_date {
private static List<List<String>> readExcel(File file) throws Exception {
// 创建输入流,读取Excel
InputStream is = new FileInputStream(file.getAbsolutePath());
// jxl提供的Workbook类
Workbook wb = Workbook.getWorkbook(is);
// 只有一个sheet,直接处理
//创建一个Sheet对象
Sheet sheet = wb.getSheet(0);
// 得到所有的行数
int rows = sheet.getRows();
// 所有的数据
List<List<String>> allData = new ArrayList<List<String>>();
// 越过第一行 它是列名称
for (int j = 1; j < rows; j++) {
List<String> oneData = new ArrayList<String>();
// 得到每一行的单元格的数据
Cell[] cells = sheet.getRow(j);
for (int k = 0; k < cells.length; k++) {
oneData.add(cells[k].getContents().trim());
}
// 存储每一条数据
allData.add(oneData);
// 打印出每一条数据
//System.out.println(oneData);
}
return allData;
}
public static void main(String[] args) {
File file = new File("F://m//1.xls");
//42列
//3337行
try {
List<List<String>> allData=readExcel(file);
//System.out.println("总数:"+allData.size());//总行数
/**
* 创建excle表格
*/
// 第一步,创建一个webbook,对应一个Excel文件
HSSFWorkbook wb = new HSSFWorkbook();
// 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet("小麦特性表");
// 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow row = sheet.createRow((int) 0);
// 第四步,创建单元格,并设置值表头 设置表头居中
//HSSFCellStyle style = wb.createCellStyle();
//style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
// HSSFRow row1 = sheet.createRow(0);
HSSFCell cell = row.createCell((short) 0);
cell.setCellValue("所有小麦特征表");
sheet.addMergedRegion(new CellRangeAddress(0,0,0,20));
HSSFRow row2 = sheet.createRow(1);
row2.createCell(0).setCellValue("品种名称");
row2.createCell(1).setCellValue("生态类型");
row2.createCell(2).setCellValue("生育期");
row2.createCell(3).setCellValue("苗性");
row2.createCell(4).setCellValue("叶色");
row2.createCell(5).setCellValue("分蘖力");
row2.createCell(6).setCellValue("株型");
row2.createCell(7).setCellValue("株高");
row2.createCell(8).setCellValue("株高");
row2.createCell(9).setCellValue("穗形");
row2.createCell(10).setCellValue("芒");
row2.createCell(11).setCellValue("壳色");
row2.createCell(12).setCellValue("粒色");
row2.createCell(13).setCellValue("硬度");
row2.createCell(14).setCellValue("籽粒饱满度");
row2.createCell(15).setCellValue("亩穗数");
row2.createCell(16).setCellValue("穗粒数");
row2.createCell(17).setCellValue("千粒重");
row2.createCell(18).setCellValue("熟相");
row2.createCell(19).setCellValue("抗倒性");
row2.createCell(20).setCellValue("抗旱性");
row2.createCell(21).setCellValue("抗寒性1");
row2.createCell(22).setCellValue("抗寒性2");
row2.createCell(23).setCellValue("粗蛋白质");
row2.createCell(24).setCellValue("湿面筋");
row2.createCell(25).setCellValue("降落数值");
row2.createCell(26).setCellValue("沉淀指数");
row2.createCell(27).setCellValue("吸水量");
row2.createCell(28).setCellValue("形成时间");
row2.createCell(29).setCellValue("稳定时间");
row2.createCell(30).setCellValue("弱化度");
row2.createCell(31).setCellValue("出粉率");
row2.createCell(32).setCellValue("延伸性");
row2.createCell(33).setCellValue("拉伸能量");
row2.createCell(34).setCellValue("拉伸面积");
row2.createCell(35).setCellValue("最大拉伸阻力");
row2.createCell(36).setCellValue("容重");
row2.createCell(37).setCellValue("节水性指数1");
row2.createCell(38).setCellValue("节水性指数2");
row2.createCell(39).setCellValue("节水性1");
row2.createCell(40).setCellValue("节水性2");
row2.createCell(41).setCellValue("抗病性1");
row2.createCell(42).setCellValue("抗病性2"); /**
* 导出txt文件
*/
// File writename = new File("G://2.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件
// writename.createNewFile(); // 创建新文件
// BufferedWriter out = new BufferedWriter(new FileWriter(writename));
// out.write("写入文件\r\n"); // \r\n即为换行 //System.out.println(allData);//输出全部
for (int i = 0; i < allData.size(); i++) {
List<String> list=allData.get(i);
HSSFRow row3 = sheet.createRow(i+2);
HSSFCell col0 = row3.createCell(0);
col0.setCellValue(list.get(0));
/**
* 导出txt文件
*/
// out.write("**************************************"+"\r\n");
// out.write("第 "+i+" 个"+"品种名称: "+list.get(0)+"\r\n");
//*************************
//System.out.println(allData.get(i));//逐条输出
//System.out.println(list.get(0));
for (int j = 0; j <list.size(); j++) {
String str=list.get(j); String newstr=str.replace(",", "。");
String newstr1=newstr.replace(";","。");
String newstr2=newstr1.replace("、","。");
String newstr3=newstr2.replace(";","。");
String newstr4=newstr3.replace(",","。");
//System.out.println(newstr1);
String[] temp;
String delimeter = "。"; // 指定分割字符
temp = newstr4.split(delimeter); // 分割字符串
// 普通 for 循环
for(int q =0; q < temp.length ; q++){
String disease="";
//生态类型
HSSFCell col11 = row3.createCell(1);
//生育周期
HSSFCell col12 = row3.createCell(2);
//苗性
HSSFCell col13 = row3.createCell(3);
//叶色
HSSFCell col14 = row3.createCell(4);
//分蘖力
HSSFCell col15 = row3.createCell(5);
//穗形
HSSFCell col16 = row3.createCell(6);
//芒
HSSFCell col17 = row3.createCell(7);
//壳色
HSSFCell col18 = row3.createCell(8);
//芒
HSSFCell col19 = row3.createCell(9);
//壳
HSSFCell col110 = row3.createCell(10);
//粒色
HSSFCell col111 = row3.createCell(11);
//硬度
HSSFCell col112 = row3.createCell(12);
//籽粒饱满度
HSSFCell col113 = row3.createCell(13);
//亩穗数
HSSFCell col114 = row3.createCell(14);
//穗粒数
HSSFCell col115 = row3.createCell(15);
//千粒重
HSSFCell col116 = row3.createCell(16);
//熟相
HSSFCell col117 = row3.createCell(17);
//抗倒性
HSSFCell col118 = row3.createCell(18);
//抗旱性
HSSFCell col119 = row3.createCell(19);
//抗寒性
HSSFCell col120 = row3.createCell(20);
HSSFCell col121 = row3.createCell(21);
HSSFCell col122 = row3.createCell(22);
HSSFCell col123 = row3.createCell(23);
HSSFCell col124 = row3.createCell(24);
HSSFCell col125 = row3.createCell(25);
HSSFCell col126 = row3.createCell(26);
HSSFCell col127 = row3.createCell(27);
HSSFCell col128 = row3.createCell(28);
HSSFCell col129 = row3.createCell(29);
HSSFCell col130 = row3.createCell(30);
HSSFCell col131 = row3.createCell(31);
HSSFCell col132 = row3.createCell(32);
HSSFCell col133 = row3.createCell(33);
HSSFCell col134 = row3.createCell(34);
HSSFCell col135 = row3.createCell(35);
HSSFCell col136 = row3.createCell(36);
HSSFCell col137 = row3.createCell(37);
HSSFCell col138 = row3.createCell(38);
HSSFCell col139 = row3.createCell(39);
HSSFCell col140 = row3.createCell(40);
HSSFCell col141 = row3.createCell(41);
HSSFCell col142 = row3.createCell(42);
HSSFCell col143 = row3.createCell(43);
for(int r =0; r < temp.length ; r++){
if (temp[r].contains("春性")==true||temp[r].contains("冬性")==true) { col11.setCellValue(temp[r]);
}
if (temp[r].contains("生育期")==true) {
col12.setCellValue(temp[r]);
}
if (temp[r].contains("幼苗")==true) {
col13.setCellValue(temp[r]);
}
if (temp[r].contains("叶色")==true) {
col14.setCellValue(temp[r]);
}
if (temp[r].contains("分蘖力")==true) {
col15.setCellValue(temp[r]);
}
if (temp[r].contains("株型")==true) {
col16.setCellValue(temp[r]);
}
if (temp[r].contains("株高")==true) {
col17.setCellValue(temp[r]);
}
if (temp[r].contains("穗纺锤")==true||temp[r].contains("穗长方")==true||temp[r].contains("穗棍棒")==true
||temp[r].contains("纺锤型")==true||temp[r].contains("棍棒形")==true
||temp[r].contains("穗型长方形")==true||temp[r].contains("长方穗型")==true) {
col19.setCellValue(temp[r]);
}
if (temp[r].contains("芒")==true) {
col110.setCellValue(temp[r]);
}
if (temp[r].contains("壳")==true) {
col111.setCellValue(temp[r]);
}
if (temp[r].contains("红粒")==true||temp[r].contains("蓝粒")==true||
temp[r].contains("白粒")==true||temp[r].contains("黑粒")==true||temp[r].contains("粒红")==true
||temp[r].contains("粒黑")==true||temp[r].contains("粒白")==true) {
col112.setCellValue(temp[r]);
}
if (temp[r].contains("硬质")==true) {
col113.setCellValue(temp[r]);
}
if (temp[r].contains("饱满")==true) {
col114.setCellValue(temp[r]);
}
if (temp[r].contains("亩穗数")==true) {
col115.setCellValue(temp[r]);
}
if (temp[r].contains("穗粒数")==true) {
col116.setCellValue(temp[r]);
}
if (temp[r].contains("千粒重")==true) {
col117.setCellValue(temp[r]);
}
if (temp[r].contains("熟相")==true) {
col118.setCellValue(temp[r]);
}
if (temp[r].contains("抗倒性")==true) {
col119.setCellValue(temp[r]);
}
if (temp[r].contains("抗旱性")==true) {
col120.setCellValue(temp[r]);
}
if (temp[r].contains("抗寒性")==true) {
col121.setCellValue(temp[r]);
}
// if (temp[r].contains("抗寒性")==true) {
// col122.setCellValue(temp[r]);
// }
if (temp[r].contains("粗蛋白质")==true) {
col123.setCellValue(temp[r]);
}
if (temp[r].contains("湿面筋")==true) {
col124.setCellValue(temp[r]);
}
if (temp[r].contains("降落数值")==true) {
col125.setCellValue(temp[r]);
}
if (temp[r].contains("沉淀指数")==true) {
col126.setCellValue(temp[r]);
}
if (temp[r].contains("吸水量")==true||temp[r].contains("吸水率")==true) {
col127.setCellValue(temp[r]);
}
if (temp[r].contains("形成时间")==true) {
col128.setCellValue(temp[r]);
}
if (temp[r].contains("稳定时间")==true) {
col129.setCellValue(temp[r]);
}
if (temp[r].contains("弱化度")==true) {
col130.setCellValue(temp[r]);
}
if (temp[r].contains("出粉率")==true) {
col131.setCellValue(temp[r]);
}
if (temp[r].contains("延伸性")==true) {
col132.setCellValue(temp[r]);
}
if (temp[r].contains("拉伸能量")==true) {
col133.setCellValue(temp[r]);
}
if (temp[r].contains("拉伸面积")==true) {
col134.setCellValue(temp[r]);
}
if (temp[r].contains("最大拉伸阻力")==true) {
col135.setCellValue(temp[r]);
}
if (temp[r].contains("容重")==true) {
col136.setCellValue(temp[r]);
}
if (temp[r].contains("节水指数")==true) {
col137.setCellValue(temp[r]);
}
// if (temp[r].contains("节水指数2")==true) {
// col138.setCellValue(temp[r]);
// }
if (temp[r].contains("节水性")==true) {
col139.setCellValue(temp[r]);
}
// if (temp[r].contains("节水性2")==true) {
// col140.setCellValue(temp[r]);
// }
/**
* 各种病症
*/
if(temp[r].contains("抗病鉴定")==true){
disease+=temp[r]+":";
}
if(temp[r].contains("叶锈病")==true){
disease+=temp[r]+",";
}
if(temp[r].contains("条锈病")==true){
disease+=temp[r]+",";
}
if(temp[r].contains("白粉病")==true){
disease+=temp[r]+",";
}
if(temp[r].contains("赤霉病")==true){
disease+=temp[r]+",";
}
if(temp[r].contains("抗条锈病")==true){
disease+=temp[r];
}
if(temp[r].contains("纹枯病")==true){
disease+=temp[r];
}
if(temp[r].contains("黄花叶病")==true){
disease+=temp[r];
}
if(temp[r].contains("根腐病")==true){
disease+=temp[r];
}
if(temp[r].contains("秆锈病")==true){
disease+=temp[r];
}
if(temp[r].contains("株期感病")==true){
disease+=temp[r];
}
if(temp[r].contains("株期抗病")==true){
disease+=temp[r];
}
if(temp[r].contains("抗赤霉")==true){
disease+=temp[r];
}
if(temp[r].contains("抗赤霉")==true){
disease+=temp[r];
}
if(true){
col141.setCellValue(disease);
//System.out.println(disease);
} // if (temp[r].contains("抗病性2")==true) {
// col142.setCellValue(temp[r]);
// } /**
* 导出txt文件
*/
// out.write("属性: "+temp[r]+"\r\n"); //System.out.println(temp[r]);//输出字符串
}
}
}
//System.out.println(list.get(1));
} // 第五步,将文件存到指定位置
FileOutputStream fout = new FileOutputStream("F://m//2.xls");
wb.write(fout);
fout.close();
/**
* 关闭txt流
*/
// out.flush(); // 把缓存区内容压入文件
// out.close(); // 最后记得关闭文件
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

  

4.做成效果如下图所示

欢迎各位大佬前来交流+QQ:164368701

java导入excle表格,并且对表格进行相应的修改,并对表格数据进行整理,最后导出本地表格等一系列操作的更多相关文章

  1. 使用poi导出Excel表格,jar包冲突

    HTTP Status 500 – Internal Server Error Type Exception Report Message Handler processing failed; nes ...

  2. Java代码导入导出 Excel 表格最简单的方法

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...

  3. Java利用POI实现导入导出Excel表格示例代码

    转自:https://www.jb51.net/article/95526.htm 介绍 Jakarta POI 是一套用于访问微软格式文档的Java API.Jakarta POI有很多组件组成,其 ...

  4. java导出excel表格

    java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...

  5. PHP导入导出excel表格图片(转)

    写excel的时候,我用过pear的库,也用过pack压包的头,同样那些利用smarty等作的简单替换xml的也用过,csv的就更不用谈了.呵呵.(COM方式不讲了,这种可读的太多了,我也写过利用wp ...

  6. .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格

    一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...

  7. PHP导入导出excel表格图片的代码和方法大全

    基本上导出的文件分为两种: 1:类Excel格式,这个其实不是传统意义上的Excel文件,只是因为Excel的兼容能力强,能够正确打开而已.修改这种文件后再保存,通常会提示你是否要转换成Excel文件 ...

  8. 【PHP】导入、导出Excel表格(有使用PHPExcel和不使用的两个版本)

    ------------        首先,导出excel          ---------------- 一.不使用PHPExcel的版本,很简单的一个方法,简洁.推荐 很简单的导出一个exc ...

  9. java 实现用户自由选择字段实现导出EXCEL表格

    package com.thinkgem.jeesite.common.utils.excel; import java.io.File; import java.io.OutputStream; i ...

随机推荐

  1. css3动画(animation)效果1-漂浮的白云

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. 17、xtrabackup 常用备份功能与选项

    并行备份 > innobackupex -p123123 --parallel=8 /backup 节流备份 > innobackupex -p123123 --throttle=200  ...

  3. adb命令之pm

    常用的用法: 查看已经安装的包 pm list packages 查看已经安装的包以及apk路径(-3:只看第三方应用: -s:只看系统应用) -f: see their associated fil ...

  4. scrapy下载中间件,UA池和代理池

    一.下载中间件 框架图: 下载中间件(Downloader Middlewares) 位于scrapy引擎和下载器之间的一层组件. - 作用: (1)引擎将请求传递给下载器过程中, 下载中间件可以对请 ...

  5. CF1059C Sequence Transformation 题解

    这几天不知道写点什么,状态也不太好,搬个题上来吧 题意:给定一个数n,设一个从1到n的序列,每次删掉一个序列中的数,求按字典序最大化的GCD序列 做法:按2的倍数找,但是如果除2能得到3的这种情况要特 ...

  6. 浅谈iOS开发中多语言的字符串排序

    一.前言 在iOS开发中,一个经常的场景是利用tableview展示一组数据,以很多首歌曲为例子.为了便于查找,一般会把这些歌曲按照一定的顺序排列,还会加上索引条以便于快速定位. 由于歌曲名可能有数字 ...

  7. 4.1、支持向量机(SVM)

    1.二分类问题 在以前的博客中,我们介绍了用于处理二分类问题的Logistic Regression算法和用于处理多分类问题的Softmax Regression算法,典型的二分类问题,如图: 对于上 ...

  8. 海思hi35xx 开发学习(1):海思媒体处理平台架构

    处理平台架构图: 主要分为: 视频输入(VI):VI 模块捕获视频图像,可对其做剪切.去噪等处理,并输出多路不同分辨率的图像数据. 视频处理(VPSS):VPSS 模块接收 VI 和解码模块发送过来的 ...

  9. CF1012B Chemical table 题解【二分图】【构造】

    有意思的网格图转化.CF Div.1 还是挺有难度的. 注:由于本题有较完美的中文题面,所以不贴英文题面. 英文题面 题目描述 Innopolis 大学的教授正努力研究元素周期表.他们知道,有 \(n ...

  10. 02-线性结构4 Pop Sequence (25 分)

    Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and p ...