日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

使用C#和Excel进行报表开发(五)-操作单元格边框和颜色 【转】

發布時間:2023/12/9 C# 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用C#和Excel进行报表开发(五)-操作单元格边框和颜色 【转】 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在用Excel作報表的時候,可能需要操作單元格的邊框和填充顏色和紋理等操作,下面的代碼說明如何設置選中的單元格的填充紋理和邊框

?

try

{

?????? ThisApplication = new Excel.Application();

?

????? ThisWorkbook = ThisApplication.Workbooks.Open("z:\\Book1.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

????????????????????

?

?????? ThisApplication.DisplayAlerts = false;

?????? xlSheet = (Excel.Worksheet)ThisWorkbook.Worksheets.get_Item(1);

?????? Excel.Range range = xlSheet.get_Range("G4","H5");

?????? range.Value = "123";

???????????????????????????

?????? Excel.Style st = ThisWorkbook.Styles.Add("PropertyBorder", Type.Missing);

???????????????????????????????????????????????????????

?????? range.Interior.Pattern = Excel.XlPattern.xlPatternCrissCross;

???????range.Borders.Weight = 2;

?????? range.Borders.get_Item(XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous;

???????range.Borders.get_Item(XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous;

???????range.Borders.get_Item(XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous;

???????range.Borders.get_Item(XlBordersIndex.xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone;

???????range.Borders.get_Item(XlBordersIndex.xlDiagonalUp).LineStyle = Excel.XlLineStyle.xlLineStyleNone;

???????range.Borders.get_Item(XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlLineStyleNone;

???????range.Borders.get_Item(XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlLineStyleNone;

???????range.Borders.get_Item(XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlDot;

???????range.Borders.get_Item(XlBordersIndex.xlEdgeLeft).Color = System.Drawing.ColorTranslator.ToOle(Color.Red);

???????????????????????????

?????? ThisWorkbook.SaveAs("z:\\Book2.xls", Type.Missing, Type.Missing,

????????????? Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange,

????????????? Type.Missing, Type.Missing, Type.Missing, Type.Missing);

}

catch (Exception ex)

{

?????? MessageBox.Show(ex.Message);

}

finally

{

?????? ThisWorkbook.Close(Type.Missing, Type.Missing, Type.Missing);

?????? ThisApplication.Workbooks.Close();

?

?????? ThisApplication.Quit();

???????System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisWorkbook);

???????System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisApplication);

?????? ThisWorkbook = null;

?????? ThisApplication = null;

?????? GC.Collect();

?????? this.Close();

}

轉載于:https://www.cnblogs.com/fmxyw/archive/2008/09/09/1287848.html

總結

以上是生活随笔為你收集整理的使用C#和Excel进行报表开发(五)-操作单元格边框和颜色 【转】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。