NPOI 合併單元格

需要用到的類:CellRangeAddress

CellRangeAddress類的構造方法

public CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol);

一共四個參數,分別是:待合併的開始行、結束行、開始列、結束列,參數均爲索引值,從0開始。

headerRow.CreateCell(0).SetCellValue("姓名");
headerRow.GetCell(0).CellStyle = headStyle;
sheet.AddMergedRegion(new CellRangeAddress(1, 1, 0, 1)); //合併
headerRow.CreateCell(2).SetCellValue("年齡");
headerRow.GetCell(2).CellStyle = headStyle;
sheet.AddMergedRegion(new CellRangeAddress(1, 1, 2, 3)); //合併

這裏寫圖片描述

發佈了24 篇原創文章 · 獲贊 6 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章