NPOI匯出word,以及對table的一些設定

2022-03-07 20:27:41 字數 2684 閱讀 4381

參考**:

npoi版本:2.1.3.1

最終效果圖:

///匯出word培訓班自然情況表

#region 培訓班自然情況表

25 xwpfdocument doc = new xwpfdocument();//

建立word文件

26 memorystream ms = new memorystream();//

建立流27

28 xwpfparagraph p0 = doc.createparagraph();//

建立段落

29 p0.alignment = paragraphalignment.center;//

居中顯示

30 xwpfrun r0 =p0.createrun();

31//

設定字型

32 r0.fontfamily = "宋體"

;33//設定字型大小

34 r0.fontsize = 18;35

//字型是否加粗,這裡加粗了

36 r0.setbold(true

);37 r0.settext("

培訓班自然情況表

");//

寫入文字

3839 xwpfparagraph p1 =doc.createparagraph();

40 p1.alignment =paragraphalignment.left;

41 xwpfrun r1 =p1.createrun();

42 r1.settext("

培訓機構:石家莊職工培訓基地");

4344 xwpftable table = doc.createtable(1, 4);//

建立table

45 table.removerow(0);//

去掉第一行空白的

46 table.setcolumnwidth(0, 6 * 256

);//設定列的寬度

47 table.setcolumnwidth(1, 10 * 256

);48 table.setcolumnwidth(2, 6 * 256

);49 table.setcolumnwidth(3, 10 * 256

);50 ct_tbl m_cttbl = doc.document.body.gettblarray()[0];//

獲得文件第一張表

51 m_cttbl.addnewtblpr().jc = new

ct_jc();

52 m_cttbl.addnewtblpr().jc.val = st_jc.center;//

表在頁面水平居中

5354

foreach (datarow r in

dt.rows)

55168

#endregion

169170

//寫入到客戶端

171doc.write(ms);

172//

173 response.addheader("

content-disposition

", string.format("

attachment; filename=.doc

", "

培訓班自然情況表

" + system.datetime.now.tostring("

yyyymmddhhmmssfff

")));

174 response.charset = "

utf-8";

175 response.contentencoding = system.text.encoding.getencoding("

utf-8");

176//

177 response.contenttype = "";

178//

把檔案流傳送到客戶端

179response.binarywrite(ms.toarray());

180 doc = null

;181

ms.close();

182ms.dispose();

183 }

fastText學習以及對embedding的理解

部落格 fasttext原理及實踐 wordembedding系列 三 fasttext enriching word vectors with subword information bag of tricks for efficient text classification embedding...

NPOI對excel檔案的匯入匯出

現理解 將乙個excel檔案 工作簿 iworkbook 看做是乙個你要操作的物件,每個工作簿包含多個工作表 isheet 物件,每個工作表中又包含多個行物件 irow 每行又包含多個單元格 icell 物件.單元格裡儲存相應資料 下面幫助更直觀的展示 iworkbook isheet irow i...

putchar與getchar以及對緩衝區的理解

getchar 由巨集實現 define getchar getc stdin getchar有乙個int型的返回值.當程式呼叫getchar時.程式就等著使用者按鍵.使用者輸入的 字元被存放在鍵盤緩衝區中 直到使用者按回車為止 回車字元也放在緩衝區中 當使用者鍵入回車之後,getchar才開始從s...