相关问题
- NPOI - Writing to file corrupts .xlsx workbook
- C#. xlsx date cell import to DataTable by NPOI 2.0
- NPOI formats all cells the same way
- NPOI - Get excel row count to check if it is empty
- Custom color for ICellStyle FillForegroundColor th
相关文章
- npoi文件名含有减号时,无法读取文件
- Excel使用Aspose.Cells或者NPOI怎么插入两列(不是在末尾插入两列)
- MemoryStream seems be closed after NPOI workbook.w
- Convert xlsx file to xls using NPOI in c#
- How to use NPOI to read Excel spreadsheet that con
- NPOI SetCellValue method doesn't write data to
- Trying to edit cell value of existing Excel file u
- Edit existing Excel file C# npoi
//设置style
ICellStyle cellstyle = workbook.CreateCellStyle();
cellstyle.VerticalAlignment = VerticalAlignment.Center;
cellstyle.Alignment = HorizontalAlignment.Center;
//合并操作
sheet.AddMergedRegion(new CellRangeAddress(index["firstRow"], index["lastRow"], index["firstCol"], index["lastCol"]));//起始行,结束行,起始列,结束列
//设置合并后style
var cell = sheet.GetRow(index["firstRow"]).GetCell(index["firstCol"]);
cell.CellStyle = cellstyle;
合并0列的n--n+2行:
CellRangeAddress m_region = new CellRangeAddress(n,n+2, 0, 0); //合并0列的n--n+2行
sheet.AddMergedRegion(m_region);
IRow row = sheet.CreateRow(n);
ICell cell = row.CreateCell(0);
ICellStyle cellstyle = hssfworkbook.CreateCellStyle();//设置垂直居中格式
cellstyle.VerticalAlignment = VerticalAlignment.Center;//垂直居中
cell.CellStyle = cellstyle;
HSSFWorkbook book = new HSSFWorkbook();
ICellStyle cellStyle = book.CreateCellStyle();
//设置单元格的样式:水平对齐居中
cellStyle.VerticalAlignment = VerticalAlignment.Justify;//垂直对齐(默认应该为center,如果center无效则用justify)
cellStyle.Alignment = HorizontalAlignment.Center;//水平对齐
cell.CellStyle=cellstyle;
為右上角的那個单元格设个样式为居中对齐试试