c#)Excel常用格式操作

來源:互聯網
上載者:User

  • range.NumberFormatLocal = "@";     //設定儲存格格式為文本   
  •   
  • range = (Range)worksheet.get_Range("A1", "E1");     //擷取Excel多個儲存格範圍:本例做為Excel表頭   
  •   
  • range.Merge(0);     //儲存格合并動作   
  •   
  • worksheet.Cells[1, 1] = "Excel儲存格賦值";     //Excel儲存格賦值   
  •   
  • range.Font.Size = 15;     //設定字型大小   
  •   
  • range.Font.Underline=true;     //設定字型是否有底線   
  •   
  • range.Font.Name="黑體";       設定字型的種類   
  •   
  • range.HorizontalAlignment=XlHAlign.xlHAlignCenter;     //設定字型在儲存格內的對其方式   
  •   
  • range.ColumnWidth=15;     //設定儲存格的寬度   
  •   
  • range.Cells.Interior.Color=System.Drawing.Color.FromArgb(255,204,153).ToArgb();     //設定儲存格的背景色   
  •   
  • range.Borders.LineStyle=1;     //設定儲存格邊框的粗細   
  •   
  • range.BorderAround(XlLineStyle.xlContinuous,XlBorderWeight.xlThick,XlColorIndex.xlColorIndexAutomatic,System.Drawing.Color.Black.ToArgb());     //給儲存格加邊框   
  •   
  • range.Borders.get_Item(Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeTop).LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlLineStyleNone; //設定儲存格上邊框為無邊框   
  •   
  •     range.EntireColumn.AutoFit();     //自動調整列寬   
  •   
  • Range.HorizontalAlignment= xlCenter;     // 文本水平置中方式   
  •   
  • Range.VerticalAlignment= xlCenter     //文本垂直置中方式   
  •   
  • Range.WrapText=true;     //文本自動換行   
  •   
  • Range.Interior.ColorIndex=39;     //填充顏色為淡紫色   
  •   
  • Range.Font.Color=clBlue;     //字型顏色   
  •   
  • xlsApp.DisplayAlerts=false;     

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.