根据index获取列编号,如传入1,得到A
public string Getzm(int Index)
{
var dividend = Index;
string columnName = string.Empty;
while (dividend > 0)
{
var modulo = (dividend - 1) % 26;
columnName = Convert.ToChar(65 + modulo) + columnName;
dividend = (dividend - modulo) / 26;
}
return columnName;
}
合并单元格
ExcelWorksheet ws
ws.Cells[$"{startName}:{endName}"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
ws.Cells[$"{startName}:{endName}"].Style.VerticalAlignment = ExcelVerticalAlignment.Center;
ws.Cells[$"{startName}:{endName}"].Merge = true;
注意,必须用ws.Cells[$"A1:C1"]这种方式而不是ws.Cells[1,1,1,3]这种,会报错
设置单元格格式
var cell = ws.Cells[$"{startName}:{endName}"]
cell.Style.Numberformat.Format = "yyyy-m-d";