package x2;
import java.io.*;
public class pro {
String[][] mat=new String[500][500];
String[][] data=new String[500][10];
int[] year=new int[500];
int[] month=new int[500];
String[] credit=new String[500];
int[] code_credit=new int[500];
int maxx;
int maxy;
int fastline=0;
int lastline=0;
int indexline=0;
int n,k;
public static void main(String[] args) {
pro te=new pro();
}
pro(){
int tr=0;
maxx=20;
maxy=100;
for(k=1;k<11;k++){
for(n=0;n<13;n++){
if(k<4){
readxls sub2=new readxls();
sub2.maxx=maxx;
sub2.maxy=maxy;
sub2.makedata("data/"+k+"(1).xls",n);
mat=sub2.mat;
}
if(k>3){
readxls2 sub21=new readxls2();
sub21.maxx=maxx;
sub21.maxy=maxy;
sub21.makedata("data/"+k+"(1).xls",n);
mat=sub21.mat;
}
writehtml("ren.html");
int s,sx;
for(s=1;s<20;s++){
for(sx=1;sx<5;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)fastline=s;
if(h==2)indexline=sx;
}
}
lastline=fastline+46;
System.out.println(fastline);
System.out.println(lastline);
tr=tr+1;
writexml("gdata/"+tr+".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<13;sx++){
pw.print("<year>");
pw.print(28-k);
pw.print("</year>");
pw.print("<age>");
pw.print(n+5);
pw.print("</age>");
pw.print("<pref>");
pw.print(mat[s][indexline]);
pw.print("</pref>");
pw.print("<code_credit>");
pw.print(sx);
pw.print("</code_credit>");
pw.print("<value>");
pw.print(mat[s][sx+indexline]);
pw.println("</value>");
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
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("入出力エラーです。"); }
}
}
package x2;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class readxls2 {
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();
short n1=cc.getCellStyle().getFillBackgroundColor();
color[s][sx]=(int)n1;
mat[s][sx]=bb;
}
}
}
}
} catch (Exception e) {e.printStackTrace();}
}
}
package x2;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import java.io.*;
public class readxls {
String[][] mat=new String[500][500];
Cell cc;
int maxx,maxy;
void makedata(String file,int num){
try{
FileInputStream is = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(is);
Sheet sh = wb.getSheetAt(num);
int s,sx,j,h;
String bb;
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年07月19日 03:57