POI 單元格格式化 資料格式化

2021-09-01 01:26:08 字數 924 閱讀 2632

hssfcellstyle cellpercentstyle = workbook.createcellstyle();   

cellpercentstyle.setdataformat((short)10);//百分數

一、第一種方式

//poi 自定義保留一位小數格式

hssfcellstyle celldigitstyle = workbook.createcellstyle();

celldigitstyle.setdataformat(workbook.createdataformat().getformat("0.0"));

// 也可以自定義成其它格式,5格式化成05

hssfcellstyle celldigitstyle = workbook.createcellstyle();

celldigitstyle.setdataformat(workbook.createdataformat().getformat("00"));

二、第二種方式

hssfcellstyle celldigitstyle2 = workbook.createcellstyle();

celldigitstyle2.setdataformat(hssfdataformat.getbuiltinformat("0.00"));//兩位小數

celldigitstyle2.setdataformat((short) 2); //作用同上

注:第二種不是自定義,如果 getbuiltinformat 返回不了引數,格式化就會失效。

例如hssfdataformat.getbuiltinformat("00")只會返回-1,這樣格式化就會失效。

所以要實現excel-> format cell-> custom,暫時只知道用第一種方式。

資料格式化

一維資料,二維資料,多維資料 就是典型的多維資料 高維資料 資料儲存 資料表示 資料操作 列表型別可以表達一維有序資料 for迴圈可以遍歷資料,進而對每個資料進行處理 如果資料間無序,可以使用集合型別 集合型別可以表達一維無序資料 for迴圈可以遍歷資料,進而對每個資料進行處理 儲存方式一 空格分隔...

Eval 中資料格式化或格式化資料

eval schoolend dbnull.value convert.todatetime eval schoolend tostring yyyy mm dd 不帶null的 datetime eval se start date tostring yyyy mm dd eval beginda...

Jquery資料格式化

資料格式化 千分號 方法1 function tothousands num g,1,方法2 千分號 before 14612741 after 14,612,741 param data returns function formattmpl data while reg.test num els...