Word 文書におけるハイパーリンクは、通常、青い書体に下線を付けて表示されます。実は、ハイパーリンクの既定のスタイルが気に入らない場合、リンクを維持したままハイパーリンクの色を変更したり、下線を削除して独自のハイパーリンクのスタイルにすることができます。この記事では、Spire.Doc for Java を使用して、Word のハイパーリンクの色を変更したり、下線を削除したりする方法を紹介します。 Spire.Doc for Java をインストールします まず、Spire. Doc for Java を Java プロジェクトに追加する必要があります。JAR ファイルは、このリンクからダウンロードできます。Maven を使用する場合は、次のコードをプロジェクトの pom.xml ファイルに追加する必要があります。 <repositories> <repository> <id>com.e-iceblue</id> <name>e-iceblue</name> <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url> </repository> </repositories> <dependencies> <dependency> <groupId>e-iceblue</groupId> <artifactId>spire.doc</artifactId> <version>10.7.10</version> </dependency> </dependencies> Word ドキュメント内のハイパーリンクの色を変更するか、下線を削除します 詳細な手順は以下の通りです。 Document クラスのオブジェクトを作成します。 Document.addSection() メソッドを使用して、ドキュメントにセクションを追加します。 Section.addParagraph() メソッドを使用して、セクションに段落を追加します。 Paragraph.appendHyperlink() メソッドを使用して、普通のハイパーリンクを挿入します。 段落とハイパーリンクを追加し、TextRange.getCharacterFormat().setTextColor() メソッドを使用して、ハイパーリンクのテキストの色を赤に変更します。 段落とハイパーリンクを追加し、TextRange.getCharacterFormat().setUnderlineStyle() メソッドを使用してハイパーリンクの下線を削除します。 Document.saveToFile() メソッドを使用して、ドキュメントを保存します。 Java import com.spire.doc.Document; import com.spire.doc.FileFormat; import com.spire.doc.Section; import com.spire.doc.documents.*; import com.spire.doc.fields.TextRange; import java.awt.*; public class ChangeHyperlink { public static void main(String[] args) { //Documentクラスのオブジェクトを作成する Document document = new Document(); //セクションを追加する Section section = document.addSection(); //段落を追加する Paragraph para= section.addParagraph(); para.appendText("普通のハイパーリンク: "); //ハイパーリンクを挿入する TextRange textRange = para.appendHyperlink("www.e-iceblue.com", "E-iceblue", HyperlinkType.Web_Link); textRange.getCharacterFormat().setFontName("Times New Roman"); textRange.getCharacterFormat().setFontSize(12f); para.appendBreak(BreakType.Line_Break); //段落を追加する para = section.addParagraph(); para.appendText("このハイパーリンクの色を変更する: "); //ハイパーリンクを挿入する textRange = para.appendHyperlink("www.e-iceblue.com", "E-iceblue", HyperlinkType.Web_Link); textRange.getCharacterFormat().setFontName("Times New Roman"); textRange.getCharacterFormat().setFontSize(12f); //ハイパーリンクの色を赤に変更する textRange.getCharacterFormat().setTextColor(Color.RED); para.appendBreak(BreakType.Line_Break); //段落を追加する para = section.addParagraph(); para.appendText("このハイパーリンクの下線を削除する: "); //ハイパーリンクを挿入する textRange = para.appendHyperlink("www.e-iceblue.com", "E-iceblue", HyperlinkType.Web_Link); textRange.getCharacterFormat().setFontName("Times New Roman"); textRange.getCharacterFormat().setFontSize(12f); //ハイパーリンクの下線を削除する textRange.getCharacterFormat().setUnderlineStyle(UnderlineStyle.None); //ドキュメントを保存する document.saveToFile("ハイパーリンクのスタイルの変更.docx", FileFormat.Docx_2013); } } 一時ライセンスを申請する 結果ドキュメントから評価メッセージを削除したい場合、または機能制限を取り除く場合は、についてこのメールアドレスはスパムボットから保護されています。閲覧するにはJavaScriptを有効にする必要があります。 にお問い合わせ、30 日間有効な一時ライセンスを取得してください。