Java 使用jxl读取Excel文件到Txt
2017-08-03 17:08
281 查看
/** * 读取excel文件到Txt * * @author wild * */ public class TestxlsOutTxt { /** * 读取xls文件内容 * * @param file * 想要读取的文件对象 * @return:Txt文件内容 */ public static String xls2String(File file) { String result = ""; try { FileInputStream fis = new FileInputStream(file); StringBuilder sb = new StringBuilder(); jxl.Workbook rwb = Workbook.getWorkbook(fis); Sheet[] sheet = rwb.getSheets(); for (int i = 0; i < sheet.length; i++) { Sheet rs = rwb.getSheet(i); for (int j = 0; j < rs.getRows(); j++) { Cell[] cells = rs.getRow(j); for (int k = 0; k < cells.length; k++) sb.append(cells[k].getContents()); } } fis.close(); result += sb.toString(); } catch (Exception e) { e.printStackTrace(); } return result; } public static void main(String[] args) { File file = new File("F:/测试的Excel.xls"); File fileTxt = new File("F:/测试的Excel.txt"); try { fileTxt.createNewFile(); Writer out = null; // 通过子类实例化,表示可以追加 out = new FileWriter(fileTxt, true); // 写入数据 out.write(xls2String(file)); out.close(); } catch (Exception e) { e.printStackTrace(); } } }
相关文章推荐
- java 按顺序 列间用逗号隔开 逐行写入txt文件(使用反射、linkedHashMap实现有序输出)
- 使用java读取txt里边的文件内容并获取大小(M).txt
- 使用java判断TXT文件的编码格式
- 使用java将搜狗词库.scel文件转化为.txt文件
- JAVA中使用freemark生成自定义文件(json、excel、yaml、txt)
- Java使用bufferedreader解析txt文件
- 【java IO】使用Java输入输出流 读取txt文件内数据,进行拼接后写入到另一个文件中
- java读取txt文件,使用正则表达式获取信息
- 使用Java读取xlxs文件和写入txt文件,并将数据写入到本地文件
- Java Applet中文件的使用
- 使用sql脚本把数据导出为.txt文件
- java从数据库导数据生成txt文件的中文编码问题
- 在VS.NET2005中使用java代码段以及SOL文件格式的解析
- Eclipse下使用Java Properties文件的中文问题
- 使用Java将Word转为Html或txt!
- 使用Java的配置文件
- 使用Java操作二进制文件 示例
- 使用Java操作二进制文件
- [Java学习]使用digester 解析xml配置文件
- 使用java将csv文件分割