Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Spreadsheet .NET
>
Tutorial
> Insert Line
The following example shows you how to create a line.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Drawing; using Independentsoft.Office.Spreadsheet; using Independentsoft.Office.Spreadsheet.Drawing; namespace Sample { class Program { static void Main(string[] args) { Workbook book = new Workbook(); Worksheet sheet1 = new Worksheet(); TwoCellAnchor anchor = new TwoCellAnchor(); anchor.Start = new StartAnchorPoint(); anchor.Start.Column = 1; anchor.Start.ColumnOffset = new Unit(0, UnitType.EnglishMetricUnit); anchor.Start.Row = 2; anchor.Start.RowOffset = new Unit(0, UnitType.EnglishMetricUnit); anchor.End = new EndAnchorPoint(); anchor.End.Column = 5; anchor.End.ColumnOffset = new Unit(0, UnitType.EnglishMetricUnit); anchor.End.Row = 7; anchor.End.RowOffset = new Unit(0, UnitType.EnglishMetricUnit); Independentsoft.Office.Spreadsheet.Drawing.Shape shape = new Independentsoft.Office.Spreadsheet.Drawing.Shape(); shape.ID = "10"; shape.Name = "Line 1"; SolidFill solidFill = new SolidFill(); solidFill.ColorChoice = new SchemeColor(SchemeColorValue.Accent6); Outline borderLine = new Outline(); borderLine.LineWidth = new Unit(2, UnitType.Point); borderLine.SolidFill = solidFill; PresetGeometry presetGeometry = new PresetGeometry(ShapeType.Line); shape.ShapeProperties.PresetGeometry = presetGeometry; shape.ShapeProperties.Outline = borderLine; anchor.Element = shape; anchor.ClientData = new ClientData(); DrawingObjects drawingObjects = new DrawingObjects(); drawingObjects.Anchors.Add(anchor); sheet1.DrawingObjects = drawingObjects; book.Sheets.Add(sheet1); book.Save("c:\\test\\output.xlsx", true); } } }
VB example
Imports System Imports Independentsoft.Office Imports Independentsoft.Office.Drawing Imports Independentsoft.Office.Spreadsheet Imports Independentsoft.Office.Spreadsheet.Drawing Module Module1 Sub Main(ByVal args As String()) Dim book As New Workbook() Dim sheet1 As New Worksheet() Dim anchor As New TwoCellAnchor() anchor.Start = New StartAnchorPoint() anchor.Start.Column = 1 anchor.Start.ColumnOffset = New Unit(0, UnitType.EnglishMetricUnit) anchor.Start.Row = 2 anchor.Start.RowOffset = New Unit(0, UnitType.EnglishMetricUnit) anchor.[End] = New EndAnchorPoint() anchor.[End].Column = 5 anchor.[End].ColumnOffset = New Unit(0, UnitType.EnglishMetricUnit) anchor.[End].Row = 7 anchor.[End].RowOffset = New Unit(0, UnitType.EnglishMetricUnit) Dim shape As New Independentsoft.Office.Spreadsheet.Drawing.Shape() shape.ID = "10" shape.Name = "Line 1" Dim solidFill As New SolidFill() solidFill.ColorChoice = New SchemeColor(SchemeColorValue.Accent6) Dim borderLine As New Outline() borderLine.LineWidth = New Unit(2, UnitType.Point) borderLine.SolidFill = solidFill Dim presetGeometry As New PresetGeometry(ShapeType.Line) shape.ShapeProperties.PresetGeometry = presetGeometry shape.ShapeProperties.Outline = borderLine anchor.Element = shape anchor.ClientData = New ClientData() Dim drawingObjects As New DrawingObjects() drawingObjects.Anchors.Add(anchor) sheet1.DrawingObjects = drawingObjects book.Sheets.Add(sheet1) book.Save("c:\test\output.xlsx", True) End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*