全表自动列宽
mysheet.Cells.Select();
mysheet.Cells.Columns.AutoFit();
合并
myRange.Merge(Missing.Value);
粗体设置
myRange.Font.Bold = true;
字体大小设置
myRange.Font.Size = 12;
水平对齐设置
myRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
垂直对齐设置
myRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
公式设置
myRange.FormulaR1C1 =
列宽设置
myRange.ColumnWidth =
行高
myRange.RowHeight =
格式
myrange.NumberFormatLocal="@";
添加行
((Excel.Range)mysheet.Cells[15,3]).EntireRow.Insert(0);
设置第10行为红色
mysheet.get_Range((Excel.Range)mysheet.Cells[10,1],(Excel.Range)mysheet.Cells[10,200]).Select();
mysheet.get_Range((Excel.Range)mysheet.Cells[10,1],(Excel.Range)mysheet.Cells[10,200]).Interior.ColorIndex=3;
单元格自动换行
myrange.WrapText = true;
单元格行高自动调整
myrange.EntireRow.AutoFit();
排序
private void SortNamedRange()
{
// Set some data in a range of cells.
this.Range["A1", missing].Value2 = 30;
this.Range["A2", missing].Value2 = 10;
this.Range["A3", missing].Value2 = 20;
this.Range["A4", missing].Value2 = 50;
this.Range["A5", missing].Value2 = 40;
// Create a NamedRange that refers to the range.
Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
this.Controls.AddNamedRange(this.Range["A1", "A5"],
"namedRange1");
// Sort the NamedRange.
namedRange1.Sort(this.Range["A1", "A5"],
Excel.XlSortOrder.xlAscending,
missing,
missing,
Excel.XlSortOrder.xlAscending,
missing,
Excel.XlSortOrder.xlAscending,
Excel.XlYesNoGuess.xlNo,
missing,
missing,
Excel.XlSortOrientation.xlSortColumns,
Excel.XlSortMethod.xlStroke,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal);
}
转载网址:http://blog.sina.com.cn/s/blog_68b5c3e301015vqe.html