package read;
import java.io.*;
public class pro {
String[][] mat=new String[500][500];
int maxx,maxy;
int lastline,fastline;
String[] credit=new String[500];
String[] age=new String[500];
String[] school=new String[500];
String[] sex=new String[500];
String[] subx=new String[500];
String[] size=new String[500];
String bu;
public static void main(String[] args) {
pro t=new pro();
}
pro(){
maxx=200;
maxy=400;
int number;
String[] name=new String[60];
namex sub=new namex();
sub.makedata("data.xls");
name=sub.name;
number=sub.number;
int tr;
for(tr=0;tr<number;tr++){
readxls sub2=new readxls();
sub2.maxx=maxx;
sub2.maxy=maxy;
sub2.makedata("data.xls",tr);
mat=sub2.mat;
int s,sx;
bu=name[tr];
fastline=14;
for(s=fastline;s<maxy;s++){
if(mat[s][9].length()>0)lastline=s;
}
for(s=fastline;s<lastline+1;s++){
credit[s]=mat[s][9].replace(" ","");
credit[s]=credit[s].replace(" ","");
}
for(s=fastline;s<lastline+1;s++){
age[s]="合計";
if(credit[s].indexOf("歳")>-1)age[s]=credit[s];
}
for(s=fastline;s<lastline+1;s++){
school[s]=school[s-1];
if(age[s].indexOf("合計")>-1)school[s]=credit[s];
school[s]=school[s].replace("\n","");
}
sex[fastline-1]="男女";
for(s=fastline;s<lastline+1;s++){
sex[s]=sex[s-1];
if(school[s].indexOf("男学")>-1)sex[s]="男";
if(school[s].indexOf("女学")>-1)sex[s]="女";
}
subx[1]="年齢";
subx[2]="勤続年数";
subx[3]="所定内実労働時間数";
subx[4]="超過実労働時間数";
subx[5]="きまって支給する現金給与額";
subx[6]="所定内給与額";
subx[7]="年間賞与その他特別給与額";
subx[8]="労働者数";
size[1]="合計";
size[2]="千人以上";
size[3]="100~999人";
size[4]="10~99人";
writehtml("ren.html");
writexml("data/"+tr+".txt");
}
}
void writexml(String file){
int s,sx,tx,m;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=fastline;s<lastline;s++){
for(sx=1;sx<5;sx++){
for(tx=1;tx<9;tx++){
pw.print("<bus>");
pw.print(bu);
pw.print("</bus>");
pw.print("<sex>");
pw.print(sex[s]);
pw.print("</sex>");
pw.print("<age>");
pw.print(age[s]);
pw.print("</age>");
pw.print("<school>");
pw.print(school[s]);
pw.print("</school>");
pw.print("<size>");
pw.print(size[sx]);
pw.print("</size>");
pw.print("<credit>");
pw.print(subx[tx]);
pw.print("</credit>");
pw.print("<value>");
m=8*sx+tx+1;
pw.print(mat[s][m]);
pw.println("</value>");
}
}}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void writehtml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println("<html>");
pw.println("<head>");
pw.println("<meta charset=\"UTF-8\">");
pw.println("</head>");
pw.println("<body>");
pw.print("<table rules=\"all\">");
pw.print("<tr>");
pw.print("<td>");
pw.print("");
pw.print("</td>");
for(sx=1;sx<maxx+1;sx++){
pw.print("<th>");
pw.print(sx);
pw.print("</th>");
}
pw.println("</tr>");
for(s=1;s<maxy+1;s++){
pw.print("<tr>");
pw.print("<th>");
pw.print(s);
pw.print("</th>");
for(sx=1;sx<maxx+1;sx++){
pw.print("<td>");
pw.print(mat[s][sx]);
pw.print("</td>");
}
pw.println("</tr>");
}
pw.println("</table>");
pw.println("</body>");
pw.println("</html>");
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
}
package read;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
public class namex{
String[] name=new String[1000];
int number;
void makedata(String file){
try{
int s;
FileInputStream is = new FileInputStream(file);
Workbook wb = new HSSFWorkbook(is);
number=wb.getNumberOfSheets();
for(s=0;s<number;s++){
name[s]=wb.getSheetName(s);
}
} catch (Exception e) {e.printStackTrace();}
}
}
package read;
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[500][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();}
}
}
最終更新:2017年02月22日 23:28