<!--excel读取1-->
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
package com.dxy.study_0628.util.excel;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.*;
public class ExceltoTxt_1124 {
public static void ToAnalysisExcel() {
try {
Workbook workbook = null;
File Inputfile = new File("F:\\xxxx\\test\\user\\myInfo.xls");
File outputfile = new File("F:\\xxxx\\test\\user\\mtInfo.txt");
File outputfile2 = new File("F:\\xxxx\\test\\user\\mtInfo2.txt");
FileOutputStream fileOutputStream2 = new FileOutputStream(outputfile2);
BufferedOutputStream bw2 = new BufferedOutputStream(fileOutputStream2);
FileInputStream fileInputStream = new FileInputStream(Inputfile);
workbook = Workbook.getWorkbook(fileInputStream);
FileOutputStream fileOutputStream = new FileOutputStream(outputfile);
BufferedOutputStream bw = new BufferedOutputStream(fileOutputStream);
Sheet readfirst = workbook.getSheet(0);
System.out.println(readfirst.getName());
int rows = readfirst.getRows();
int clomns = readfirst.getColumns();
System.out.println("row:" + rows);
System.out.println("clomns:" + clomns);
for (int i = 3; i < rows; i++) {
Cell[] cells = readfirst.getRow(i);
String ce1 = cells[0].getContents();
String ce2 = cells[1].getContents();
String ce3 = cells[2].getContents();
String ce4 = cells[3].getContents();
String output = ce1 + "," + ce2 + "," + ce3 + "," + ce4 + "\n";
System.out.print(output);
byte[] outputbyte = new String(output).getBytes();
bw.write(outputbyte);
System.out.println();
bw.flush();
}
Sheet readfirst1 = workbook.getSheet(1);
System.out.println(readfirst1.getName());
int rows1 = readfirst1.getRows();
int clomns1 = readfirst1.getColumns();
for (int i = 4; i < rows1; i++) {
Cell[] cells = readfirst1.getRow(i);
String ce1 = cells[0].getContents();
String ce2 = cells[1].getContents();
String ce3 = cells[2].getContents();
String ce4 = cells[3].getContents();
String output = ce1 + "," + ce2 + "," + ce3 + "," + ce4 + "\n";
System.out.print(output);
byte[] outputbyte = new String(output).getBytes();
bw2.write(outputbyte);
System.out.println();
bw2.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ExceltoTxt_1124.ToAnalysisExcel();
}
}