certificate.pptx中有一张幻灯片。 这是一份证书表格,应打印100页以上。 所以我用InsertFromFile复制了100张幻灯片 旋转每张幻灯片并更改名称,专业和时期。 下面是代码。我想提高效率。 有办法吗? 预先感谢您的回答。
公共静态无效ReadSlide() {
string filePath = @"C:\certificate.pptx";
Application pptApplication = new Application();
Presentation createPPTX = pptApplication.Presentations.Add(MsoTriState.msoTrue);
Slides newSlides = createPPTX.Slides;
for (int i = 0; i < 100; ++i)
{
newSlides.InsertFromFile(filePath, 0, 1);
}
for (int j = 1; j <= 100; ++j)
{
for (int i = 1; i <= newSlides[j].Shapes.Count; ++i)
{
var shape = (Microsoft.Office.Interop.PowerPoint.Shape)newSlides[j].Shapes[i];
if (shape.HasTextFrame == MsoTriState.msoTrue)
{
TextRange textRange;
string text;
if (shape.TextFrame.HasText == MsoTriState.msoTrue)
{
textRange = shape.TextFrame.TextRange;
text = textRange.Text;
text = text.Replace("Major", tableDatas[j].Major);
text = text.Replace("Id", tableDatas[j].Id);
text = text.Replace("Name", tableDatas[j].Name);
text = text.Replace("Date", tableDatas[j].Date);
text = text.Replace("Today", Today);
shape.TextFrame.TextRange.Text = text;
//readSlide.Shapes[i] = shape;
newSlides[j].Shapes[i].TextFrame.TextRange.Text = text;
}
}
}
}
createPPTX.SaveAs(@"C:\sample.pptx", PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
createPPTX.Close();
pptApplication.Quit();
}