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. ASP.NET多行文本框限制字符个数

    asp.net中TextBox当设置TextMode = Multiline时,其MaxLength属性无效.可使用JS进行辅助限制输入的字符个数.中文算两个字符,西文算1个字符. TextBox属性 ...

  2. python3获取指定目录内容的详细信息

    不同平台获取指定目录内容的详细信息命令各不相同: Linux中可以通过ls -al获取获取 windows中可以通过dir命令获取 下面是我写的一个通用获取目录内容详细信息的python3脚本: #! ...

  3. 表单设置 disabled 后无法传值到后台的解决办法

    在提交 from 表单时,下面的 input 无法正常提交给后台, 发现,如果input的字段设为disabled,该表单是无法提交的. <input type="text" ...

  4. Kaggle: Google Analytics Customer Revenue Prediction EDA

    前言 内容提要 本文为Kaggle竞赛 Google Analytics Customer Revenue Prediction 的探索性分析 题目要求根据历史顾客访问GStore的数据,预测其中部分 ...

  5. tensorflow 曲线拟合

    tensorflow 曲线拟合 Python代码: import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ...

  6. 《Pro SQL Server Internals, 2nd edition》的CHAPTER 3 Statistics中的Introduction to SQL Server Statistics、Statistics and Execution Plans、Statistics Maintenance(译)

    <Pro SQL Server Internals> 作者: Dmitri Korotkevitch 出版社: Apress出版年: 2016-12-29页数: 804定价: USD 59 ...

  7. CMS漏洞检测工具 – CMSmap

    CMSmap是一个Python编写的针对开源CMS(内容管理系统)的安全扫描器,它可以自动检测当前国外最流行的CMS的安全漏洞. CMSmap主要是在一个单一的工具集合了不同类型的CMS的常见的漏洞. ...

  8. 微软职位内部推荐-Senior Software Engineer - Back End

    微软近期Open的职位: SharePoint is a multi-billion dollar enterprise business that has grown from an on-prem ...

  9. Final阶段基于NABCD评论作品

    组名:杨老师粉丝群 组长:乔静玉 组员:吴奕瑶  刘佳瑞  公冶令鑫  杨磊  刘欣  张宇  卢帝同 一.拉格朗日2018--<飞词> 1.1  NABCD分析 N(Need,需求):该 ...

  10. “吃神么,买神么”的第一个Sprint计划(结束)

    “吃神么,买神么”项目Sprint计划 ——5.28  星期四(第八天)第一次Spring计划结束   第一阶段Spring的目标以及完成情况: 时间:5月21号~5月28号(7天) 目标:第一阶段结 ...