Hypertextový odkaz
Contents
[
Hide
]
Tento článek demonstruje přidávání, načítání, odstraňování a aktualizaci hypertextových odkazů na tvarech pomocí Aspose.Slides pro Android přes Java.
Přidání hypertextového odkazu
Vytvořte obdélníkový tvar s hypertextovým odkazem směřujícím na externí webovou stránku.
static void addHyperlink() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.getTextFrame().setText("Aspose");
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
textPortion.getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com"));
} finally {
presentation.dispose();
}
}
Přístup k hypertextovému odkazu
Načtěte informace o hypertextovém odkazu z textové části tvaru.
static void accessHyperlink() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.getTextFrame().setText("Aspose");
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
textPortion.getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com"));
IHyperlink hyperlink = textPortion.getPortionFormat().getHyperlinkClick();
} finally {
presentation.dispose();
}
}
Odstranění hypertextového odkazu
Odstraňte hypertextový odkaz z textu tvaru.
static void removeHyperlink() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.getTextFrame().setText("Aspose");
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
textPortion.getPortionFormat().setHyperlinkClick(new Hyperlink("https://www.aspose.com"));
textPortion.getPortionFormat().setHyperlinkClick(null);
} finally {
presentation.dispose();
}
}
Aktualizace hypertextového odkazu
Změňte cíl existujícího hypertextového odkazu. Použijte HyperlinkManager k úpravě textu, který již hypertextový odkaz obsahuje, což napodobuje bezpečnou aktualizaci hypertextových odkazů v PowerPointu.
static void updateHyperlink() {
Presentation presentation = new Presentation();
try {
ISlide slide = presentation.getSlides().get_Item(0);
IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 50, 50, 150, 50);
shape.getTextFrame().setText("Aspose");
IParagraph paragraph = shape.getTextFrame().getParagraphs().get_Item(0);
IPortion textPortion = paragraph.getPortions().get_Item(0);
textPortion.getPortionFormat().setHyperlinkClick(new Hyperlink("https://old.example.com"));
// Změna hypertextového odkazu v existujícím textu by měla být provedena pomocí
// HyperlinkManageru místo přímého nastavení vlastnosti.
// To napodobuje, jak PowerPoint bezpečně aktualizuje hypertextové odkazy.
textPortion.getPortionFormat().getHyperlinkManager().setExternalHyperlinkClick("https://new.example.com");
} finally {
presentation.dispose();
}
}