package delta;
import java.io.*;
public class pro {
int s,sx;
int maxx,maxy;
String[][] mat=new String[5000][5000];
String str;
String[] credit=new String[500];
String[][] count=new String[500][50];
String[] index=new String[500];
String[] subindex=new String[500];
int lastline;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
readxls sub=new readxls();
sub.maxx=50;
sub.maxy=220;
sub.makedata("data.xls",0);
mat=sub.mat;
lastline=194;
for(sx=5;sx<27;sx++){
str=mat[5][sx]+mat[6][sx]+mat[7][sx];
credit[sx]=str.replace("\n","");
}
for(s=8;s<lastline+1;s++){
for(sx=5;sx<27;sx++){
count[s][sx]=mat[s][sx];
}
}
for(s=8;s<lastline+1;s++){
str=mat[s][3];
if(str.length()<1)str=index[s-1];
index[s]=str.replace("年", "");;
subindex[s]=mat[s][4].replace("月", "");
}
writex("ren.txt");
}
void writex(String file){
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=8;s<lastline+1;s++){
for(sx=5;sx<27;sx++){
pw.print("<year>");
pw.print(index[s]);
pw.print("</year>");
pw.print("<month>");
pw.print(subindex[s]);
pw.print("</month>");
pw.print("<credit>");
pw.print(credit[sx]);
pw.print("</credit>");
pw.print("<code_credit>");
pw.print(sx-4);
pw.print("</code_credit>");
pw.print("<value>");
pw.print(count[s][sx]);
pw.println("</value>");
}
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package delta;
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();}
}
}
最終更新:2015年08月30日 07:05