package hotel2;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class pro {
String[] name=new String[1000];
int number,s;
String[] name_month=new String[1000];
String[] name_table=new String[1000];
int[] code_month=new int[1000];
int[] code_table=new int[1000];
String[][] mat=new String[200][200];
int fastline,lastline,prefline;
String[] v=new String[200];
String[] pref=new String[200];
int tr;
int mon,cr;
int delta;
public static void main(String[] args) {
pro te=new pro();
}
pro(){
int n=0;
for(tr=21;tr<27;tr++){
namex sub=new namex();
sub.makedata("data/h"+tr+".xls");
name=sub.name;
number=sub.number;
for(s=1;s<13;s++){
name_month[s]="("+s+"月)";
}
for(s=1;s<11;s++){
name_table[s]="第"+s+"表";
}
int sx;
for(s=0;s<number;s++){
code_month[s]=0;
for(sx=1;sx<13;sx++){
if(name[s].indexOf(name_month[sx])>-1)code_month[s]=sx;
}
}
for(s=0;s<number;s++){
code_table[s]=0;
for(sx=1;sx<11;sx++){
if(name[s].indexOf(name_table[sx])>-1)code_table[s]=sx;
}
if(name[s].indexOf("参考")>-1)code_table[s]=0;
}
int k;
for(k=0;k<number;k++){
mon=code_month[k];
cr=code_table[k];
int z=0;
if(mon==0)z=100;
if(cr==0)z=100;
if(z<50){
readxls sub2=new readxls();
sub2.maxx=100;
sub2.maxy=100;
sub2.makedata("data/h"+tr+".xls",k);
mat=sub2.mat;
int h;
fastline=0;
for(s=1;s<10;s++){
for(sx=1;sx<10;sx++){
h=0;
if(mat[s][sx].indexOf("北")>-1)h=h+1;
if(mat[s][sx].indexOf("海")>-1)h=h+1;
if(h==2)fastline=s;
if(h==2)prefline=sx;
}}
lastline=0;
for(s=fastline;s<100;s++){
h=0;
if(mat[s][prefline].indexOf("沖")>-1)h=h+1;
if(mat[s][prefline].indexOf("縄")>-1)h=h+1;
if(lastline==0)h=h+1;
if(h==3)lastline=s;
}
System.out.println(prefline);
System.out.println(fastline);
System.out.println(lastline);
for(s=fastline;s<lastline+1;s++){
pref[s]="p"+(s+1-fastline);
v[s]=mat[s][prefline+1];
}
n=n+1;
writexml("gdata/"+n+".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++){
pw.print("<year>");
pw.print(tr);
pw.print("</year>");
pw.print("<month>");
pw.print(mon);
pw.print("</month>");
pw.print("<pref>");
pw.print(pref[s]);
pw.print("</pref>");
pw.print("<table>");
pw.print(cr);
pw.print("</table>");
pw.print("<value>");
pw.print(v[s]);
pw.println("</value>");
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package hotel2;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class namex{
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 hotel2;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class readxls {
int maxx,maxy;
Cell cc;
String[][] mat=new String[50000][500];
int[][] color= new int[50000][500];
void makedata(String file,int number){
try{
FileInputStream is = new FileInputStream(file);
Workbook wb = new HSSFWorkbook(is);
Sheet sh = wb.getSheetAt(number);
int s,sx,j,h;
String bb;
CellStyle style = wb.createCellStyle();
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);
j=0;
if(row==null)j=100;
if(j<50){
for(sx=1;sx<maxx+1;sx++){
cc = row.getCell(sx-1);
h=0;
if(cc==null)h=100;
if(h<50){
int type =cc.getCellType();
bb="";
if(type==1)bb=cc.getStringCellValue();
if(type==0)bb=""+cc.getNumericCellValue();
mat[s][sx]=bb;
}
}
}
}
} catch (Exception e) {e.printStackTrace();}
}
}
最終更新:2016年06月07日 20:11