Rileva il tipo di collegamento ipertestuale
Contents
[
Hide
]
Rileva il tipo di collegamento ipertestuale
Un file Excel può avere diversi tipi di collegamenti ipertestuali come esterno, riferimento di cella, percorso file, ecc. Aspose.Cells supporta la funzione per rilevare il tipo di collegamento ipertestuale. I tipi di collegamenti ipertestuali sono rappresentati dalTargetModeTypeEnumerazione. IlTargetModeTypeL’enumerazione ha i seguenti membri.
- ESTERNO: Link esterno
- PERCORSO DEL FILE: percorso locale e completo di file\cartelle.
- E-MAIL: E-mail
- RIFERIMENTO_CELLULA: collegamento alla cella o all’intervallo denominato.
Per verificare il tipo di collegamento ipertestuale, il fileCollegamento ipertestuale la classe fornisce aTipo di collegamento proprietà con un tipo restituito diTargetModeType. Il seguente frammento di codice illustra l’uso diTipo di collegamentoproprietà utilizzando thisfile excel di origine.
Codice sorgente
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
public static void main(String[] args) throws Exception { | |
// The path to the directories. | |
String sourceDir = Utils.Get_SourceDirectory(); | |
Workbook workbook = new Workbook(sourceDir + "LinkTypes.xlsx"); | |
// Get the first (default) worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Create a range A2:B3 | |
Range range = worksheet.getCells().createRange("A1", "A7"); | |
// Get Hyperlinks in range | |
Hyperlink[] hyperlinks = range.getHyperlinks(); | |
for (Hyperlink link : hyperlinks) | |
{ | |
System.out.println(link.getTextToDisplay() + ": " + getLinkTypeName(link.getLinkType())); | |
} | |
System.out.println("DetectLinkTypes executed successfully."); | |
} | |
private static String getLinkTypeName(int linkType){ | |
if(linkType == TargetModeType.EXTERNAL){ | |
return "EXTERNAL"; | |
} else if(linkType == TargetModeType.FILE_PATH){ | |
return "FILE_PATH"; | |
} else if(linkType == TargetModeType.EMAIL){ | |
return "EMAIL"; | |
} else { | |
return "CELL_REFERENCE"; | |
} | |
} |
Di seguito è riportato l’output generato dal frammento di codice sopra indicato.
Uscita console
LinkTypes.xlsx: FILE_PATH </br>
C:\Windows\System32\cmd.exe: FILE_PATH </br>
C:\Program Files\Common Files: FILE_PATH </br>
'Test Sheet'!B2: CELL_REFERENCE </br>
FullPathExample: CELL_REFERENCE </br>
https://products.aspose.com/cells/ : EXTERNAL </br>
mailto:test@test.com?subject=TestLink: EMAIL