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的更多相关文章

  1. Report_客制化以PLSQL输出XLS标记实现Excel报表(案例)

    2015-02-12 Created By BaoXinjian

  2. excel批量转换为CSV格式,xls批量导出csv格式

    工具/原料   excel 2013 地址链接:http://pan.baidu.com/s/1c1ZABlu 密码:d3rc 方法/步骤     首选我们把需要导出为CVS的Excel文件整理集中到 ...

  3. MySQL数据库如何与EXCEL的XLS格式相互转换

    1 将SQL导出为EXCEL方法,有如下数据库(my_impa),里面有两张表 2 如果是EXCEL格式,一定要勾选"将字段名称放在首行",否则待会儿导入的时候就需要你手工新建字段 ...

  4. PHP输出xls文件

    PHP输出xls文件 标签: phpexcelxmlcsvborderheader 2008-11-17 09:33 2611人阅读 评论(0) 收藏 举报  分类: WebDev(9)  版权声明: ...

  5. C#:导入Excel通用类(Xls格式)

    PS:在CSV格式和XLSX格式中有写到通用调用的接口和引用的插件,所以在这个xls格式里面并没有那么详细,只是配上xls通用类. 一.引用插件NPOI.dll.NPOI.OOXML.dll.NPOI ...

  6. 使用Apache POI导出Excel小结--导出XLS格式文档

    使用Apache POI导出Excel小结 关于使用Apache POI导出Excel我大概会分三篇文章去写 使用Apache POI导出Excel小结--导出XLS格式文档 使用Apache POI ...

  7. 输入一个秒数,要求转换为XX小时XX分XX秒的格式输出出来;

    package arithmetic; import java.util.Scanner; import org.junit.Test; public class Test02 { /** * 输入一 ...

  8. c#代码01--控制台的简单输入与输出及日期的格式输出

    /* 使用ReadLine()完成控制台的输入输出内容 */ using System; namespace Test { class Test1 { static void Main(string[ ...

  9. 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[ ...

随机推荐

  1. Debian10快速部署DHCP服务

    前言 DHCP(动态主机配置协议)是一个局域网的网络协议.指的是由服务器控制一段IP地址范围,客户机登录服务器时就可以自动获得服务器分配的IP地址和子网掩码. 进日,想提升一下自己的技术水平,于是就做 ...

  2. Alpha冲刺-第三次冲刺笔记

    Alpha冲刺-冲刺笔记 这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/2018SE2 这个作业要求在哪里 https://edu.cnblogs. ...

  3. SpringBoot中的Tomcat是如何启动的?

    <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>s ...

  4. 【GDOI2014模拟】JZOJ2020年8月14日T2 网格

    [GDOI2014模拟]JZOJ2020年8月14日T2 网格 题目 Time and Memory Limits Description 某城市的街道呈网格状,左下角坐标为A(0, 0),右上角坐标 ...

  5. PyQt(Python+Qt)学习随笔:QTreeWidgetItem项子项展开相关方法

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 树型部件QTreeWidget中的QTreeWidgetItem项如果一个项有子项,可以调用setE ...

  6. edusrc上海交通大学证书

  7. linux c++ 内存泄漏检测工具:AddressSanitizer(ASan)

    1.介绍 AddressSanitizer(ASan),该工具为gcc自带,4.8以上版本均可以使用. 2.使用 编译的方式很简单,只需要添加 -fsanitize=address -g 即可,如 g ...

  8. 【学习笔记】使用 bitset 求解较高维偏序问题

    求解五维偏序 给定 \(n(\le 3\times 10^4)\) 个五元组,对于每个五元组 \((a_i, b_i, c_i, d_i, e_i)\),求存在多少个 \(1\le j\le n\) ...

  9. Python编码相关

    1.#coding=utf-8的作用 作用是这个文件代码的编码格式,如果没有声明代码中不能出现中文字符,包括注释中也不能出现.否则会报错SyntaxError: Non-ASCII character ...

  10. 冬季里有温度的 3D 可视化智慧供热系统

    前言 随着供暖季来临,我国北方大部分省市开始陆续供热.一年一度的供暖问题被提上了日程.在我们的印象里,供热的设施不论是锅炉.管道还是暖气片,都是坚硬的钢铁.铸铁.HT 通过自主研发的强大的基于 HTM ...