C# 添加箭头线条形状到Excel_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > C# 添加箭头线条形状到Excel

C# 添加箭头线条形状到Excel

 2019/9/19 21:28:11  Miaonly  程序员俱乐部  我要评论(0)
  • 摘要:在Excel中,可以添加不同类型的形状,包括线条形状、矩形形状、基本形状、箭头总汇、公式形状、流程图、标注形状、星于旗帜形状等等。在“C#操作Excel形状”这篇文章中,介绍了在Excel中添加、读取、隐藏、删除形状的方法。本篇文章将介绍除上述文章中涉及到的形状外,带箭头的线条形状的添加方法。通过这些线条形状应用到表格中可起到特定指示、连接或转换作用。下面将通过C#代码示例演示。使用工具:Spire.XLSfor.NET9.9.0文件获取及dll引用:方法1:通过官网下载文件包。下载后
  • 标签:C# excel

class="MsoNormal">在Excel中,可以添加不同类型的形状,包括线条形状、矩形形状、基本形状、箭头总汇、公式形状、流程图、标注形状、星于旗帜形状等等。在“C# 操作Excel形状”这篇文章中,介绍了在Excel中添加、读取、隐藏、删除形状的方法。本篇文章将介绍除上述文章中涉及到的形状外,带箭头的线条形状的添加方法。通过这些线条形状应用到表格中可起到特定指示、连接或转换作用。下面将通过C#代码示例演示。

?

使用工具: Spire.XLS for .NET 9.9.0

?

文件获取及dll引用:

方法1通过官网下载文件包。下载后,解压文件。将bin文件夹中的Spire.Xls.dll文件添加引用到C# 程序。如下图:


?

方法2可通过Nuget下载。

?

C#代码示例(供参考)

using Spire.Xls;
using System.Drawing;

namespace AddLines_XLS
{
    class Program
    {
        static void Main(string[] args)
        {
            //创建workbook类的实例,并获取第一张工作表
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            //添加水平方向带箭头的线条,并设置线条颜色           
            var line1 = sheet.TypedLines.AddLine();
            line1.Top = 10;
            line1.Left = 20;
            line1.Width = 100;
            line1.Height = 0;
            line1.Color = Color.Blue;
            line1.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow;          
            var line11 = sheet.TypedLines.AddLine();
            line11.Top = 40;
            line11.Left = 20;
            line11.Width = 100;
            line11.Height = 0;
            line11.Color = Color.Blue;            
            line11.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;

            var line111 = sheet.TypedLines.AddLine();
            line111.Top = 70;
            line111.Left = 20;
            line111.Width = 100;
            line111.Height = 0;
            line111.Color = Color.Blue;
            line111.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            line111.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;

            //插入倾斜的带箭头的线条,并设置线条颜色
            var line_1 = sheet.TypedLines.AddLine();
            line_1.Top = 10;
            line_1.Left = 140;
            line_1.Width = 60;
            line_1.Height = 50;
            line_1.Color = Color.Red;
            line_1.BeginArrowHeadStyle = ShapeArrowStyleType.LineNoArrow;
            line_1.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;

            var line_2 = sheet.TypedLines.AddLine();
            line_2.Top = 10;
            line_2.Left = 180;
            line_2.Width = 60;
            line_2.Height = 50;
            line_2.Color = Color.Red;
            line_2.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            line_2.EndArrowHeadStyle = ShapeArrowStyleType.LineNoArrow;

            var line_3 = sheet.TypedLines.AddLine();
            line_3.Top = 10;
            line_3.Left = 220;
            line_3.Width = 60;
            line_3.Height = 50;
            line_3.Color = Color.Red;
            line_3.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            line_3.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;

            //插入肘形箭头连接符
            Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape line3 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape;
            line3.LineShapeType = LineShapeType.ElbowLine;
            line3.Width = 30;
            line3.Height = 50;
            line3.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            line3.Top = 100;
            line3.Left = 50;

            Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape line2 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape;
            line2.LineShapeType = LineShapeType.ElbowLine;            
            line2.Top = 100;
            line2.Left = 100;
            line2.Width = 50;
            line2.Height = 50;
            line2.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            line2.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow;
            

            //插入曲线箭头连接符
            line3 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape;
            line3.LineShapeType = LineShapeType.CurveLine;
            line3.Top = 100;
            line3.Left = 170;
            line3.Width = 30;
            line3.Height = 50;
            line3.EndArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen;
            
            line2 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape;
            line2.LineShapeType = LineShapeType.CurveLine;           
            line2.Top = 100;
            line2.Left = 230;
            line2.Width = 30;
            line2.Height = 50;
            line2.EndArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen;
            line2.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen;
            

            //保存文档
            workbook.SaveToFile("AddLines.xlsx", ExcelVersion.Version2013);
          }
    }
}

箭头线条形状添加效果:


?

?

(本文完)

转载请注明出处!

?

  • 大小: 37.4 KB
  • 大小: 24 KB
  • 查看图片附件
发表评论
用户名: 匿名