文檔首頁(yè)>>Spire.XLS 系列教程>>Excel .NET組件Spire.XLS圖片管理系列教程:替換圖形并插入箭頭
Excel .NET組件Spire.XLS圖片管理系列教程:替換圖形并插入箭頭
更多資源查看:Spire.XLS工作表教程 | Spire.Doc系列教程 | Spire.PDF系列教程
Spire.XLS for .NET 是一款專業(yè)的 .NET Excel 組件, 它可以用在各種.NET 框架中,包括 .NET Core、ASP.NET 和 Windows Forms 等相關(guān)的.NET 應(yīng)用程序。在Excel表格中圖片也是我們經(jīng)常會(huì)使用到的工具,這時(shí)我們?nèi)绾问褂肧pire.XLS來(lái)完成呢?這就是本系列教程將給大家詳細(xì)講解的。
C# Excel 圖片替換
原文檔如下:
//創(chuàng)建Workbook實(shí)例 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 工作表,接下來(lái)將介紹如何使用Spire.XLS插入常用的箭頭如雙箭頭,肘形箭頭和曲線箭頭到Excel文檔。
using Spire.Xls; using System.Drawing; namespace Add_Lines_to_Excel { class Program { static void Main(string[] args) { //創(chuàng)建workbook實(shí)例并獲取第一張工作表 Workbook workbook = new Workbook(); Worksheet sheet = workbook.Worksheets[0]; //插入雙箭頭并設(shè)置線條顏色 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; //插入箭頭并設(shè)置線條顏色 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); } } }
*想要購(gòu)買Spire.XLS正版授權(quán)的朋友可以聯(lián)系慧都客服哦~