Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JSpreadsheet
>
Tutorial
> Insert Line
The following example shows you how to create a line.
import com.independentsoft.office.Unit; import com.independentsoft.office.UnitType; import com.independentsoft.office.drawing.Outline; import com.independentsoft.office.drawing.PresetGeometry; import com.independentsoft.office.drawing.SchemeColor; import com.independentsoft.office.drawing.SchemeColorValue; import com.independentsoft.office.drawing.ShapeType; import com.independentsoft.office.drawing.SolidFill; import com.independentsoft.office.spreadsheet.Workbook; import com.independentsoft.office.spreadsheet.Worksheet; import com.independentsoft.office.spreadsheet.drawing.ClientData; import com.independentsoft.office.spreadsheet.drawing.DrawingObjects; import com.independentsoft.office.spreadsheet.drawing.EndAnchorPoint; import com.independentsoft.office.spreadsheet.drawing.Shape; import com.independentsoft.office.spreadsheet.drawing.StartAnchorPoint; import com.independentsoft.office.spreadsheet.drawing.TwoCellAnchor; public class Example { public static void main(String[] args) { try { Workbook book = new Workbook(); Worksheet sheet1 = new Worksheet(); TwoCellAnchor anchor = new TwoCellAnchor(); StartAnchorPoint start = new StartAnchorPoint(); start.setColumn(1); start.setColumnOffset(new Unit(0, UnitType.ENGLISH_METRIC_UNIT)); start.setRow(2); start.setRowOffset(new Unit(0, UnitType.ENGLISH_METRIC_UNIT)); EndAnchorPoint end = new EndAnchorPoint(); end.setColumn(5); end.setColumnOffset(new Unit(0, UnitType.ENGLISH_METRIC_UNIT)); end.setRow(7); end.setRowOffset(new Unit(0, UnitType.ENGLISH_METRIC_UNIT)); anchor.setStart(start); anchor.setEnd(end); Shape shape = new Shape(); shape.setID("10"); shape.setName("Line 1"); SolidFill solidFill = new SolidFill(); solidFill.setColorChoice(new SchemeColor(SchemeColorValue.ACCENT_6)); Outline borderLine = new Outline(); borderLine.setLineWidth(new Unit(2, UnitType.POINT)); borderLine.setSolidFill(solidFill); PresetGeometry presetGeometry = new PresetGeometry(ShapeType.LINE); shape.getShapeProperties().setPresetGeometry(presetGeometry); shape.getShapeProperties().setOutline(borderLine); anchor.setElement(shape); anchor.setClientData(new ClientData()); DrawingObjects drawingObjects = new DrawingObjects(); drawingObjects.getAnchors().add(anchor); sheet1.setDrawingObjects(drawingObjects); book.getSheets().add(sheet1); book.save("c:\\test\\output.xlsx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*