package test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import com.sppm.kds.entity.Policy;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
public class ImportTest {
@Test
public void test01(){
File file = new File("E:\\import\\语料.xls");
readExcelAddXML(file,"E:\\import");
}
public void readExcelAddXML(File f,String path){
OutputStreamWriter pw = null;
try {
List
//String tempFile = "E:\\import\\test.xml";
File file = new File(path,"tianlong.xml");
if (!file.exists()) {
file.createNewFile();
}
//确认流的输出文件和编码格式,此过程创建了“test.txt”实例
pw = new OutputStreamWriter(new FileOutputStream(file),"utf-8");
pw.write("
pw.write("
pw.write("
pw.write("
for(int i=0;i
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.write("
pw.flush();
}
pw.write("\n"+"
pw.flush();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
pw.close();//关闭流
} catch (IOException e) {
e.printStackTrace();
}
}
}
private static List
System.out.println("进入到readExcelFileOutList()");
List
InputStream is = null;
try{
is = new FileInputStream(f);
Workbook rwb = Workbook.getWorkbook(is);
//获得总的Sheets,得到sheet的层数
Sheet[] sheets = rwb.getSheets();
int sheetLen = sheets.length;
//获得第一个Sheets 的结果
jxl.Sheet rs = rwb.getSheet(0);
int num_row = rs.getRows();//得到行数
int num_column=rs.getColumns();//得到列数
System.out.println("行:"+num_row+"列:"+num_column);
for(int j=1;j < num_row ;j++){
Cell[] cell = rs.getRow(j);//得到第j行的所有值
for(int column_index=0;column_index
String title= cell[column_index++].getContents();
String department = cell[column_index++].getContents();
String release_date = cell[column_index++].getContents();
String timeliness= cell[column_index++].getContents();
String province = cell[column_index++].getContents();
String category= cell[column_index++].getContents();
String effect_level = cell[column_index++].getContents();
String source = cell[column_index++].getContents();
String content = cell[column_index++].getContents();
String post_date= cell[column_index++].getContents();
String issued_number = cell[column_index++].getContents();
String implement_date = cell[column_index++].getContents();
list.add(new Policy(id, title, department, release_date, timeliness, province, category, effect_level, source, content, post_date,issued_number,implement_date));
}
}
} catch(Exception ex) {
ex.printStackTrace();
} finally {
try {
if(is != null) is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return list;
}
}