設置固定值 worksheet.Columns[1].ColumnWidth = 15;
設置自動換行 worksheet.Columns.WrapText = true;
設置自動行高、列寬
xlApp.Columns.AutoFit();
xlApp.Rows.AutoFit();
對齊方式
worksheet.Columns.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft; // 對齊方式
或
worksheet.Columns[3].HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft; // 對齊方式
其它
•sheet.Range["A1", "F" + (c + 2)].Borders.LineStyle = 1; // 邊框粗細
•sheet.Range["A1", "F" + (c + 2)].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; // 對齊方式
•sheet.Range["A1", "F1"].MergeCells = true; // 合並單元格
•sheet.Range["A1", "F2"].Font.Bold = true; // 加粗
•sheet.Range["A1", "F1"].Font.Size = 13; // 字號
•sheet.Range["A1", "F" + (c + 2)].Font.Size = 11;
•sheet.Range["A1", "F" + (c + 2)].RowHeight = 21; // 行高
•sheet.Range["A1"].RowHeight = 35;
•sheet.Range["A1", "F1"].ColumnWidth = 17; // 列寬
•sheet.Range["B1"].ColumnWidth = 20;
•sheet.Range["A2", "F2"].Interior.Color = System.Drawing.ColorTranslator.ToOle(Color.FromArgb(197, 217, 241)); // 單元格背景顏色
