動態生成excel

2021-09-21 06:01:52 字數 4771 閱讀 7840

}//20gp的合併運費,補錄費用,箱號

iteratorit = list.iterator();

//20gp箱子數量

int twetygp = 0;

//臨時箱號

string tempcontainerno="";

//臨時運費

bigdecimal yf = new bigdecimal(0);

//需要刪除箱子的臨時id

string tempid = "";

while(it.hasnext())else

}//新的不包含舊的費用項

if (!flag)

}accountcontainer.setadditionalcostlist(additionalcostlistnow);

twetygp=0;

}}else

}workbook = new hssfworkbook();

cellrangeaddress callrangeaddress = new cellrangeaddress(0,0,0,7+titlelist.size());//起始行,結束行,起始列,結束列

//左對齊,無邊框

hssfcellstyle headstyle = createcellstyle(workbook,"楷體",(short)12,true,false,true,"",false);

hssfcellstyle erstyle = createcellstyle(workbook,"楷體",(short)16,true,true,false,"",false);

hssfcellstyle colstyle = createcellstyle(workbook,"宋體",(short)11,true,true,false,"",true);

//2.建立工作表

hssfsheet sheet = workbook.createsheet("sheet1");

//列印方向,true:橫向,false:縱向

sheet.getprintsetup().setlandscape(true);

//使得乙個sheet適合一頁 

sheet.setautobreaks(true); 

載入合併單元格物件

sheet.addmergedregion(callrangeaddress);

//設定預設列寬

sheet.setdefaultcolumnwidth(15);

//3.建立行

建立頭標題行;並且設定頭標題

hssfrow rower = sheet.createrow(0);

hssfcell celler = rower.createcell(0);

//載入單元格樣式

celler.setcellstyle(erstyle);

celler.setcellvalue(dateutils.formatdate(receivable.gettrain().getdeparturedate(),"yyyy年mm月dd日") +"  " + "中亞班列" + "  "+"阿拉山口對賬單");

建立列標題;並且設定列標題

hssfrow row2 = sheet.createrow(1);

row2.setheightinpoints((short) 30);

hssfcell cellrow =row2.createcell(0);

cellrow.setcellstyle(colstyle);

cellrow.setcellvalue("序號");

hssfcell cellrow1 =row2.createcell(1);

cellrow1.setcellstyle(colstyle);

cellrow1.setcellvalue("客戶");

hssfcell cellrow2=row2.createcell(2);

cellrow2.setcellstyle(colstyle);

cellrow2.setcellvalue("箱號");

hssfcell cellrow3=row2.createcell(3);

cellrow3.setcellstyle(colstyle);

cellrow3.setcellvalue("箱型");

hssfcell cellrow4=row2.createcell(4);

cellrow4.setcellstyle(colstyle);

cellrow4.setcellvalue("品名");

hssfcell cellrow5=row2.createcell(5);

cellrow5.setcellstyle(colstyle);

cellrow5.setcellvalue("口岸");

hssfcell cellrow6=row2.createcell(6);

cellrow6.setcellstyle(colstyle);

cellrow6.setcellvalue("報關");

hssfcell cellrow7 =row2.createcell(7);

cellrow7.setcellstyle(colstyle);

cellrow7.setcellvalue("出口國家");

for(int i=0;i//根據titlelist合併單元格

cellrangeaddress callrangetitle10 = new cellrangeaddress(3+list.size(),3+list.size(),8,titlelist.size()-1+8);

sheet.addmergedregion(callrangetitle10);

hssfrow createrow=null;

for(int i=0;ifor(int j=0;jhssfrow rows = sheet.createrow(list.size()+2);

rows.setheightinpoints((short)20);

hssfcell cellrows=rows.createcell(7);

cellrows.setcellstyle(colstyle);

cellrows.setcellvalue("小計:");

char begin_letter='h';

for(int k=0;khssfrow rows2 = sheet.createrow(list.size()+3);

rows2.setheightinpoints((short)20);

hssfcell cellrows2=rows2.createcell(7);

cellrows2.setcellstyle(colstyle);

cellrows2.setcellvalue("合計:");

hssfcell cellrows8=rows2.createcell(8);

colstyle.setdataformat(hssfdataformat.getbuiltinformat("0.00"));

cellrows8.setcellstyle(colstyle);

cellrows8.setcelltype(hssfcell.cell_type_formula);

for (int j = 0; j < titlelist.size()-1; j++)

char begin_letter1='h';

string baseprice="";

for(int k=0;khssfrow rows3 = sheet.createrow(list.size()+6);

rows3.setheightinpoints((short)20);

hssfcell cellrows3=rows3.createcell(0);

cellrows3.setcellstyle(headstyle);

cellrows3.setcellvalue("製表人");

hssfcell cellrows31=rows3.createcell(6);

cellrows31.setcellstyle(headstyle);

cellrows31.setcellvalue("訂艙確認人");

hssfrow rows4 = sheet.createrow(list.size()+10);

rows4.setheightinpoints((short)20);

hssfcell cellrows4=rows4.createcell(0);

cellrows4.setcellstyle(headstyle);

cellrows4.setcellvalue("現場操作");

hssfcell cellrows41=rows4.createcell(6);

cellrows41.setcellstyle(headstyle);

cellrows41.setcellvalue("企業蓋章");

hssfrow rows5 = sheet.createrow(list.size()+14);

rows5.setheightinpoints((short)20);

hssfcell cellrows5=rows5.createcell(0);

cellrows5.setcellstyle(headstyle);

cellrows5.setcellvalue("境外費用確認人");

Excel動態生成JSON

在最近的乙個專案中,有大量的資料來源來至excel,轉成json供前台使用。excel資料是人工錄入的,難免會有錯誤,所以中間會有邏輯檢查。在c 中 讀取excel 的方式有很多,網上一搜一大堆,這裡我也貼出乙個excelhelper,提供根據excel檔案獲取所有sheet名稱和獲取sheet內容...

asp動態生成excel檔案

實現將動態生成excel 並將內容一併寫入 code createby guofeng 生成在交費記錄的excel if request act then else 主程式開始 code createby guofeng dim sql,filename,fs,myfile,x,link set f...

Excel動態報表

老闆總是公司最忙的乙個人。所以給老闆演示的報表一定要簡明扼要,突出重點。你的報表是這樣的嗎?excel高手的報表卻是這樣的 用圖表動態展示每個月的銷售完成情況 沒有對比沒有傷害,即好看又直觀,完勝第一種純 式報表。看上去很複雜,其實有乙個excel功能就可以輕鬆搞定,它就是 資料透視表 下面就分享一...