package xls;
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[5000][5000];
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,hh;
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);
hh=0;
if(cc==null)hh=100;
if(hh<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();}
}
}
package xls;
import java.io.*;
public class pro {
int maxx=20;
int maxy=4000;
String[][] mat=new String[3000][50];
int lastline;
int fastline;
String[] subdata=new String[3000];
int number;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
readxls sub2=new readxls();
sub2.maxx=maxx;
sub2.maxy=maxy;
sub2.makedata("data.xls",0);
mat=sub2.mat;
int s;
fastline=3;
for(s=1;s<maxy;s++){
if(mat[s][1].length()>0)lastline=s;
}
int sx=0;
for(s=fastline;s<lastline+1;s++){
if(mat[s][5].indexOf("市町村民")>-1) {
sx=sx+1;
String c=mat[s][2].substring(0,5);
subdata[sx]=c+","+mat[s][4]+","+mat[s][6]+","+mat[s][7];
subdata[sx]=subdata[sx]+","+mat[s][8]+","+mat[s][9]+","+mat[s][10];
subdata[sx]=subdata[sx]+","+mat[s][11]+","+mat[s][12];
System.out.println(subdata[sx]);
}
}
number=sx;
writexml("ren.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.println(subdata[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
最終更新:2016年09月17日 16:53