Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JSpreadsheet
>
Tutorial
> Create Cell Link
The following example shows you how to create link to a cell.
import com.independentsoft.office.spreadsheet.Cell; import com.independentsoft.office.spreadsheet.DataBarColor; import com.independentsoft.office.spreadsheet.DefinedName; import com.independentsoft.office.spreadsheet.Font; import com.independentsoft.office.spreadsheet.Hyperlink; import com.independentsoft.office.spreadsheet.Underline; import com.independentsoft.office.spreadsheet.UnderlineType; import com.independentsoft.office.spreadsheet.Workbook; import com.independentsoft.office.spreadsheet.Worksheet; import com.independentsoft.office.spreadsheet.styles.CellFormat; public class Example { public static void main(String[] args) { try { DataBarColor dataBarColor = new DataBarColor(); dataBarColor.setColor("0000FF"); Font font1 = new Font(); font1.setName("Calibri"); font1.setSize(11); font1.setFamily(2); font1.setUnderline(new Underline(UnderlineType.SINGLE)); font1.setColor(dataBarColor); Hyperlink link = new Hyperlink(); link.setDisplay("MyLink"); link.setLocation("MyName1"); link.setReference("A1"); link.setExternal(false); CellFormat format1 = new CellFormat(); format1.setFont(font1); Cell a1 = new Cell("MyLink"); a1.setHyperlink(link); a1.setFormat(format1); Worksheet sheet1 = new Worksheet(); sheet1.setID(1); sheet1.setName("TestSheet1"); sheet1.set("A1", a1); Worksheet sheet2 = new Worksheet(); sheet2.setID(1); sheet2.setName("TestSheet2"); sheet2.set("A1", new Cell("Destination")); DefinedName name1 = new DefinedName("MyName1"); name1.setBody("TestSheet2!$A$1:$A$1"); Workbook book = new Workbook(); book.getSheets().add(sheet1); book.getSheets().add(sheet2); book.getDefinedNames().add(name1); 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*