
XWPFTableRow MyRow = table.GetRow(0);//獲取第一行
XWPFTableCell cell = MyRow.GetCell(0);//獲取一個單元格,創建單元格時就創建了一個CT_P
CT_Tc cttc = cell.GetCTTc();
CT_TcPr ctPr = cttc.AddNewTcPr();
CT_Row m_NewRow = new CT_Row();
MyRow = new XWPFTableRow(m_NewRow, table);
table.AddRow(MyRow); //必須要!!!
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cttc = cell.GetCTTc();
ctPr = cttc.AddNewTcPr();
ctPr.AddNewVMerge().val = ST_Merge.restart;//合并行
ctPr.AddNewVAlign().val = ST_VerticalJc.center;//垂直
table.RemoveRow(0);
m_NewRow = new CT_Row();
MyRow = new XWPFTableRow(m_NewRow, table);
table.AddRow(MyRow);
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cttc = cell.GetCTTc();
ctPr = cttc.AddNewTcPr();
ctPr.AddNewVMerge().val = ST_Merge.@continue;//合并行
m_NewRow = new CT_Row();
MyRow = new XWPFTableRow(m_NewRow, table);
table.AddRow(MyRow);
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cell = MyRow.CreateCell();
cttc = cell.GetCTTc();
ctPr = cttc.AddNewTcPr();
ctPr.AddNewVMerge().val = ST_Merge.@continue;//合并行
uj5u.com熱心網友回復:
用EXCEL模板填充的方式,你這樣的硬編碼作業量太大了,而且意義不大。建議先讀取EXCEL,將變數讀取出來,替換后重新保存。
EXCEL模板可以由客戶自行合并,增加標題等資訊。
我們要做的是定義變數,比如雙表的單頭欄位$$開頭,重復的單身用$開頭。
uj5u.com熱心網友回復:
你好,NPOI 匯出word 讓第一行單元格合并 如何實作??轉載請註明出處,本文鏈接:https://www.uj5u.com/net/85074.html
標籤:C#
上一篇:ASP.NET MVC API以及.Core API進行安全攔截和API請求頻率控制
下一篇:C#繪制Voronoi圖
