Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Add hyperlink
The following example shows you how to add a hyperlink.
import com.independentsoft.office.word.Color; import com.independentsoft.office.word.Hyperlink; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.RunContentColor; import com.independentsoft.office.word.Underline; import com.independentsoft.office.word.UnderlinePattern; import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); Run run = new Run(); run.addText("Independentsoft"); run.setUnderline(new Underline(UnderlinePattern.SINGLE)); Color runColor = new Color("#0000FF"); run.setColor(new RunContentColor(runColor)); Hyperlink link = new Hyperlink(); link.add(run); link.setTarget("http://www.independentsoft.com"); Paragraph paragraph = new Paragraph(); paragraph.add(link); doc.getBody().add(paragraph); doc.save("c:\\test\\output.docx", true); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
Need help? Ask our developers:
Name*
Email*
Message*