package soc;
import java.io.File;
import java.io.*;
public class pro {
String[][] mat=new String[3000][700];
int fastline,lastline;
int indexline,creditline,prefline,subline;
int creditx,credity;
int[] year=new int[50000];
int[] month=new int[50000];
String[] dic=new String[50000];
String[] credit=new String[500];
String[] index=new String[5000];
String[] code=new String[5000];
String date;
int maxy,maxx;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
File f=new File("data");
String[] fx=f.list();
maxy=2500;
maxx=500;
int trs=0;
int tr;
for(tr=0;tr<fx.length;tr++){
String file="data/"+fx[tr];
int number;
count subc=new count();
subc.makedata(file);
number=subc.number;
int k;
for(k=0;k<number;k++){
System.out.println(file+","+k);
readxls sub=new readxls();
sub.maxx=maxx;
sub.maxy=maxy;
sub.makedata(file,k);
mat=sub.mat;
writehtml("ren.html");
int s,sx;
indexline=0;
fastline=0;
for(s=1;s<20;s++){
for(sx=1;sx<10;sx++){
int h=0;
if(mat[s][sx].indexOf("北")>-1)h=h+1;
if(mat[s][sx].indexOf("海")>-1)h=h+1;
if(h==2)indexline=sx;
if(h==2)fastline=s;
}
}
System.out.println(indexline);
System.out.println(fastline);
for(s=fastline;s<2300;s++){
int h=0;
if(mat[s][indexline].indexOf("与")>-1)h=h+1;
if(mat[s][indexline].indexOf("那")>-1)h=h+1;
if(h==2)lastline=s;
}
System.out.println(lastline);
for(s=fastline;s<lastline+1;s++){
index[s]=mat[s][indexline];
code[s]=mat[s][indexline-1];
}
for(s=1;s<fastline;s++){
for(sx=1;sx<20;sx++){
if(mat[s][sx].indexOf("市")>-1)creditline=s;
}
}
System.out.println("DE"+creditline);
for(s=1;s<400;s++){
credit[s]=mat[creditline][s];
}
for(s=1;s<400;s++){
String str=mat[fastline-1][s];
year[s]=numx(str);
}
trs=trs+1;
writexml("gdata/"+trs+".txt");
}
}
}
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=1;sx<maxx+1;sx++){
if(year[sx]>0){
pw.print("<year>");
pw.print(year[sx]);
pw.print("</year>");
pw.print("<pref>");
pw.print(index[s]);
pw.print("</pref>");
pw.print("<code>");
pw.print(code[s]);
pw.print("</code>");
pw.print("<credit>");
pw.print(credit[sx]);
pw.print("</credit>");
pw.print("<value>");
pw.print(mat[s][sx]);
pw.println("</value>");
}
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
int numx(String str){
int nx;
nx=0;
try{
nx=Integer.parseInt(str);
}catch (Exception e) {}
return nx;
}
void writehtml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println("<html>");
pw.println("<head>");
pw.println("<meta charset=\"UTF-8\">");
pw.println("</head>");
pw.println("<body>");
pw.print("<table rules=\"all\">");
pw.print("<tr>");
pw.print("<td>");
pw.print("");
pw.print("</td>");
for(sx=1;sx<maxx+1;sx++){
pw.print("<th>");
pw.print(sx);
pw.print("</th>");
}
pw.println("</tr>");
for(s=1;s<maxy+1;s++){
pw.print("<tr>");
pw.print("<th>");
pw.print(s);
pw.print("</th>");
for(sx=1;sx<maxx+1;sx++){
pw.print("<td>");
pw.print(mat[s][sx]);
pw.print("</td>");
}
pw.println("</tr>");
}
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package soc;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class count{
String[] name=new String[1000];
int number;
void makedata(String file){
try{
int s;
FileInputStream is = new FileInputStream(file);
Workbook wb = new HSSFWorkbook(is);
number=wb.getNumberOfSheets();
for(s=0;s<number;s++){
name[s]=wb.getSheetName(s);
}
} catch (Exception e) {e.printStackTrace();}
}
}
package soc;
import java.io.FileInputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class readxls{
int pointx,pointy;
int px,py;
int maxx,minx,miny,maxy;
int creditrow;
int checkline,checkx;
String[][] mat=new String[3000][5000];
void makedata(String file,int shnumber){
try{
FileInputStream is = new FileInputStream(file);
Workbook wb = new HSSFWorkbook(is);
Sheet sh = wb.getSheetAt(shnumber);
int s,sx;
int h1,h2;
String str;
for(s=miny;s<maxy+1;s++){
for(sx=minx;sx<maxx+1;sx++){
mat[s][sx]="";
}
}
for(s=miny;s<maxy+1;s++){
Row row = sh.getRow(s-1);
h1=0;
if(row==null)h1=100;
if(h1<50){
for(sx=minx;sx<maxx+1;sx++){
Cell cell = row.getCell(sx-1);
str="";
h2=0;
if(cell==null)h2=100;
if(h2<50){
int type =cell.getCellType();
str="";
if(type==0)str=""+cell.getNumericCellValue();
if(type==1)str=cell.getStringCellValue();
mat[s][sx]=str;
}
}
}
}
} catch (Exception e) {e.printStackTrace();}
}
}
最終更新:2016年06月10日 16:57