java 读取 并 写入一个新的Excle
来源:互联网 发布:重庆编程培训 编辑:程序博客网 时间:2024/06/11 20:44
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(); } }}
阅读全文
0 0
- java 读取 并 写入一个新的Excle
- 一个java读取word文档并将其写入xml文档的例子
- 如何使用JavaExcel(jxl)读取一个文件并写入一个新文件
- 如何读取一个文件并将内容写入一个新文件中
- java读取excle指定位置的数据
- .Net读取Excle数据写入到数据库
- MATLAB读取txt文件,并逐行处理字符串,写入到新的txt中
- python读取excel指定列数据并写入到新的excel
- java写入Excel并读取文件
- Java读取Excel文件并写入数据库
- 利用Java读取并写入Word文件
- 利用Java读取并写入Word文件
- 利用Java读取并写入Word文件
- 用java的poi类读取一个excel表格的内容后再写入到一个新excel表格中的完整代码
- 救火!各位大虾,怎样用JAVA程序读取excle文件或excle数据库,并插入到oracle数据库中,万分感谢
- 用JAVA编写的读取一个文本文件的一行之后读取另一个文本文件的另一行,逐行交叉读取并生成新的文本文件
- winform中 如何读取Excel文件,之后再把它写入一个新的Excel文件
- QT读取xml文件,然后写入另外一个新的xml文件
- java使double/float保留两位小数的多方法 java保留两位小数
- 大数据学习第一章 linux环境的安装配置
- Win10和Ubuntu的引导修复,Ubuntu引导Win10
- Jsoup解决跨域请求----示例java版
- thymeleaf th:text 不显示标签
- java 读取 并 写入一个新的Excle
- 巧用表值函数
- 无法安装pywin32 蓝屏时提醒which was not found in the registry
- (React-Native 学习之五) HelloWorld RnDemo运行
- Java-运算符
- tensorflow if语句
- /dev/rhdisk5: the requested resource is busy
- 两种事务配置方式
- vue学习笔记4