package xlx;
import java.io.*;
public class pro {
int maxx,maxy;
String[][] mat=new String[60][200];
int tr;
int[] year=new int[50];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
year[0]=1970;
int s;
for(s=1;s<50;s++){
year[s]=1972+s;
}
maxx=130;
maxy=50;
for(tr=0;tr<41;tr++){
readxls sub=new readxls();
sub.maxx=maxx;
sub.maxy=maxy;
sub.makedata("data2.xls",tr);
mat=sub.mat;
writefile("data/"+tr+".txt");
}
}
void writefile(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
int s,sx;
for(s=2;s<41;s++){
for(sx=2;sx<110;sx++){
pw.print("<year>");
pw.print(year[tr]);
pw.print("</year>");
pw.print("<mono>");
pw.print(s-1);
pw.print("</mono>");
pw.print("<bus>");
pw.print(sx-1);
pw.print("</bus>");
pw.print("<value>");
pw.print(mat[s][sx]);
pw.println("</value>");
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package xlx;
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();}
}
}
最終更新:2016年06月16日 01:55