文档彩票走势图>>Spire.XLS 系列教程>>Excel .NET组件Spire.XLS图片管理系列教程:替换图形并插入箭头
Excel .NET组件Spire.XLS图片管理系列教程:替换图形并插入箭头
更多资源查看:Spire.XLS工作表教程 | Spire.Doc系列教程 | Spire.PDF系列教程
Spire.XLS for .NET 是一款专业的 .NET Excel 组件, 它可以用在各种.NET 框架中,包括 .NET Core、ASP.NET 和 Windows Forms 等相关的.NET 应用程序。在Excel表格中图片也是我们经常会使用到的工具,这时我们如何使用Spire.XLS来完成呢?这就是本系列教程将给大家详细讲解的。
C# Excel 图片替换
原文档如下:
//创建Workbook实例 Workbook workbook = new Workbook(); //加载Excel文档 workbook.LoadFromFile(@"Input.xlsx"); //获取第一张工作表 Worksheet sheet = workbook.Worksheets[0]; //替换工作表中第一张图片 sheet.Pictures[0].Picture = Image.FromFile("image.jpg"); //保存文档 workbook.SaveToFile("ReplaceImage.xlsx", ExcelVersion.Version2013);
替换图片后:
C# Excel 插入箭头
前面我们介绍了如何使用 Spire.XLS 插入图形到Excel 工作表,接下来将介绍如何使用Spire.XLS插入常用的箭头如双箭头,肘形箭头和曲线箭头到Excel文档。
using Spire.Xls; using System.Drawing; namespace Add_Lines_to_Excel { class Program { static void Main(string[] args) { //创建workbook实例并获取第一张工作表 Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; //插入双箭头并设置线条颜色 var line = sheet.TypedLines.AddLine(); line.Top = 10; line.Left = 20; line.Width = 100; line.Height = 0; line.Color = Color.Blue; line.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow; line.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow; //插入箭头并设置线条颜色 var line_1 = sheet.TypedLines.AddLine(); line_1.Top = 50; line_1.Left = 30; line_1.Width = 100; line_1.Height = 100; line_1.Color = Color.Red; line_1.BeginArrowHeadStyle = ShapeArrowStyleType.LineNoArrow; line_1.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.Width = 50; line2.Height = 50; line2.EndArrowHeadStyle = ShapeArrowStyleType.LineArrow; line2.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrow; line2.Left = 120; line2.Top = 100; //插入曲线箭头连接符 line3 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape; line3.LineShapeType = LineShapeType.CurveLine; line3.Width = 30; line3.Height = 50; line3.EndArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen; line3.Top = 100; line3.Left = 200; //插入曲线双箭头连接符 line2 = sheet.TypedLines.AddLine() as Spire.Xls.Core.Spreadsheet.Shapes.XlsLineShape; line2.LineShapeType = LineShapeType.CurveLine; line2.Width = 30; line2.Height = 50; line2.EndArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen; line2.BeginArrowHeadStyle = ShapeArrowStyleType.LineArrowOpen; line2.Left = 250; line2.Top = 100; //Save the file workbook.SaveToFile("AddLines.xlsx", ExcelVersion.Version2013); } } }
*想要购买Spire.XLS正版授权的朋友可以哦~