EPPlus合并单元格和自动样式

ws.Cells[1, 1].Value = "姓名";
            ws.Cells[1, 1, 2, 1].Merge = true;
            ws.Cells[1, 2].Value = "专业";
            ws.Cells[1, 2, 2, 2].Merge = true;
            ws.Cells[1, 3].Value = "类别";
            ws.Cells[1, 3, 1, 2 + titles.Count].Merge = true;
            for (int i = 3; i < 3 + titles.Count; i++)
            {
                ws.Cells[2, i].Value = titles[i - 3];
            }

            var fromCol = 2 + titles.Count + 1;
            ws.Cells[1, fromCol].Value = "总计";
            ws.Cells[1, fromCol, 2, fromCol].Merge = true;

            var row = 3;
            foreach (var item in re.Items)
            {
                ws.Cells[row, 1].Value = item.Name;
                ws.Cells[row, 2].Value = item.Major;

                for (var i = 3; i < 3 + item.RecordReports.Count; i++)
                    ws.Cells[row, i].Value = item.RecordReports[i - 3].Value;

                ws.Cells[row, 3 + item.RecordReports.Count].Value = item.SumValue;

                row++;
            }
            ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;//水平居中
            ws.Cells.Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中
            ws.Cells.AutoFitColumns();
            ws.Cells.Style.WrapText = true;//自动换行

你可能感兴趣的:(EPPlus合并单元格和自动样式)