Siga este guia sobre como adicionar hiperlink a PowerPoint com C# REST API. Você aprenderá a inserir hiperlink automaticamente no PowerPoint com C# RESTful Service usando um Cloud SDK baseado em .NET que oferece suporte a todos os recursos avançados para trabalhar com apresentações. Ele o ajudará a selecionar um slide e uma forma específicos para adicionar um hiperlink personalizado.
Pré-requisito
Download Aspose.Slides Cloud SDK for Dotnet for inserting hyperlinks
Configure o projeto C# com o SDK acima para adicionar um link a uma forma
Etapas para adicionar um link ao PowerPoint com API baseada em C# .NET
- Instancie o SlidesApi com a chave de API e o segredo para autenticação
- Leia o arquivo de entrada em um fluxo de memória e carregue-o
- Definir índices dos slides e formas para adicionar hiperlink (índice baseado em 1)
- Crie um objeto de forma com um hiperlink
- Update a forma no slide especificado com o hiperlink
- Imprima o URL do hiperlink atualizado no console para verificação
- Baixe a apresentação atualizada da nuvem como um stream e salve-a no disco
Estas etapas explicam como adicionar hiperlink no PowerPoint com API REST C#. Você pode criar um Shape e adicionar um hiperlink definindo o tipo de ação e o URL externo. Por fim, atualize a forma de destino no slide desejado usando a forma recém-criada e salve a saída no disco, se necessário.
Código para inserir link no PowerPoint com 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. | |
} | |
} | |
} |
Este código demonstra como inserir hiperlink no PowerPoint com interface REST C#. Você pode definir várias propriedades de um hiperlink, como um sinalizador para ativar/desativar um hiperlink, dica de ferramenta, histórico, clique em destaque e parar o som ao clicar. Observe que todas essas propriedades estão disponíveis passando o mouse sobre o hiperlink em vez de clicar nele.
Este artigo nos ensinou a criar um hiperlink no PowerPoint com C# Low Code API. Para adicionar um SmartArt em um slide, consulte o artigo em Adicione SmartArt ao PowerPoint com API REST C#.