package x2;
import java.io.*;
import java.io.File;
public class pro {
int maxx,maxy;
String[][] mat=new String[3000][120];
String[] code=new String[2500];
String[] city=new String[2500];
String[] credit=new String[50];
int fastline,lastline;
int creditx;
public static void main(String[] args) {
pro te=new pro();
}
pro(){
File f=new File("data");
String[] ff=f.list();
int tr;
for(tr=0;tr<ff.length;tr++){
maxx=50;
maxy=2000;
readxls sub=new readxls();
sub.maxx=maxx;
sub.maxy=maxy;
sub.makedata("data/"+ff[tr],0);
mat=sub.mat;
int s,mm=0;
for(s=1;s<21;s++){
int h=0;
if(mat[s][1].indexOf("市")>-1)h=h+1;
if(mat[s][1].indexOf("区")>-1)h=h+1;
if(h==2)mm=s;
}
fastline=mm+5;
lastline=mm+1968;
for(s=fastline;s<lastline+1;s++){
code[s]=mat[s][1];
city[s]=mat[s][2];
}
creditx=0;
for(s=3;s<30;s++){
credit[s]=mat[mm][s].replace("\n","");
if(credit[s].length()>0)creditx=s;
}
writehtml("ren.html");
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=3;sx<creditx+1;sx++){
pw.print("<code>");
pw.print(code[s]);
pw.print("</code>");
pw.print("<city>");
pw.print(city[s]);
pw.print("</city>");
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("入出力エラーです。"); }
}
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.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][120];
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();}
}
}
最終更新:2017年02月23日 22:22