📄 estimatemaker.java
字号:
import jp.ne.so_net.ga2.no_ji.jcom.excel8.*;
import jp.ne.so_net.ga2.no_ji.jcom.*;
import java.io.File;
import java.util.Date;
/*
Excel梡儔僢僷傪巊偭偨丄JCom偺僒儞僾儖僾儘僌儔儉
*/
public class EstimateMaker {
public boolean print_enable = false; // 報嶞偡傞偐偳偆偐
// 愝掕崁栚
public String company = ""; // 夛幮柤
public String section1 = ""; // 強懏1
public String section2 = ""; // 強懏2
public String custmer = ""; // 屭媞柤
public String validperiod = ""; // 尒愊桳岠婜尷
public String createdate = ""; // 嶌惉擔
public String estimatedNo = ""; // 尒愊彂No.
public String charge = ""; // 扴摉幰
public String[] itemname = new String[15]; // 昳柤x15屄
public String[] itemtype = new String[15]; // 宆斣x15屄
public int[] itemprice = new int[15]; // 扨壙x15屄
public int[] itemcount = new int[15]; // 悢検x15屄
public String[] itemmemo = new String[15]; // 旛峫x15屄
public boolean makeEstimate(String fname) {
ReleaseManager rm = new ReleaseManager();
try {
System.out.println("EXCEL傪婲摦拞...");
// 偡偱偵棫偪忋偑偭偰偄傞偲丄怴偟偄僂傿儞僪僂偱奐偔丅
ExcelApplication excel = new ExcelApplication(rm);
excel.Visible(true);
ExcelWorkbooks xlBooks = excel.Workbooks();
ExcelWorkbook xlBook = xlBooks.Open(fname);
ExcelWorksheet xlSheet = excel.ActiveSheet();
ExcelRange xlRange = xlSheet.Cells();
// 愝掕崁栚傪僙儖偵戙擖
System.out.println("愝掕崁栚傪僙儖偵戙擖");
xlRange.Item(4,2).Value(company);
xlRange.Item(5,2).Value(section1);
xlRange.Item(6,2).Value(section2);
xlRange.Item(8,2).Value(custmer);
xlRange.Item(14,4).Value(validperiod);
xlRange.Item(3,8).Value(createdate);
xlRange.Item(5,8).Value(estimatedNo);
xlRange.Item(7,8).Value(charge);
for(int i=0; i<15; i++) {
xlRange.Item(22+i,3).Value(itemname[i]);
xlRange.Item(22+i,4).Value(itemtype[i]);
if(itemcount[i]!=0) {
xlRange.Item(22+i,5).Value(itemprice[i]);
xlRange.Item(22+i,6).Value(itemcount[i]);
}
else {
xlRange.Item(22+i,5).Value("");
xlRange.Item(22+i,6).Value("");
}
xlRange.Item(22+i,8).Value(itemmemo[i]);
}
// 僾儕儞僞偵弌椡偡傞応崌偼僐儊儞僩傪偼偢偟偰偔偩偝偄丅
// 僨僼僅儖僩偺僾儕儞僞偵弌椡偝傟傑偡丅
if(print_enable) {
System.out.println("僾儕儞僞偵報嶞偟傑偡丅");
xlSheet.PrintOut();
}
// 僼傽僀儖偵曐懚偡傞応崌偼僐儊儞僩傪奜偟偰偔偩偝偄丅
// 僨傿儗僋僩儕傪巜掕偟側偄応崌偼丄(My Documents)偵曐懚偝傟傑偡丅
System.out.println("僼傽僀儖偵曐懚偟傑偡丅");
xlBook.Save();
xlBook.Close(false,null,false);
excel.Quit();
}
catch(Exception e) {
e.printStackTrace();
return false; // 幐攕
}
finally { rm.release(); }
return true;
}
public static void main(String[] args) {
EstimateMaker est = new EstimateMaker();
est.company = "傑偭偔傠偦傆偲"; // 夛幮柤
est.section1 = "偁傉傝奐敪晹栧"; // 強懏1
est.section2 = "傑偔偣傞僌儖乕僾"; // 強懏2 偊偔偣傞偩傠両
est.custmer = "傃傞 偘偊偮 條"; // 屭媞柤
est.validperiod = "2000/09/05"; // 尒愊桳岠婜尷
est.createdate = "2000/08/06"; // 嶌惉擔
est.estimatedNo = "PL1234-56-7890"; // 尒愊彂No.
est.charge = "搉曈 媊懃"; // 扴摉幰
for(int i=0; i<15; i++) {
est.itemname[i] = "-"; // 昳柤x15
est.itemtype[i] = ""; // 宆斣x15
est.itemprice[i] = 0; // 扨壙x15
est.itemcount[i] = 0; // 悢検x15
est.itemmemo[i] = ""; // 旛峫x15
}
// 崁栚1
est.itemname[0] = "娭悢僣儕乕Ver14.40";
est.itemtype[0] = "FT-1440S";
est.itemprice[0] = 1500;
est.itemcount[0] = 1;
est.itemmemo[0] = "僜乕僗晅";
// 崁栚2
est.itemname[1] = "JCom 2.00";
est.itemtype[1] = "JC-200";
est.itemprice[1] = 800;
est.itemcount[1] = 4;
est.itemmemo[1] = "";
// 崁栚3
est.itemname[2] = "SYLBIS 兛斉";
est.itemtype[2] = "SY-1A";
est.itemprice[2] = 3000;
est.itemcount[2] = 1;
est.itemmemo[2] = "DirectX懳墳";
// 抣傪愝掕仌報嶞.
est.print_enable = false;
// 嶌嬈梡偺僼傽僀儖傪嶌惉丅尒愊彂No偲摨偠偵偡傞丅
try {
String workfile = ".\\"+est.estimatedNo+".xls";
System.out.println("僼傽僀儖傪僐僺乕 "+workfile);
FileCopy.copy(".\\estimate.xls", workfile);
// 尒愊彂傪嶌惉丅Excel偼撈帺偺娐嫬傪帩偮偺偱丄僼傽僀儖柤傪愨懳僷僗偵偟偰搉偡
System.out.println("尒愊彂嶌惉");
boolean rc = est.makeEstimate((new File(workfile)).getCanonicalPath());
if(rc)
System.out.println("惉岟偟傑偟偨");
else
System.out.println("幐攕偟傑偟偨(;_;)");
}
catch(Exception e) {
e.printStackTrace();
System.out.println("幐攕偟傑偟偨(T_T)");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -