Siga esta guía sobre cómo agregar un hipervínculo a PowerPoint con la API REST de C#. Aprenderá a insertar hipervínculos en PowerPoint automáticamente con el servicio RESTful de C# utilizando un SDK de nube basado en .NET que admite todas las funciones avanzadas para trabajar con presentaciones. Le ayudará a seleccionar una diapositiva y una forma particulares para agregar un hipervínculo personalizado.
Requisito previo
Descargar Aspose.Slides Cloud SDK for Dotnet for inserting hyperlinks
Configure el proyecto C# con el SDK anterior para agregar un enlace a una forma
Pasos para agregar un enlace a PowerPoint con API basada en C# .NET
- Cree una instancia de SlidesApi con la clave API y el secreto para la autenticación.
- Lea el archivo de entrada en una secuencia de memoria y cárguelo
- Establecer índices de las diapositivas y formas para agregar hipervínculos (índice basado en 1)
- Crear un objeto de forma con un hipervínculo
- Update la forma en la diapositiva especificada con el hipervínculo
- Imprima la URL del hipervínculo actualizado a la consola para su verificación.
- Descargue la presentación actualizada desde la nube como una secuencia y guárdela en el disco.
Estos pasos explican cómo agregar un hipervínculo en PowerPoint con C# REST API. Puede crear una forma y agregar un hipervínculo definiendo el tipo de acción y la URL externa. Finalmente, actualice la forma de destino en la diapositiva deseada usando la forma recién creada y guarde el resultado en el disco si es necesario.
Código para insertar enlace en PowerPoint con C# Low Code API
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. | |
} | |
} | |
} |
Este código demuestra cómo insertar un hipervínculo en PowerPoint con la interfaz REST de C#. Puede configurar varias propiedades de un hipervínculo, como una bandera para habilitar/deshabilitar un hipervínculo, información sobre herramientas, historial, resaltar el clic y detener el sonido al hacer clic. Tenga en cuenta que todas estas propiedades están disponibles al pasar el cursor sobre el hipervínculo en lugar de hacer clic en él.
Este artículo nos ha enseñado a crear un hipervínculo en PowerPoint con C# Low Code API. Para agregar un SmartArt en una diapositiva, consulte el artículo sobre Agregue SmartArt a PowerPoint con la API REST de C#.