package viyu;
import java.io.*;
public class pro {
String[] name=new String[1000];
int number,s;
int fastline,lastline;
String[][] mat=new String[500][500];
String[] credit=new String[500];
String[] city=new String[500];
int maxx=100;
int maxy=100;
public static void main(String[] args) {
pro te=new pro();
}
pro(){
int tr;
for(tr=19;tr<28;tr++){
namex sub=new namex();
sub.makedata("data/toshi"+tr+".xls");
name=sub.name;
number=sub.number;
int point=0;
for(s=0;s<number;s++){
int h=0;
if(name[s].indexOf("市")>-1)h=h+1;
if(name[s].indexOf("勢")>-1)h=h+1;
if(h==2)point=s;
}
readxls sub2=new readxls();
sub2.maxx=maxx;
sub2.maxy=maxy;
sub2.makedata("data/toshi"+tr+".xls",point);
mat=sub2.mat;
writehtml("ren.html");
fastline=0;
for(s=1;s<maxy;s++){
if(mat[s][1].indexOf("函")>-1)fastline=s;
}
for(s=1;s<maxy;s++){
if(mat[s][1].indexOf("市")>-1)lastline=s;
}
System.out.println(fastline);
System.out.println(lastline);
int sx;
for(s=fastline;s<lastline+1;s++){
city[s]=mat[s][1];
}
for(sx=2;sx<maxx;sx++){
String str="";
for(s=1;s<fastline-1;s++){
str=str+mat[s][sx];
}
str=str.replace("\n","");
if(str.indexOf("市勢")>-1)str="";
credit[sx]=str;
System.out.println(sx+","+str);
}
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=2;sx<maxx;sx++){
if(credit[sx].length()>2){
pw.print("<city>");
pw.print(city[s]);
pw.print("</city>");
pw.print("<credit>");
pw.print(credit[sx]);
pw.print("</credit>");
pw.print("<code>");
pw.print(sx);
pw.print("</code>");
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 viyu;
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 viyu;
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();}
}
}
最終更新:2017年03月11日 09:03