Ikuti panduan ini tentang cara menambahkan hyperlink ke PowerPoint dengan C# REST API. Anda akan belajar menyisipkan hyperlink di PowerPoint secara otomatis dengan C# RESTful Service menggunakan Cloud SDK berbasis .NET yang mendukung semua fitur lanjutan untuk bekerja dengan presentasi. Ini akan membantu Anda dalam memilih slide dan bentuk tertentu untuk menambahkan hyperlink khusus.
Prasyarat
Unduh Aspose.Slides Cloud SDK for Dotnet for inserting hyperlinks
Siapkan proyek C# dengan SDK di atas untuk menambahkan tautan ke bentuk
Langkah-langkah Menambahkan Tautan ke PowerPoint dengan API berbasis C# .NET
- Buat instance SlidesApi dengan kunci API dan rahasia untuk autentikasi
- Baca file input ke dalam aliran memori dan unggah
- Mengatur indeks slide dan bentuk untuk menambahkan hyperlink (indeks berbasis 1)
- Buat objek bentuk dengan hyperlink
- Update bentuk pada slide yang ditentukan dengan hyperlink
- Cetak URL hyperlink yang diperbarui ke konsol untuk verifikasi
- Unduh presentasi yang diperbarui dari cloud sebagai aliran dan simpan di disk
Langkah-langkah ini menjelaskan cara menambahkan hyperlink di PowerPoint dengan C# REST API. Anda dapat membuat Bentuk dan menambahkan hyperlink dengan menentukan jenis tindakan dan URL eksternal. Terakhir, perbarui bentuk target pada slide yang diinginkan menggunakan bentuk yang baru dibuat dan simpan hasilnya pada disk jika diperlukan.
Kode untuk Menyisipkan Tautan di PowerPoint dengan 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. | |
} | |
} | |
} |
Kode ini menunjukkan cara menyisipkan hyperlink di PowerPoint dengan C# REST Interface. Anda dapat mengatur berbagai properti hyperlink seperti tanda untuk mengaktifkan/menonaktifkan hyperlink, tooltip, riwayat, sorot klik, dan menghentikan suara saat klik. Perhatikan bahwa semua properti ini tersedia dengan mengarahkan kursor ke hyperlink, bukan mengkliknya.
Artikel ini telah mengajarkan kita untuk membuat hyperlink di PowerPoint dengan C# Low Code API. Untuk menambahkan SmartArt di slide, lihat artikel di Tambahkan SmartArt ke PowerPoint dengan C# REST API.