前面我们介绍了如何使用 spire.xls ,本文将介绍如何使用spire.xls插入常用的箭头如双箭头,肘形箭头和曲线箭头到excel文档。
c#
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);
}
}
}
vb.net
imports spire.xls
imports system.drawing
namespace add_lines_to_excel
class program
private shared sub main(args as string())
'创建workbook实例并获取第一张工作表
dim workbook as new workbook()
dim sheet as worksheet = workbook.worksheets(0)
'插入双箭头并设置线条颜色
dim 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
'插入箭头并设置线条颜色
dim 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
'插入肘形箭头连接符
dim line3 as spire.xls.core.spreadsheet.shapes.xlslineshape = trycast(sheet.typedlines.addline(), 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
'插入肘形双箭头连接符
dim line2 as spire.xls.core.spreadsheet.shapes.xlslineshape = trycast(sheet.typedlines.addline(), 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 = trycast(sheet.typedlines.addline(), 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 = trycast(sheet.typedlines.addline(), 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)
end sub
end class
end namespace