アットウィキロゴ

poi2

package codex;
 
 
public class pro {
 
    String[] credit=new String[50];
    int creditnumber;
    String[] code=new String[50];
    String[] style=new String[50];
    int[] strlong=new int[50];
    String[][] v=new String[500][60]; 
    int datanumber;
 
    public static void main(String[] args) {
        pro t=new pro();
    }
 
 
 
    pro(){
 
 
 
 
 
 
 
 
 
datanumber=2;
creditnumber=2;
 
credit[1]="A";
credit[2]="B";
 
code[1]="4A";
code[2]="4B";
 
 
style[1]="INTEGER";
style[2]="VARCHAR";
 
strlong[1]=4;
strlong[2]=3;
 
int s,sx;
 
 
 
for(s=1;s<datanumber+1;s++){
 for(sx=1;sx<creditnumber+1;sx++){   
v[s][sx]="500";
 }}
 
 
 
 
pre sub=new pre();
sub.datanumber=datanumber;
sub.creditnumber=creditnumber;
sub.credit=credit;
sub.code=code;
sub.style=style;
sub.strlong=strlong;
sub.v=v;
sub.makedata("x.xls");
 
 
 
 
 
 
 
 
    }
 
 
 
 
 
 
 
}
 
 
 
 
 
package codex;
 
 
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;
import java.io.*;
 
public class pre {
 
    String[] credit=new String[50];
    int creditnumber;
    String[] code=new String[50];
    String[] style=new String[50];
    int[] strlong=new int[50];
    String[][] v=new String[500][60]; 
    int datanumber;
 
 
 
 
 
    void makedata(String file){
 
 
 
 
 
 
       Workbook wb = new HSSFWorkbook();
Sheet sh = wb.createSheet();
 
 
 
 
int s,sx;
Row[] row=new Row[datanumber+4];
 
for(s=0;s<datanumber+4;s++){
row[s] = sh.createRow(s);
    }   
 
Cell[][] cx=new Cell[datanumber+4][creditnumber];
 
for(s=0;s<datanumber+4;s++){
for(sx=0;sx<creditnumber;sx++){
cx[s][sx]= row[s].createCell(sx);
 }}
 
 
for(sx=0;sx<creditnumber;sx++){
cx[0][sx].setCellValue(credit[sx+1]);
cx[1][sx].setCellValue(code[sx+1]);
cx[2][sx].setCellValue(style[sx+1]);
cx[3][sx].setCellValue(strlong[sx+1]);
}
 
 
 
 
for(s=1;s<datanumber+1;s++){
    for(sx=1;sx<creditnumber+1;sx++){
    cx[s+3][sx-1].setCellValue(v[s][sx]);
    }}
 
    FileOutputStream out =null;
 
    try{
 
 
        out = new FileOutputStream(file);
 
       wb.write(out);
 
    }catch(IOException e){System.out.println(e.toString());}
 
 
 
 
 
 
    }
 
 
 
 
 
 
 
}
 
最終更新:2015年04月24日 01:35