Independentsoft
Any library, any programming language
Home
Purchase
Support
Company
Contact
JWord
>
Tutorial
> Highlight text
The following example shows you how to highlight text with different colors.
import com.independentsoft.office.word.HighlightColor; import com.independentsoft.office.word.Paragraph; import com.independentsoft.office.word.Run; import com.independentsoft.office.word.WordDocument; public class Example { public static void main(String[] args) { try { WordDocument doc = new WordDocument(); // Yellow highlight Run yellowRun = new Run(); yellowRun.addText("This text has yellow highlight. "); yellowRun.setHighlightColor(HighlightColor.YELLOW); // Green highlight Run greenRun = new Run(); greenRun.addText("This text has green highlight. "); greenRun.setHighlightColor(HighlightColor.GREEN); // Cyan highlight Run cyanRun = new Run(); cyanRun.addText("This text has cyan highlight. "); cyanRun.setHighlightColor(HighlightColor.CYAN); // Magenta highlight Run magentaRun = new Run(); magentaRun.addText("This text has magenta highlight. "); magentaRun.setHighlightColor(HighlightColor.MAGENTA); // Red highlight Run redRun = new Run(); redRun.addText("This text has red highlight. "); redRun.setHighlightColor(HighlightColor.RED); // Normal text Run normalRun = new Run(); normalRun.addText("This text has no highlight."); Paragraph paragraph = new Paragraph(); paragraph.add(yellowRun); paragraph.add(greenRun); paragraph.add(cyanRun); paragraph.add(magentaRun); paragraph.add(redRun); paragraph.add(normalRun); 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*