我正在尝试将用作标题的单元格的值居中。这是我目前用来格式化这些单元格的代码。我正在使用带有 C# 的 Excel 互操作。如何在此单元格范围内将值居中。
public void createHeaders(int row, int col, string htext, string cell1,
string cell2, int mergeColumns, string b, bool font, int size, string
fcolor)
{
worksheet.Cells[row, col] = htext;
workSheet_range = worksheet.get_Range(cell1, cell2);
workSheet_range.Merge(mergeColumns);
switch (b)
{
case "BLUE":
workSheet_range.Interior.Color = System.Drawing.Color.Red.ToArgb();
break;
case "GAINSBORO":
workSheet_range.Interior.Color =
System.Drawing.Color.Gainsboro.ToArgb();
break;
//case "Turquoise":
// workSheet_range.Interior.Color =
//System.Drawing.Color.Turquoise.ToArgb();
//break;
case "PeachPuff":
workSheet_range.Interior.Color =
System.Drawing.Color.PeachPuff.ToArgb();
break;
default:
// workSheet_range.Interior.Color = System.Drawing.Color..ToArgb();
break;
}
//workSheet_range.Borders.Color = System.Drawing.Color.Black.ToArgb();
//workSheet_range.Borders = null;
workSheet_range.Font.Bold = font;
workSheet_range.ColumnWidth = size;
workSheet_range.Font.Color = System.Drawing.Color.FloralWhite.ToArgb();
}