Segui questa guida su come aggiungere un collegamento ipertestuale a PowerPoint con l’API REST C#. Imparerai a inserire automaticamente il collegamento ipertestuale in PowerPoint con il servizio RESTful C# utilizzando un Cloud SDK basato su .NET che supporta tutte le funzionalità avanzate per lavorare con le presentazioni. Ti aiuterà nella selezione di una diapositiva e di una forma particolari per l’aggiunta di un collegamento ipertestuale personalizzato.
Prerequisito
Scaricamento Aspose.Slides Cloud SDK for Dotnet for inserting hyperlinks
Configura il progetto C# con l’SDK precedente per aggiungere un collegamento a una forma
Passaggi per aggiungere un collegamento a PowerPoint con API basata su C# .NET
- Crea un’istanza di SlidesApi con la chiave API e il segreto per l’autenticazione
- Leggere il file di input in un flusso di memoria e caricarlo
- Imposta gli indici delle diapositive e delle forme per l’aggiunta del collegamento ipertestuale (indice in base 1)
- Crea un oggetto forma con un collegamento ipertestuale
- Update la forma sulla diapositiva specificata con il collegamento ipertestuale
- Stampa l’URL del collegamento ipertestuale aggiornato sulla console per la verifica
- Scarica la presentazione aggiornata dal cloud come flusso e salvala sul disco
Questi passaggi spiegano come aggiungere un collegamento ipertestuale in PowerPoint con l’API REST C#. Puoi creare una forma e aggiungere un collegamento ipertestuale definendo il tipo di azione e l’URL esterno. Infine, aggiorna la forma di destinazione nella diapositiva desiderata utilizzando la forma appena creata e, se necessario, salva l’output sul disco.
Codice per inserire il collegamento in PowerPoint con l’API C# Low Code
using Aspose.Slides.Cloud.Sdk; // Import the Aspose.Slides Cloud SDK to work with PowerPoint presentations. | |
using Aspose.Slides.Cloud.Sdk.Model; // Import models used by the SDK. | |
using System; // Import the System namespace for basic functionalities. | |
using System.IO; // Import System.IO for file input/output operations. | |
namespace AsposeTestCodes | |
{ | |
class Program | |
{ | |
static void Main(string[] args) // Main method - the program's entry point. | |
{ | |
// Instantiate the SlidesApi with the API key and secret for authentication. | |
SlidesApi slidesApi = new SlidesApi("Client ID", "Client Secret"); | |
// Name of the PowerPoint file to work with. | |
string fileName = "PresentationWithoutHyperlink.pptx"; | |
// Read the file into a memory stream and upload it to the Aspose.Slides cloud storage. | |
FilesUploadResult uploadedPresResult = slidesApi.UploadFile(fileName, new MemoryStream(File.ReadAllBytes(fileName))); | |
// Index of the slide and shape where the target shape is located (1-based index). | |
int slideIndex = 2, shapeIndex = 2; | |
Shape shape = new Shape // Create a shape object with a hyperlink | |
{ | |
HyperlinkClick = new Hyperlink | |
{ | |
ActionType = Hyperlink.ActionTypeEnum.Hyperlink, // Set the action type as a hyperlink. | |
ExternalUrl = "https://docs.aspose.cloud/slides" // The URL for the hyperlink. | |
} | |
}; | |
// Update the shape on the specified slide with the hyperlink. | |
ShapeBase updatedShpWithHyperlink = slidesApi.UpdateShape(fileName, slideIndex, shapeIndex, shape); | |
// Print the updated hyperlink's URL to the console for verification. | |
Console.WriteLine(updatedShpWithHyperlink.HyperlinkClick.ExternalUrl); | |
// Download the updated presentation from the cloud as a stream. | |
Stream stream = slidesApi.DownloadFile(fileName); | |
// Save the downloaded presentation to the local file system with a new name. | |
var fs = new FileStream("PresWithHyperlinks.pptx", FileMode.Create, FileAccess.Write); | |
stream.CopyTo(fs); // Copy the content from the stream to the file. | |
} | |
} | |
} |
Questo codice dimostra come inserire un collegamento ipertestuale in PowerPoint con l’interfaccia REST C#. È possibile impostare varie proprietà di un collegamento ipertestuale, ad esempio un flag per abilitare/disabilitare un collegamento ipertestuale, la descrizione comando, la cronologia, l’evidenziazione del clic e l’interruzione del suono al clic. Tieni presente che tutte queste proprietà sono disponibili passando con il mouse sul collegamento ipertestuale anziché facendo clic su di esso.
Questo articolo ci ha insegnato a creare un collegamento ipertestuale in PowerPoint con l’API C# Low Code. Per aggiungere una SmartArt in una diapositiva, fare riferimento all’articolo su Aggiungi SmartArt a PowerPoint con l’API REST C#.