アットウィキロゴ

エクセル処理

package exl;
 
import java.io.*;
 
public class pro {
 
    int maxx=60;
    int maxy=300;
 
    String[][] mat=new String[500][100]; 
    String[] city=new String[500]; 
      String[] name=new String[500];
        String[] party=new String[500];
    int fastline,lastline;
    int creditx,credity;
 
    public static void main(String[] args) {
        pro te=new pro();
    }
 
    pro(){
 
        int tr;
 
    for(tr=1;tr<48;tr++){    
 
    readxls sub2=new readxls();
    sub2.maxx=maxx;
    sub2.maxy=maxy;
    sub2.makedata("data/"+tr+".xls",0);
    mat=sub2.mat;
 int s;
 
 fastline=11;
 lastline=0;
    for(s=1;s<maxy;s++){
    if(mat[s][1].length()>1)lastline=s;
    }
 
 
      for(s=fastline;s<lastline+1;s++){
    city[s]=mat[s][1];
 
    }
 
 
      creditx=2;
     for(s=1;s<60;s++){
    if(mat[9][s].length()>1)credity=s;
    }
 
    for(s=creditx;s<credity+1;s++){
    name[s]=mat[9][s];
    party[s]=mat[6][s];  
    }
 
 
    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=creditx;sx<credity+1;sx++){ 
pw.print("<city>"); 
pw.print(city[s]); 
pw.print("</city>"); 
pw.print("<name>"); 
pw.print(name[sx]); 
pw.print("</name>"); 
pw.print("<party>");
pw.print(party[sx]);
pw.print("</party>");  
pw.print("<value>");
pw.print(mat[s][sx]); 
pw.println("</value>");
}
}
 
 
System.out.println("ファイルに書きこみました。"); 
pw.close(); 
} catch(IOException ep){ System.out.println("入出力エラーです。"); } 
 
 
} 
 
 
}
 
 
package exl;
 
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][500]; 
int[][] color= new int[5000][500];
 
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,h;
      String bb;
 
 
      CellStyle style = wb.createCellStyle();
 
          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);
  h=0;
  if(cc==null)h=100;
  if(h<50){
  int type =cc.getCellType();
   bb="";
  if(type==1)bb=cc.getStringCellValue();
  if(type==0)bb=""+cc.getNumericCellValue();
 
  short n1=cc.getCellStyle().getFillBackgroundColor();
 
  color[s][sx]=(int)n1;
  mat[s][sx]=bb;
  }
  }
  }
  }
 
 
 
 
 
  } catch (Exception e) {e.printStackTrace();}
 
 
 
 
 
 
 
 }
}
 
最終更新:2016年08月19日 13:49