package exl;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class pro {
String[][] mat=new String[200][200];
int fastline,lastline;
int creditx,credity;
String[] party=new String[200];
String[] name=new String[200];
String[] city=new String[200];
public static void main(String[] args) {
pro t=new pro();
}
pro(){
try{
int p;
int delta=0;
for(p=1;p<48;p++){
String file="data/"+p+".xls";
FileInputStream is = new FileInputStream(file);
Workbook wb = new HSSFWorkbook(is);
int n=wb.getNumberOfSheets();
int k;
Sheet sh=wb.getSheetAt(0);
int s,sx;
int maxx,maxy;
maxx=100;
maxy=180;
for(s=1;s<maxy+1;s++){
for(sx=1;sx<maxx+1;sx++){
mat[s][sx]="";
}}
for(s=1;s<maxy+1;s++){
Row row = sh.getRow(s-1);
int j=0;
if(row==null)j=100;
if(j<50){
for(sx=1;sx<maxx+1;sx++){
Cell cc = row.getCell(sx-1);
int h=0;
if(cc==null)h=100;
if(h<50){
int type =cc.getCellType();
String bb="";
if(type==1)bb=cc.getStringCellValue();
if(type==0)bb=""+cc.getNumericCellValue();
mat[s][sx]=bb;
}
}
}
}
fastline=0;
lastline=0;
for(s=1;s<maxy+1;s++){
if(mat[s][1].length()>0)lastline=s;
}
fastline=11;
creditx=2;
credity=0;
for(s=1;s<maxx+1;s++){
if(mat[fastline][s].length()>0)credity=s;
}
for(s=creditx;s<credity+1;s++){
party[s]=mat[6][s];
if(party[s].length()<1)party[s]=party[s-1];
name[s]=mat[9][s];
}
for(s=fastline;s<lastline+1;s++){
city[s]=mat[s][1];
}
delta=delta+1;
writexml("gdata/"+delta+".txt");
}
} catch (Exception e) {e.printStackTrace();}
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=fastline;s<lastline+1;s++){
for(sx=creditx;sx<credity+1;sx++){
pw.print("<city>");
pw.print(city[s]);
pw.print("</city>");
pw.print("<party>");
pw.print(party[sx]);
pw.print("</party>");
pw.print("<name>");
pw.print(name[sx]);
pw.print("</name>");
pw.print("<value>");
pw.print(mat[s][sx]);
pw.println("</value>");
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
最終更新:2016年06月14日 01:09