输入xls格式 输出 xls
package com.cn.peitest.excel.word; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date; import org.apache.poi.hssf.usermodel.HSSFCell;
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.poifs.filesystem.POIFSFileSystem;
public class xlsToxls { public static void main(String[] args) throws Exception { //输入xls格式
POIFSFileSystem fs = null;
HSSFWorkbook xwb = null;
HSSFSheet xsheet = null;
HSSFRow xrow = null;
HSSFCell xcell = null;
//输出xls格式
HSSFWorkbook hwb = new HSSFWorkbook();
HSSFSheet hsheet =null;// wb.createSheet("sheet1");
HSSFRow hrow = null;//sheet.createRow(0);
HSSFCell hcell=null;//row0.createCell(0);
//cell0.setCellValue("0000"); SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间 File inf=new File("C:\\Users\\pei\\Desktop\\新建 XLS 工作表.xls");
File ouf=new File("C:\\Users\\Pei\\Desktop\\HYD test 1_0_2 tm="+df.format(new Date())+".xls"); boolean sheetflag=true;
int sheetid=0; boolean rowflag=true;
int rowid =0;
try {
FileInputStream fis = new FileInputStream(inf);
xwb=new HSSFWorkbook(fis);
System.out.println("表单数="+xwb.getNumberOfSheets());
while(sheetflag){
if(sheetid==xwb.getNumberOfSheets()){break;}
xsheet=xwb.getSheetAt(sheetid);
if(xsheet==null){
sheetflag=false;
}else{
hsheet=hwb.createSheet(xsheet.getSheetName());
sheetid++;
rowid=0;
rowflag=true;
while(rowflag){
hrow=hsheet.createRow(rowid);
xrow=xsheet.getRow(rowid);
if(xrow==null){
rowflag=false;
}else{
rowid++;
for(int c=0;c<30;c++){ xcell=xrow.getCell(c);
if(xcell!=null&&xcell.toString().length()>0){
String a1=xcell.toString().replaceAll(".00", "");
String a2=a1.replaceAll(".0", "");
String data=a2.replaceAll("O", "0");
hrow.createCell(c).setCellValue(data);
}
}
}
}
}
} //FileOutputStream output=new FileOutputStream(ouf);
//xwb.write(output);
//System.out.println("导出结束");
//output.close();
} catch (Exception e) {
e.printStackTrace();
}
finally{
System.out.println("处理结束。。。。等待导出完成");
FileOutputStream output=new FileOutputStream(ouf);
hwb.write(output);
System.out.println("导出结束");
output.close();
} } }
//pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.com</groupId>
<artifactId>excelReadAndWrite</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.codec</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
</dependencies>
</project>
输入xls格式 输出 xls的更多相关文章
- Report_客制化以PLSQL输出XLS标记实现Excel报表(案例)
2015-02-12 Created By BaoXinjian
- excel批量转换为CSV格式,xls批量导出csv格式
工具/原料 excel 2013 地址链接:http://pan.baidu.com/s/1c1ZABlu 密码:d3rc 方法/步骤 首选我们把需要导出为CVS的Excel文件整理集中到 ...
- MySQL数据库如何与EXCEL的XLS格式相互转换
1 将SQL导出为EXCEL方法,有如下数据库(my_impa),里面有两张表 2 如果是EXCEL格式,一定要勾选"将字段名称放在首行",否则待会儿导入的时候就需要你手工新建字段 ...
- PHP输出xls文件
PHP输出xls文件 标签: phpexcelxmlcsvborderheader 2008-11-17 09:33 2611人阅读 评论(0) 收藏 举报 分类: WebDev(9) 版权声明: ...
- C#:导入Excel通用类(Xls格式)
PS:在CSV格式和XLSX格式中有写到通用调用的接口和引用的插件,所以在这个xls格式里面并没有那么详细,只是配上xls通用类. 一.引用插件NPOI.dll.NPOI.OOXML.dll.NPOI ...
- 使用Apache POI导出Excel小结--导出XLS格式文档
使用Apache POI导出Excel小结 关于使用Apache POI导出Excel我大概会分三篇文章去写 使用Apache POI导出Excel小结--导出XLS格式文档 使用Apache POI ...
- 输入一个秒数,要求转换为XX小时XX分XX秒的格式输出出来;
package arithmetic; import java.util.Scanner; import org.junit.Test; public class Test02 { /** * 输入一 ...
- c#代码01--控制台的简单输入与输出及日期的格式输出
/* 使用ReadLine()完成控制台的输入输出内容 */ using System; namespace Test { class Test1 { static void Main(string[ ...
- PHP系列 | PHPexcel导入xls格式 ,提示错误:iconv(): Wrong charset, conversion from `CP936' to `UTF-8' is not allowed
导入xls格式(2003版本)时会报错提示错误信息 iconv(): Wrong charset, conversion from `CP936' to `UTF-8' is not allowed[ ...
随机推荐
- linux查看内存及磁盘使用情况
1.查看当前目录 命令: df -h (统一每个目录下磁盘的整体情况) 2.查看指定目录 在命令后直接放目录名,比如查看"usr"目录使用情况: 命令: df ...
- 【进阶之路】定时任务调用平台xxl-job
大家好,我是练习java两年半时间的南橘,从一名连java有几种数据结构都不懂超级小白,到现在懂了一点点的进阶小白,学到了不少的东西.知识越分享越值钱,我这段时间总结(包括从别的大佬那边学习,引用)了 ...
- 20200116_centos7.2 下 mysql_5.7修改root密码
1. 需改my.cnf文件 [root@rakinda-iot-platform ~]# vim /etc/my.cnf 2. 新增一行, 登录时跳过密码, 保存后退出, 重启mysql system ...
- moviepy音视频剪辑VideoClip类to_ImageClip方法使用注意事项
☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑VideoClip类to_ImageClip方法将剪辑对应时刻t的帧转换成ImageClip图像剪辑,图像剪辑是所有帧都是固定图像数据 ...
- vue中两行代码实现全选及子选项全部选中,则全选按钮选中,反之有一个没选中,就取消选中全选按钮
every() 方法使用指定函数检测数组中的所有元素: 如果数组中检测到有一个元素不满足,则整个表达式返回 false ,且剩余的元素不会再进行检测. 如果所有元素都满足条件,则返回 true. 逻辑 ...
- CTFD平台部署自制题目指北(灌题)
给实验室同学搭建的CTFD平台用于内部训练和CTF的校赛,为了循序渐进当然是先内部出一些简单入门的题目,但是网上大部分关于CTFD平台的都只是部署,而关于题目放置的内容却很少,虽然这个过程比较简单,但 ...
- PHP代码审计分段讲解(2)
03 多重加密 源代码为: <?php include 'common.php'; $requset = array_merge($_GET, $_POST, $_SESSION, $_COOK ...
- 记阿里云 RDS MySQL 的一个大坑
花了一个下午的时间,终于把一个阿里云 RDS MySQL 的一个大坑填上了,解决方法令人匪夷所思!绝对会让各位看官感到大吃一惊,阿里云 RDS MySQL 居然有这样 xx 的大坑! 问题 最近应业务 ...
- python——sklearn完整例子整理示范(有监督,逻辑回归范例)(原创)
sklearn使用方法,包括从制作数据集,拆分数据集,调用模型,保存加载模型,分析结果,可视化结果 1 import pandas as pd 2 import numpy as np 3 from ...
- (数据科学学习手札99)掌握pandas中的时序数据分组运算
本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 我们在使用pandas分析处理时间序列数据 ...