# Primeiros passos com o IronPPT
## IronPowerPoint: Biblioteca PowerPoint for .NET
**IronPPT** é uma biblioteca para PowerPoint desenvolvida pela Iron Software. Destaca-se por oferecer funcionalidades robustas para trabalhar com apresentações do PowerPoint em aplicações .NET .
- Carregar, manipular e salvar apresentações do PowerPoint. Trabalhe facilmente com arquivos .pptx e .ppt.
- Configuração de slides: Configure o tamanho, a orientação, a cor de fundo e o layout dos slides.
- Texto: Manipular conteúdo de texto, estilos, divisão, anexação de texto e adição de caixas de texto.
- Estilo do texto: Gerencie a família da fonte, tamanho, cor, negrito, itálico, sublinhado e alinhamento.
- Formas: Adicione e manipule formas, incluindo definir tamanho, posição, tipo e rotação.
- Imagens: Insira imagens nos slides com opções de dimensionamento, alinhamento e posicionamento.
<div class="hsg-featured-snippet">
<h2>Biblioteca C# para apresentações em PowerPoint for .NET</h2>
<ol>
<li><a class="js-modal-open" data-modal-id="trial-license-after-download" href="https://www.nuget.org/packages/IronPPT/">Baixe a biblioteca C# para manipulação de apresentações do PowerPoint.</a></li>
<li>Criar e modificar documentos .pptx ou .ppt</li>
<li>Gerencie as propriedades dos slides, como ordem, visibilidade e rotação do conteúdo.</li>
<li>Adicione elementos aos slides, como texto, imagens e formas.</li>
<li>Estilize o conteúdo com facilidade.</li>
</ol>
</div>
## Instalação
### Biblioteca IronPPT
A instalação do IronPPT é rápida e simples. Adicione o pacote usando o seguinte método:
```shell
:ProductInstall
```
Alternativamente, você pode baixá-lo diretamente do [site oficial do IronPPT no NuGet](https://www.nuget.org/packages/IronPPT) .
Após a instalação, simplesmente inclua `using IronPPT;` no topo do seu código C# para começar.
## Aplicando a chave de licença
Para usar o IronPPT, aplique uma licença válida ou uma chave de avaliação definindo a propriedade **LicenseKey** . Adicione o seguinte código imediatamente após a declaração de importação e antes de chamar qualquer método do IronPPT:
```csharp
/// <summary>
/// This code sets the license key for the IronPPT library.
/// Ensure you have the correct namespace access by installing the IronPPT NuGet package
/// and adjust the license key appropriately for your use case.
/// </summary>
using System; // Required for Console output
using IronPPT; // Ensure the IronPPT library is referenced in your project.
namespace IronPPTApplication
{
class Program
{
public static void Main(string[] args)
{
// Calling the method to set the IronPPT license key.
SetIronPPTLicense();
}
/// <summary>
/// Sets the license key for the IronPPT library to unlock its full features.
/// </summary>
private static void SetIronPPTLicense()
{
// Correctly setting the license for the IronPPT library.
// Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01";
// Inform the user that the license key has been set.
Console.WriteLine("IronPPT license key has been set.");
}
}
}
```
## Exemplos de código
Vamos explorar alguns exemplos de código e os recursos disponíveis.
## Criar arquivo PowerPoint
Crie a apresentação PowerPoint instanciando a classe `PresentationDocument` usando um de seus construtores. Use os métodos `AddSlide` e `AddText` para adicionar slides e texto, respectivamente. Depois disso, use o método `Save` para exportar a apresentação PowerPoint.
```csharp
using IronPPT;
// This code demonstrates the creation of a PowerPoint presentation and saving it as a file.
// Create a new PowerPoint presentation document
var document = new PresentationDocument();
// Create a new slide object
var slide = new Slide();
// Add text content to the slide
slide.AddText("Hello!");
// Add the newly created slide with text to the document
document.AddSlide(slide);
// Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx");
```
## Adicionar forma
Você pode usar o método `AddShape` de um objeto de slide para adicionar formas. Várias propriedades da forma podem ser configuradas, como cor de preenchimento, cor do contorno, posição, ângulo, tipo e mais.
```csharp
using IronPPT;
using IronPPT.Drawing; // Assuming this namespace contains `Shape` and `Color` classes
using IronPPT.Enums; // Assuming this namespace contains the `ShapeType` enum
// Load a PowerPoint presentation from the specified file
var document = new PresentationDocument("output.pptx");
// Create and configure a new shape, in this case, a triangle
Shape shape = new Shape
{
Name = "triangle", // Assign a name to the shape
Type = ShapeType.Triangle, // Set the shape type to Triangle
Width = 100, // Set the width of the shape
Height = 100, // Assumed height for the shape, should be set for visibility
FillColor = new Color("#444444"), // Set the fill color of the shape
OutlineColor = Color.Black, // Set the outline color to black
Position = new System.Drawing.Point(200, 200) // Set the position of the shape
};
// Ensure that the slides array has at least one slide to add the shape to
if (document.Slides.Count > 0)
{
// Add the shape to the first slide
document.Slides[0].AddShape(shape);
}
else
{
// If there are no slides, handle the error or add a slide
document.Slides.Add(new Slide()); // Assuming there's a way to add new slides
document.Slides[0].AddShape(shape); // Add the shape to the newly added slide
}
// Export the PowerPoint presentation to a new file
document.Save("addShape.pptx");
```
## Adicionar imagem
Adicionar uma imagem a qualquer slide também é uma tarefa simples. O exemplo de código abaixo adiciona uma imagem ao primeiro slide, modifica as propriedades da imagem, como posição, ângulo, nome, largura e altura, e então salva a apresentação atualizada como um arquivo .pptx.
```csharp
using IronPPT;
using System.Drawing;
// This code demonstrates creating a new PowerPoint presentation, adding an image to it,
// modifying the image's properties, and exporting the presentation.
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Ensure there's at least one slide in the presentation
// Create the first slide if it doesn't exist yet
if (document.Slides.Count == 0)
{
document.Slides.Add();
}
// Initialize an Image object
// Load an image from a file specified by the file path
// Ensure that "sample.png" exists at the specified path
Image image = new Image();
image.LoadFromFile("sample.png");
// Add the image to the first slide of the presentation
var newImage = document.Slides[0].AddImage(image);
// Edit the image's properties
// Set the position of the image using X and Y coordinates
newImage.Position = new Point(200, 200);
// Set the rotation angle of the image in degrees
newImage.Angle = 45;
// Set a name for the image, which can be useful for identification
newImage.Name = "new image";
// Set the dimensions of the image
newImage.Width = 150;
newImage.Height = 150;
// Export the PowerPoint presentation with the new image
document.Save("addImage.pptx");
```
## Licenciamento e suporte disponíveis
**IronPPT** é uma biblioteca comercial, mas [licenças de avaliação gratuitas](trial-license) estão disponíveis.
Para obter mais detalhes sobre a Iron Software, visite nosso site em:[https://ironsoftware.com/](https://ironsoftware.com/) . Se precisar de ajuda ou tiver alguma dúvida, [entre em contato com nossa equipe](https://www.ironsoftware.com/csharp/ppt/#live-chat-support) .
### Suporte do Iron Software
Para assistência geral e questões técnicas, entre em contato conosco pelo e-mail:[support@ironsoftware.com](mailto:support@ironsoftware.com) .
IronPPT é uma biblioteca para PowerPoint desenvolvida pela Iron Software. Destaca-se por oferecer funcionalidades robustas para trabalhar com apresentações do PowerPoint em aplicações .NET .
Carregar, manipular e salvar apresentações do PowerPoint. Trabalhe facilmente com arquivos .pptx e .ppt.
Configuração de slides: Configure o tamanho, a orientação, a cor de fundo e o layout dos slides.
Texto: Manipular conteúdo de texto, estilos, divisão, anexação de texto e adição de caixas de texto.
Estilo do texto: Gerencie a família da fonte, tamanho, cor, negrito, itálico, sublinhado e alinhamento.
Formas: Adicione e manipule formas, incluindo definir tamanho, posição, tipo e rotação.
Imagens: Insira imagens nos slides com opções de dimensionamento, alinhamento e posicionamento.
Biblioteca C# para apresentações em PowerPoint for .NET
Após a instalação, simplesmente inclua using IronPPT; no topo do seu código C# para começar.
Aplicando a chave de licença
Para usar o IronPPT, aplique uma licença válida ou uma chave de avaliação definindo a propriedade LicenseKey . Adicione o seguinte código imediatamente após a declaração de importação e antes de chamar qualquer método do IronPPT:
/// <summary>/// This code sets the license key for the IronPPT library./// Ensure you have the correct namespace access by installing the IronPPT NuGet package/// and adjust the license key appropriately for your use case./// </summary>using System; // Required for Console outputusing IronPPT; // Ensure the IronPPT library is referenced in your project.namespace IronPPTApplication{ class Program { public static voidMain(string[] args) { // Calling the method to set the IronPPT license key.SetIronPPTLicense(); } /// <summary> /// Sets the license key for the IronPPT library to unlock its full features. /// </summary> private static voidSetIronPPTLicense() { // Correctly setting the license for the IronPPT library. // Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01"; // Inform the user that the license key has been set.Console.WriteLine("IronPPT license key has been set."); } }}
/// <summary>
/// This code sets the license key for the IronPPT library.
/// Ensure you have the correct namespace access by installing the IronPPT NuGet package
/// and adjust the license key appropriately for your use case.
/// </summary>
using System; // Required for Console output
using IronPPT; // Ensure the IronPPT library is referenced in your project.
namespace IronPPTApplication
{
class Program
{
public static void Main(string[] args)
{
// Calling the method to set the IronPPT license key.
SetIronPPTLicense();
}
/// <summary>
/// Sets the license key for the IronPPT library to unlock its full features.
/// </summary>
private static void SetIronPPTLicense()
{
// Correctly setting the license for the IronPPT library.
// Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01";
// Inform the user that the license key has been set.
Console.WriteLine("IronPPT license key has been set.");
}
}
}
''' <summary>''' This code sets the license key for the IronPPT library.''' Ensure you have the correct namespace access by installing the IronPPT NuGet package''' and adjust the license key appropriately for your use case.''' </summary>ImportsSystem' Required for Console outputImportsIronPPT' Ensure the IronPPT library is referenced in your project.NamespaceIronPPTApplicationFriend Class Program PublicShared Sub Main(ByVal args() AsString) ' Calling the method to set the IronPPT license key.SetIronPPTLicense() End Sub ''' <summary> ''' Sets the license key for the IronPPT library to unlock its full features. ''' </summary> PrivateShared Sub SetIronPPTLicense() ' Correctly setting the license for the IronPPT library. ' Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01" ' Inform the user that the license key has been set.Console.WriteLine("IronPPT license key has been set.") End Sub End ClassEndNamespace
''' <summary>
''' This code sets the license key for the IronPPT library.
''' Ensure you have the correct namespace access by installing the IronPPT NuGet package
''' and adjust the license key appropriately for your use case.
''' </summary>
Imports System ' Required for Console output
Imports IronPPT ' Ensure the IronPPT library is referenced in your project.
Namespace IronPPTApplication
Friend Class Program
Public Shared Sub Main(ByVal args() As String)
' Calling the method to set the IronPPT license key.
SetIronPPTLicense()
End Sub
''' <summary>
''' Sets the license key for the IronPPT library to unlock its full features.
''' </summary>
Private Shared Sub SetIronPPTLicense()
' Correctly setting the license for the IronPPT library.
' Replace "IRONPPT.MYLICENSE.KEY.1EF01" with your actual key.
IronPPT.License.LicenseKey = "IRONPPT.MYLICENSE.KEY.1EF01"
' Inform the user that the license key has been set.
Console.WriteLine("IronPPT license key has been set.")
End Sub
End Class
End Namespace
Exemplos de código
Vamos explorar alguns exemplos de código e os recursos disponíveis.
Criar arquivo PowerPoint
Crie a apresentação PowerPoint instanciando a classe PresentationDocument usando um de seus construtores. Use os métodos AddSlide e AddText para adicionar slides e texto, respectivamente. Depois disso, use o método Save para exportar a apresentação PowerPoint.
using IronPPT;// This code demonstrates the creation of a PowerPoint presentation and saving it as a file.// Create a new PowerPoint presentation documentvar document = new PresentationDocument();// Create a new slide objectvar slide = new Slide();// Add text content to the slideslide.AddText("Hello!");// Add the newly created slide with text to the documentdocument.AddSlide(slide);// Export the PowerPoint presentation to a file named "output.pptx"document.Save("output.pptx");
using IronPPT;
// This code demonstrates the creation of a PowerPoint presentation and saving it as a file.
// Create a new PowerPoint presentation document
var document = new PresentationDocument();
// Create a new slide object
var slide = new Slide();
// Add text content to the slide
slide.AddText("Hello!");
// Add the newly created slide with text to the document
document.AddSlide(slide);
// Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx");
ImportsIronPPT' This code demonstrates the creation of a PowerPoint presentation and saving it as a file.' Create a new PowerPoint presentation documentPrivate document = New PresentationDocument()' Create a new slide objectPrivate slide = New Slide()' Add text content to the slideslide.AddText("Hello!")' Add the newly created slide with text to the documentdocument.AddSlide(slide)' Export the PowerPoint presentation to a file named "output.pptx"document.Save("output.pptx")
Imports IronPPT
' This code demonstrates the creation of a PowerPoint presentation and saving it as a file.
' Create a new PowerPoint presentation document
Private document = New PresentationDocument()
' Create a new slide object
Private slide = New Slide()
' Add text content to the slide
slide.AddText("Hello!")
' Add the newly created slide with text to the document
document.AddSlide(slide)
' Export the PowerPoint presentation to a file named "output.pptx"
document.Save("output.pptx")
Adicionar forma
Você pode usar o método AddShape de um objeto de slide para adicionar formas. Várias propriedades da forma podem ser configuradas, como cor de preenchimento, cor do contorno, posição, ângulo, tipo e mais.
using IronPPT;using IronPPT.Drawing; // Assuming this namespace contains `Shape` and `Color` classesusing IronPPT.Enums; // Assuming this namespace contains the `ShapeType` enum// Load a PowerPoint presentation from the specified filevar document = new PresentationDocument("output.pptx");// Create and configure a new shape, in this case, a triangleShape shape = new Shape{Name = "triangle", // Assign a name to the shapeType = ShapeType.Triangle, // Set the shape type to TriangleWidth = 100, // Set the width of the shapeHeight = 100, // Assumed height for the shape, should be set for visibilityFillColor = new Color("#444444"), // Set the fill color of the shapeOutlineColor = Color.Black, // Set the outline color to blackPosition = new System.Drawing.Point(200, 200) // Set the position of the shape};// Ensure that the slides array has at least one slide to add the shape toif (document.Slides.Count > 0){ // Add the shape to the first slide document.Slides[0].AddShape(shape);}else{ // If there are no slides, handle the error or add a slide document.Slides.Add(new Slide()); // Assuming there's a way to add new slides document.Slides[0].AddShape(shape); // Add the shape to the newly added slide}// Export the PowerPoint presentation to a new filedocument.Save("addShape.pptx");
using IronPPT;
using IronPPT.Drawing; // Assuming this namespace contains `Shape` and `Color` classes
using IronPPT.Enums; // Assuming this namespace contains the `ShapeType` enum
// Load a PowerPoint presentation from the specified file
var document = new PresentationDocument("output.pptx");
// Create and configure a new shape, in this case, a triangle
Shape shape = new Shape
{
Name = "triangle", // Assign a name to the shape
Type = ShapeType.Triangle, // Set the shape type to Triangle
Width = 100, // Set the width of the shape
Height = 100, // Assumed height for the shape, should be set for visibility
FillColor = new Color("#444444"), // Set the fill color of the shape
OutlineColor = Color.Black, // Set the outline color to black
Position = new System.Drawing.Point(200, 200) // Set the position of the shape
};
// Ensure that the slides array has at least one slide to add the shape to
if (document.Slides.Count > 0)
{
// Add the shape to the first slide
document.Slides[0].AddShape(shape);
}
else
{
// If there are no slides, handle the error or add a slide
document.Slides.Add(new Slide()); // Assuming there's a way to add new slides
document.Slides[0].AddShape(shape); // Add the shape to the newly added slide
}
// Export the PowerPoint presentation to a new file
document.Save("addShape.pptx");
ImportsIronPPTImportsIronPPT.Drawing' Assuming this namespace contains `Shape` and `Color` classesImportsIronPPT.Enums' Assuming this namespace contains the `ShapeType` enum' Load a PowerPoint presentation from the specified filePrivate document = New PresentationDocument("output.pptx")' Create and configure a new shape, in this case, a trianglePrivate shape As New ShapeWith { .Name = "triangle", .Type = ShapeType.Triangle, .Width = 100, .Height = 100, .FillColor = New Color("#444444"), .OutlineColor = Color.Black, .Position = New System.Drawing.Point(200, 200)}' Ensure that the slides array has at least one slide to add the shape toIf document.Slides.Count > 0 Then ' Add the shape to the first slide document.Slides(0).AddShape(shape)Else ' If there are no slides, handle the error or add a slide document.Slides.Add(New Slide()) ' Assuming there's a way to add new slides document.Slides(0).AddShape(shape) ' Add the shape to the newly added slideEnd If' Export the PowerPoint presentation to a new filedocument.Save("addShape.pptx")
Imports IronPPT
Imports IronPPT.Drawing ' Assuming this namespace contains `Shape` and `Color` classes
Imports IronPPT.Enums ' Assuming this namespace contains the `ShapeType` enum
' Load a PowerPoint presentation from the specified file
Private document = New PresentationDocument("output.pptx")
' Create and configure a new shape, in this case, a triangle
Private shape As New Shape With {
.Name = "triangle",
.Type = ShapeType.Triangle,
.Width = 100,
.Height = 100,
.FillColor = New Color("#444444"),
.OutlineColor = Color.Black,
.Position = New System.Drawing.Point(200, 200)
}
' Ensure that the slides array has at least one slide to add the shape to
If document.Slides.Count > 0 Then
' Add the shape to the first slide
document.Slides(0).AddShape(shape)
Else
' If there are no slides, handle the error or add a slide
document.Slides.Add(New Slide()) ' Assuming there's a way to add new slides
document.Slides(0).AddShape(shape) ' Add the shape to the newly added slide
End If
' Export the PowerPoint presentation to a new file
document.Save("addShape.pptx")
Adicionar imagem
Adicionar uma imagem a qualquer slide também é uma tarefa simples. O exemplo de código abaixo adiciona uma imagem ao primeiro slide, modifica as propriedades da imagem, como posição, ângulo, nome, largura e altura, e então salva a apresentação atualizada como um arquivo .pptx.
using IronPPT;using System.Drawing;// This code demonstrates creating a new PowerPoint presentation, adding an image to it,// modifying the image's properties, and exporting the presentation.// Create a new PowerPoint presentationvar document = new PresentationDocument();// Ensure there's at least one slide in the presentation// Create the first slide if it doesn't exist yetif (document.Slides.Count == 0){ document.Slides.Add();}// Initialize an Image object// Load an image from a file specified by the file path// Ensure that "sample.png" exists at the specified pathImage image = new Image(); image.LoadFromFile("sample.png");// Add the image to the first slide of the presentationvar newImage = document.Slides[0].AddImage(image);// Edit the image's properties// Set the position of the image using X and Y coordinatesnewImage.Position = new Point(200, 200);// Set the rotation angle of the image in degreesnewImage.Angle = 45;// Set a name for the image, which can be useful for identificationnewImage.Name = "new image";// Set the dimensions of the imagenewImage.Width = 150;newImage.Height = 150;// Export the PowerPoint presentation with the new imagedocument.Save("addImage.pptx");
using IronPPT;
using System.Drawing;
// This code demonstrates creating a new PowerPoint presentation, adding an image to it,
// modifying the image's properties, and exporting the presentation.
// Create a new PowerPoint presentation
var document = new PresentationDocument();
// Ensure there's at least one slide in the presentation
// Create the first slide if it doesn't exist yet
if (document.Slides.Count == 0)
{
document.Slides.Add();
}
// Initialize an Image object
// Load an image from a file specified by the file path
// Ensure that "sample.png" exists at the specified path
Image image = new Image();
image.LoadFromFile("sample.png");
// Add the image to the first slide of the presentation
var newImage = document.Slides[0].AddImage(image);
// Edit the image's properties
// Set the position of the image using X and Y coordinates
newImage.Position = new Point(200, 200);
// Set the rotation angle of the image in degrees
newImage.Angle = 45;
// Set a name for the image, which can be useful for identification
newImage.Name = "new image";
// Set the dimensions of the image
newImage.Width = 150;
newImage.Height = 150;
// Export the PowerPoint presentation with the new image
document.Save("addImage.pptx");
ImportsIronPPTImportsSystem.Drawing' This code demonstrates creating a new PowerPoint presentation, adding an image to it,' modifying the image's properties, and exporting the presentation.' Create a new PowerPoint presentationPrivate document = New PresentationDocument()' Ensure there's at least one slide in the presentation' Create the first slide if it doesn't exist yetIf document.Slides.Count = 0 Then document.Slides.Add()End If' Initialize an Image object' Load an image from a file specified by the file path' Ensure that "sample.png" exists at the specified pathDim image As New Image()image.LoadFromFile("sample.png")' Add the image to the first slide of the presentationDim newImage = document.Slides(0).AddImage(image)' Edit the image's properties' Set the position of the image using X and Y coordinatesnewImage.Position = New Point(200, 200)' Set the rotation angle of the image in degreesnewImage.Angle = 45' Set a name for the image, which can be useful for identificationnewImage.Name = "new image"' Set the dimensions of the imagenewImage.Width = 150newImage.Height = 150' Export the PowerPoint presentation with the new imagedocument.Save("addImage.pptx")
Imports IronPPT
Imports System.Drawing
' This code demonstrates creating a new PowerPoint presentation, adding an image to it,
' modifying the image's properties, and exporting the presentation.
' Create a new PowerPoint presentation
Private document = New PresentationDocument()
' Ensure there's at least one slide in the presentation
' Create the first slide if it doesn't exist yet
If document.Slides.Count = 0 Then
document.Slides.Add()
End If
' Initialize an Image object
' Load an image from a file specified by the file path
' Ensure that "sample.png" exists at the specified path
Dim image As New Image()
image.LoadFromFile("sample.png")
' Add the image to the first slide of the presentation
Dim newImage = document.Slides(0).AddImage(image)
' Edit the image's properties
' Set the position of the image using X and Y coordinates
newImage.Position = New Point(200, 200)
' Set the rotation angle of the image in degrees
newImage.Angle = 45
' Set a name for the image, which can be useful for identification
newImage.Name = "new image"
' Set the dimensions of the image
newImage.Width = 150
newImage.Height = 150
' Export the PowerPoint presentation with the new image
document.Save("addImage.pptx")
Curtis Chau é bacharel em Ciência da Computação (Universidade Carleton) e se especializa em desenvolvimento front-end, com experiência em Node.js, TypeScript, JavaScript e React. Apaixonado por criar interfaces de usuário intuitivas e esteticamente agradáveis, Curtis gosta de trabalhar com frameworks modernos e criar manuais bem estruturados e visualmente atraentes.