我发下主要代码吧,涉及到静态变量的。主要是想把文件路径filename和获取的source的名字改成非静态的
public class ProcessRow {
static Properties source;
static {
try {
source = new Properties();
FileInputStream fis = new FileInputStream(new File(
inputPropertieName()));
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
source.load(isr);
fis.close();
} catch (Exception e) {
// throw new ExceptionInInitializerError(e);
}
}
public static String filterAlphabet(String alph) {
alph = alph.replaceAll("[^(A-Z)]", "");
return alph;
}
public String Pname() {
String hai = UseProcess.fileName;
String a = filterAlphabet(hai);
String b = hai.substring(hai.indexOf(a), hai.indexOf(a) + 6);
return b;
}
public static String inputPropertieName() {
/*
* System.out.println("请输入配置文件名称:"); Scanner a = new Scanner(System.in);
* String propertieName = a.next();
*/
// a.close();
ProcessRow a = new ProcessRow();
String propertieName = a.Pname();
return propertieName;
}
// 判断方法1,2
public boolean panduan1(XSSFRow from) {
return from.getCell(8).toString().trim()
.equals(source.getProperty("I列值1"))
&& (from.getCell(2).toString().trim().equals(source
.getProperty("C列值1")));// 1 I列值为“I列值1” 且C列值为“C列值1”
}
public boolean panduan2(XSSFRow from) {
return from.getCell(8).toString().trim()
.equals(source.getProperty("I列值2"))
&& (from.getCell(2).toString().trim().equals(source
.getProperty("C列值2")));// 2 I列值为“I列值2” 且C列值为“C列值2”
}
.........
Output类
public class Output {
static Date d = new Date();
static DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
final static String fileName = df.format(d);
static String b = null;
static String c = ProcessRow.source.getProperty("输出路径")+fileName + "_main" + ".xlsx";
public static FileOutputStream init() {
FileOutputStream s = null;
try {
s = new FileOutputStream(c);
} catch (FileNotFoundException e) {
}
return s;
}
public static XSSFWorkbook getWorkbook() throws IOException{
FileInputStream fis = new FileInputStream(c);
XSSFWorkbook wb = new XSSFWorkbook( fis );
return wb;
}
}
UseProcess类
public class UseProcess {
static String fileName=UseProcess.fileName();
static XSSFSheet readsheet;
static {
try {
readsheet = readWorkbook();
} catch (Exception e) {
// TODO: handle exception
}
}
static XSSFWorkbook sc = null;
static XSSFWorkbook sr = null;
public static String fileName() {
System.out.println("请输入文件路径(将文件拖入程序):");
Scanner a = new Scanner(System.in);
String fileName = a.next();
//a.close();
return fileName;
}
ArrayList date1 = new ArrayList();
ArrayList value1 = new ArrayList();
ArrayList date2 = new ArrayList();
ArrayList value2 = new ArrayList();
int lastnum = getNum(fileName);
int i = Integer.parseInt(ProcessRow.source.getProperty("表单数据从第几行开始")) - 1;
static int j = 1;
public static int getNum(String Filename) {
try {
InputStream myxls;
myxls = new FileInputStream(Filename);
sr = new XSSFWorkbook(myxls);
XSSFSheet sheet = sr.getSheetAt(0);// 第一个工作表
return sheet.getLastRowNum();// 获取第一个工作表的行数
} catch (IOException e) {
return 0;
}
}
主函数
public class TestMain {
public static void test() throws IOException, NumberFormatException, ParseException{
UseProcess.createWorkbook();
UseProcess n = new UseProcess();
for (int i = 1; i <= Integer.parseInt(ProcessRow.source
.getProperty("condition-process的个数")); i++) {
n.UseProcess1(String.valueOf(i));
}
n.UseProcessNull();
System.out.println("输入完毕");
}
public static void main(String[] args) throws NumberFormatException, IOException, ParseException {
TestMain.test();
}