Aapche POI txt 导入excel
来源:互联网 发布:centos u盘 编辑:程序博客网 时间:2024/06/08 01:50
程序运行前的txt文件格式如上图
程序运行后的excel文件如下图
package com.ultrapower.command;import java.io.BufferedReader;import java.io.File;import java.io.FileOutputStream;import java.io.FileReader;import java.io.OutputStream;import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;public class Test {static String inputfile="d:\\test001.txt";static String outputexcel="d:\\test001.xls";
static String sheetname="测试";public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new FileReader(new File(inputfile)));//获取流 XSSFWorkbook hwb = new XSSFWorkbook();// 新建一个Excel工作簿 XSSFSheet sheet = hwb.createSheet(sheetname);//新建一个工作表 //XSSFCellStyle cellStyle = hwb.createCellStyle(); XSSFRow row = null;//列 XSSFCell[] cell = null;//单元格数组 String str = null; int i = 0; //这里的str记录的是每一行的数据,由于源文件的数据都是用tab分隔的,所以要先切割,然后再添加到相对应的单元格里 while ((str = br.readLine()) != null) { row = sheet.createRow(i); //获取有几个分隔符 String[] s =str.split(""); int num =s.length; cell = new XSSFCell[num]; for(int j=0;j<=(num-1);j++){ cell[j] = row.createCell(j); cell[j].setCellValue(s[j]); } i++; } OutputStream out = new FileOutputStream(outputexcel); System.out.println("转换完毕"); hwb.write(out); out.close(); br.close(); }}
0 0
- Aapche POI txt 导入excel
- java POI 将txt文件导入到excel中
- poi 导入excel源码
- POI导入excel出错
- 使用POI 导入excel
- POI导入Excel
- excel导入(poi)
- poi导入导出excel
- poi excel导入导出
- poi 导入 Excel
- POI实现excel导入
- java poi 导入excel
- 使用poi 导入 excel
- poi导入excel
- POI数据导入Excel
- poi之excel导入
- POI方法导入Excel
- POI导入/导出 EXCEL
- iOS超全开源框架、项目和学习资料汇总(2)动画篇
- java异常种类总结
- Eclipse中设置选中某个字段页面中同名的标记出来
- Linux平台下java程序员的基本功(七)
- Linux目录结构、Linux分区大小、挂载点和如何分区
- Aapche POI txt 导入excel
- Android项目快速编译之Freeline-Android的配置与集成
- 关于BaseAdapter的数据混乱的分析与解决总结
- Android 实现图片的单点缩放、拖动、旋转
- Linux平台下java程序员的基本功(六)
- Ubuntu 12.04中设置安装Google拼音输入法
- ubuntu14.04安装visp3.0.0
- weex实践初探
- 前端问题笔记-1