package ken;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class pro {
String urlx;
String[] data=new String[50000];
int s,sx,datanumber,tx;
String[] name=new String[50000];
String[] code=new String[50000];
int[] id=new int[50000];
int number;
String[][] mat=new String[5000][200];
int fastline,lastline;
int indexline,creditline,prefline,subline;
int creditx,credity;
int[] year=new int[50000];
int[] month=new int[50000];
String[] index=new String[50000];
String[] credit=new String[500];
String[] subcredit=new String[500];
int yy,mm;
int upper,under;
String file;
int maxx=50;
int maxy=2000;
public static void main(String[] args) {
pro te=new pro();
}
pro(){
int page;
yy=2016;
mm=3;
for(page=1;page<166;page++){
mm=mm-1;
if(mm<1)yy=yy-1;
if(mm<1)mm=12;
String str;
str=""+yy+mm;
if(mm<10)str=""+yy+"0"+mm;
file="data/"+str+".xls";
readxls sub=new readxls();
sub.maxx=maxx;
sub.maxy=maxy;
sub.makedata(file,0);
mat=sub.mat;
writehtml("ren.html");
int h;
indexline=0;
fastline=7;
for(s=1;s<20;s++){
for(sx=1;sx<10;sx++){
if(mat[s][sx].indexOf("穀")>-1)fastline=s-1;
if(mat[s][sx].indexOf("穀")>-1)indexline=sx;
}}
lastline=0;
creditx=0;
credity=0;
for(s=fastline;s<maxy;s++){
if(mat[s][indexline].indexOf("類")>-1)lastline=s;
}
System.out.println(fastline);
System.out.println(lastline);
for(s=1;s<fastline;s++){
for(sx=indexline+1;sx<15;sx++){
h=0;
if(mat[s][sx].indexOf("ト")>-1)h=h+1;
if(mat[s][sx].indexOf("ン")>-1)h=h+1;
if(creditx==0)h=h+1;
if(h==3)creditx=sx;
}}
System.out.println(creditx);
for(s=fastline;s<lastline+1;s++){
credit[s]=mat[s][indexline]+mat[s][indexline+1];
credit[s]=credit[s].replace(" ","");
credit[s]=credit[s].replace(" ","");
credit[s]=credit[s].replace("\n","");
if(credit[s]==null)credit[s]="";
}
writefile("gdata/"+page+".txt");
}
}
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("入出力エラーです。"); }
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
int ch;
for(s=fastline;s<lastline+1;s++){
pw.print("<year>");
pw.print(yy);
pw.print("</year>");
pw.print("<month>");
pw.print(mm);
pw.print("</month>");
pw.print("<mono>");
pw.print(credit[s]);
pw.print("</mono>");
pw.print("<code_mono>");
pw.print(s);
pw.print("</code_mono>");
pw.print("<ton>");
pw.print(mat[s][creditx]);
pw.print("</ton>");
pw.print("<tonkilo>");
pw.print(mat[s][creditx+1]);
pw.println("</tonkilo>");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package ken;
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[10000][500];
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月08日 21:18