JXL读取,写入Excel2003

相关阅读:
poi 读写excel2003:http://www.cnblogs.com/gavinYang/p/3576739.html
poi 读写excel2007:http://www.cnblogs.com/gavinYang/p/3576741.html

package com.write;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook; public class JSXWriteExcelXls { public static void main(String[] args) { //只支持读取2003 Map<Integer, List<String[]>> map = readExcel(new File("e:/读取excel.xls"));
for(int n=0;n<map.size();n++){
List<String[]> list = map.get(n);
System.out.println("-------------------------sheet"+n+"--------------------------------");
for(int i=0;i<list.size();i++){
String[] arr = (String[]) list.get(i);
for(int j=0;j<arr.length;j++){
if(j==arr.length-1)
System.out.print(arr[j]);
else
System.out.print(arr[j]+"|");
}
System.out.println();
}
} writeExcel(new File("e:/写入excel.xls"),map);
} public static Map<Integer, List<String[]>> readExcel(File file) {
Map<Integer, List<String[]>> map = new HashMap<Integer, List<String[]>>();
try {
Workbook wb = Workbook.getWorkbook(file);
for(int n=0;n<wb.getSheets().length;n++){
Sheet sheet = wb.getSheet(n);
if (sheet == null) {
continue;
}
List<String[]> list = new ArrayList<String[]>();
for (int i = 0; i < sheet.getRows(); i++) {
Cell[] row = sheet.getRow(i);
if (row == null) {
continue;
}
String[] singleRow = new String[row.length];
for (int j = 0; j < sheet.getColumns(); j++) {
Cell cell = sheet.getCell(j, i); // 列 行
//获取Cell的类型:cell.getType() 类型的枚举CellType.xxx
singleRow[j] = cell.getContents();
}
list.add(singleRow);
}
map.put(n, list);
}
} catch (BiffException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return map;
}    // 写文件
public static void writeExcel(File file,Map<Integer, List<String[]>> map) {
try {
// 创建文件
WritableWorkbook book = Workbook.createWorkbook(file);
for(int n=0;n<map.size();n++){
WritableSheet sheet = book.createSheet("sheet"+(n+1), n);
List<String[]> list = map.get(n);
for(int i=0;i<list.size();i++){
String[] arr = list.get(i);
for(int j=0;j<arr.length;j++){
sheet.addCell(new Label(j, i, arr[j]));
}
}
}
book.write();
book.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

JXL读取,写入Excel的更多相关文章

  1. JXL读取写入excel表格数据

    问题描述: 使用java的jxl包创建.写入excel表格数据 问题解决: (1)说明 (2)写入execel数据 注: 以上是写入数据需要调用的函数接口 注: 具体接口调用过程,如上所示 (3)读取 ...

  2. 使用C#实现读取/写入Excel表

    C#实现写入Excel表 using System; using System.Reflection; using System.IO; using Microsoft.Office.Interop. ...

  3. POI读取/写入Excel文件

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io ...

  4. python3 读取写入excel操作-win32com

    前面有写一篇是用xlrd操作excel的,这一篇是使用win32com来进行操作excel,个人推荐使用win32com. 要使用win32com组件,也需要先导入win32com包. # -*- c ...

  5. Python xlrd xlwt 读取写入Excel.

    import xlrd import xlwt #读取 xlrd.Book.encoding = "gbk" wb = xlrd.open_workbook(filename='s ...

  6. sql sever读取写入Excel总结

    主要用到openrowset,opendatasource系统函数,这两个函数任意一个都能完成任务 用这种方法可以实现Excel和sqlserver表之间的相互导入导出. 如果使用openrowset ...

  7. Java poi读取,写入Excel,处理row和cell可能为空的情况

    首先需要导入包 import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.NP ...

  8. 第十课: - 读取/写入Excel/Json格式数据

    第 10 课 从DataFrame到Excel 从Excel到DataFrame 从DataFrame到JSON 从JSON到DataFrame In [1]: import pandas as pd ...

  9. (最全最灵活地)利用Jxl工具包实现Excel表的内容读取 、写入(可向已有表中追加数据)

    1.引子 (1)读取 Jxl工具比较强大,可以方便地实现Excel表的读取和写入.另一款工具Poi也具有相似的功能,并且功能更多,运用也相对复杂.Poi读取Excel表内容时,需要先判断其内容格式,如 ...

随机推荐

  1. xgboost学习与总结

    最近在研究xgboost,把一些xgboost的知识总结一下.这里只是把相关资源作总结,原创的东西不多. 原理 xgboost的原理首先看xgboost的作者陈天奇的ppt 英文不太好的同学可以看看这 ...

  2. 并发编程(Concurrent programming)

    并发编程(Concurrent programming) 1.并发编程概述 2.委托(delegate) 3.事件(event) 4.线程(thread) 5.线程池(threadPool) 6.任务 ...

  3. FSM Code Generator

    FSM Code Generator is a script code generator for Finite State Machine, it has a viaual designer bas ...

  4. 科普贴 | 数字钱包MetaMask安装使用详解,活用MetaMask轻松驾驭以太坊

    MetaMask 是一款浏览器插件钱包,不需下载安装客户端,只需添加至浏览器扩展程序即可使用,非常方便.它是很多支持 ETH 参投的 ICO 项目推荐使用的钱包之一. 2018年初最火的一个币,应该就 ...

  5. Network Mapper 嗅探工具

    1. nmap (目标ip地址 xxx.xxx.xxx.xxx) - 例子:nmap xxx.xxx.xxx.xxx2. nmap自定义扫描 - 例子:nmap -p(端口号) xxx.xxx.xxx ...

  6. Nuxeo 认证绕过和RCE漏洞分析(CVE-2018-16341)

    简介 Nuxeo Platform是一款跨平台开源的企业级内容管理系统(CMS).nuxeo-jsf-ui组件处理facelet模板不当,当访问的facelet模板不存在时,相关的文件名会输出到错误页 ...

  7. PAT甲题题解-1012. The Best Rank (25)-排序水题

    排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...

  8. 团队作业week7

    软件分析和用户需求调查 具体细则见: http://www.cnblogs.com/xinz/p/3308608.html

  9. 2017-2018 第一学期201623班《程序设计与数据结构》-第9&10周作业问题总结

    一.作业内容 第8周作业 http://www.cnblogs.com/rocedu/p/7484252.html#WEEK08 第9周作业 http://www.cnblogs.com/rocedu ...

  10. PAT 1001. A+B Format 解题

    GitHub PDF 1001. A+B Format (20) Calculate a + b and output the sum in standard format -- that is, t ...