//create a new workbook Workbook workbook = new Workbook(); IWorksheet worksheet = workbook.getWorksheets().get(0); // Add shapes IShape shape1 = worksheet.getShapes().addShape(AutoShapeType.Rectangle, 10, 0, 100, 100); shape1.getTextFrame().getTextRange().add("Go to google web site."); IShape shape2 = worksheet.getShapes().addShape(AutoShapeType.RightArrow, 10, 120, 100, 100); shape2.getTextFrame().getTextRange().add("Go to sheet1 C3:E4"); IShape shape3 = worksheet.getShapes().addShape(AutoShapeType.Oval, 10, 240, 100, 100); shape3.getTextFrame().getTextRange().add("Send an email to sales"); IShape shape4 = worksheet.getShapes().addShape(AutoShapeType.LeftArrow, 10, 360, 100, 100); shape4.getTextFrame().getTextRange().add("Link to external.xlsx file."); //add a hyperlink link to web page. worksheet.getHyperlinks().add(shape1, "http://www.google.com/", null, "open google web site.", "Google"); //add a hyperlink link to a range in this document. worksheet.getHyperlinks().add(shape2, null, "Sheet1!$C$3:$E$4", "Go to sheet1 C3:E4", null); //add a hyperlink link to email address. worksheet.getHyperlinks().add(shape3, "mailto:us.sales@grapecity.com", null, "Send an email to sales", "Send an email to sales"); //add a hyperlink link to external file. //change the path to real picture file path. String path = "external.xlsx"; worksheet.getHyperlinks().add(shape4, path, null, "link to external.xlsx file.", "External.xlsx"); //save to an excel file workbook.save("CreateShapeWithHyperlink.xlsx");
//create a new workbook var workbook = Workbook() val worksheet = workbook.worksheets.get(0) // Add shapes val shape1 = worksheet.shapes.addShape(AutoShapeType.Rectangle, 10.0, 0.0, 100.0, 100.0) shape1.textFrame.textRange.add("Go to google web site.") val shape2 = worksheet.shapes.addShape(AutoShapeType.RightArrow, 10.0, 120.0, 100.0, 100.0) shape2.textFrame.textRange.add("Go to sheet1 C3:E4") val shape3 = worksheet.shapes.addShape(AutoShapeType.Oval, 10.0, 240.0, 100.0, 100.0) shape3.textFrame.textRange.add("Send an email to sales") val shape4 = worksheet.shapes.addShape(AutoShapeType.LeftArrow, 10.0, 360.0, 100.0, 100.0) shape4.textFrame.textRange.add("Link to external.xlsx file.") //add a hyperlink link to web page. worksheet.hyperlinks.add(shape1, "http://www.google.com/", null, "open google web site.", "Google") //add a hyperlink link to a range in this document. worksheet.hyperlinks.add(shape2, null, "Sheet1!\$C$3:\$E$4", "Go to sheet1 C3:E4", null) //add a hyperlink link to email address. worksheet.hyperlinks.add(shape3, "mailto:us.sales@grapecity.com", null, "Send an email to sales", "Send an email to sales") //add a hyperlink link to external file. //change the path to real picture file path. val path = "external.xlsx" worksheet.hyperlinks.add(shape4, path, null, "link to external.xlsx file.", "External.xlsx") //save to an excel file workbook.save("CreateShapeWithHyperlink.xlsx")