package test;
import java.io.*;
public class pro {
int maxx,maxy;
String[][] mat=new String[500][500];
int fastline,lastline;
int creditline;
int tr;
String[][] v=new String[500][500];
public static void main(String[] args) {
pro test=new pro();
}
pro(){
fastline=32;
lastline=56;
creditline=24;
for(tr=1;tr<48;tr++){
String file;
maxx=100;
maxy=100;
file="data/"+tr+"m_q.xlsx";
if(tr<10)file="data/0"+tr+"m_q.xlsx";
readxslx sub=new readxslx();
sub.maxx=100;
sub.maxy=100;
sub.makedata(file,4);
mat=sub.mat;
writehtml("ren.html");
int s;
for(s=fastline;s<lastline+1;s++){
v[tr][s]=mat[s][creditline];
}
}
writexml("ren.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<48;s++){
for(sx=fastline;sx<lastline+1;sx++){
pw.print("<pref>");
pw.print(s);
pw.print("</pref>");
pw.print("<credit>");
pw.print(sx-fastline+1);
pw.print("</credit>");
pw.print("<value>");
pw.print(v[s][sx]);
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 test;
import org.apache.poi.xssf.usermodel.*;
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 readxslx{
String[][] mat=new String[500][500];
Cell cc;
int maxx,maxy;
void makedata(String file,int number){
try{
FileInputStream is = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(is);
Sheet sh = wb.getSheetAt(number);
int s,sx,j,h;
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);
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();
mat[s][sx]=bb;
}
}
}
}
} catch (Exception e) {e.printStackTrace();}
}
}
最終更新:2016年06月05日 16:04