使用Gradient方法处理渐变填充功能.docxVIP

  • 18
  • 0
  • 约1.46千字
  • 约 2页
  • 2017-05-16 发布于重庆
  • 举报
使用Gradient方法处理渐变填充功能

【e800编译】此示例演示在Microsoft Excel 2010中如何使用FillFormat对象的渐变填充功能。此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C#中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。Microsoft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。实例代码在Excel 2010中新建工作簿,复制下列所有代码到Sheet1类模块,将光标置于GradientDemo内,按F8单步执行代码。并列放置VBA和Excel窗口,这样你就可以参考注释中的提示。SubGradientDemo()DimrngAsRangeSetrng=Range(B2:C10)rng.Cells.MergeDimgrd1AsLinearGradientrng.Interior.Pattern=XlPattern.xlPatternLinearGradientSetgrd1=rng.Interior.GradientDimcsAsColorStop Set the gradient to be tilted by 10 degrees:grd1.Degree=10 Add a color stop at 25% of the width:Setcs=grd1.ColorStops.Add(0.25)cs.Color=vbYellow Set the shading: -1 is black, 1 is white, 0 is the full color. Setting this to 0.25 makes it a little paler.cs.TintAndShade=0.25 Add a color stop at 100% of the width:Setcs=grd1.ColorStops.Add(1)cs.Color=vbRed Repeat with a rectangular gradient:Setrng=Range(E2:F10)Dimgrd2AsRectangularGradientrng.Interior.Pattern=XlPattern.xlPatternRectangularGradientrng.Cells.MergeSetgrd2=rng.Interior.Gradient Set the offset for the rectangular gradient to the center of the region:grd2.RectangleLeft=0.5grd2.RectangleTop=0.5 Add color stops at 25% and 100%:Setcs=grd2.ColorStops.Add(0.25)cs.Color=vbRedSetcs=grd2.ColorStops.Add(1)cs.Color=vbYellowEndSub

文档评论(0)

1亿VIP精品文档

相关文档