Eu estou construindo um add-in para o PowerPoint e precisa acessar os slides ou objetos Slide, ou até mesmo toda a apresentação; infelizmente, o único método que eu posso ver de fazer isso é abrir um Novo arquivo ppt. Agora eu estou tendo que recorrer ao método hacky de salvar a apresentação atual e reabri-la com o Packaging para manipular qualquer coisa (mais especificamente, eu estou tendo que SHA os objetos Slide do arquivo pptx para ver se eles mudaram - Não é ideal)
Existe alguma maneira de abrir o arquivo que está atualmente aberto no PowerPoint sem ter que IO um arquivo?
Obrigado pela ajuda, P
Respostas:
0 para resposta № 1Eu suponho que você criou um projeto de suplemento do PowerPoint (2007/2010) no VisualStudio. Em geral, você pode acessar a apresentação ativa com classe estática Globals
deste jeito:
Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex] ...
Editar: Exemplo para uso:
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
...
try
{
int numberOfSlides = Globals.ThisAddIn
.Application.ActivePresentation.Slides.Count;
if (numberOfSlides > 0)
{
// get first slide
PowerPoint.Slide firstSlide = Globals.ThisAddIn
.Application.ActivePresentation.Slides[0];
// get first shape (object) in the slide
int shapeCount = firstSlide.Shapes.Count;
if (shapeCount > 0)
{
PowerPoint.Shape firstShape = firstSlide.Shapes[0];
}
// add a label
PowerPoint.Shape label = firstSlide.Shapes.AddLabel(
Orientation: Microsoft.Office.Core
.MsoTextOrientation.msoTextOrientationHorizontal,
Left: 100,
Top: 100,
Width: 200,
Height: 100);
// write hello world with a slidenumber
label.TextFrame.TextRange.Text = "Hello World! Page: ";
label.TextFrame.TextRange.InsertSlideNumber();
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error: " + ex);
}