确实有几种方法可以做到这一点。让我们开始吧,如果您打算做一个可以执行相同功能的加载项,您可以在以下位置找到有关如何创建加载项的更多信息:https ://netoffice.codeplex.com/
现在,让我们回到你的主要问题。一个简单的方法是在 C# 中。
//http://netoffice.codeplex.com/discussions/277323
/// Loop through all our sheets in Excel in order to make the replacement
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
/// Select current sheet
sheet.Activate();
workSheet = (Excel.Worksheet)xlsApp.Worksheets[worksheetnumber];
//Console.WriteLine(workSheet.Name);
foreach (Excel.Range cell in workSheet.UsedRange)
{
}
}
这段代码允许您遍历所有工作表并检查使用的单元格。
在您的情况下,您希望考虑一些特定的范围。
sheet.UsedRange.Copy(Missing.Value);
您可以将其保存到变量中,并逐行读取并解释其结果。
这是 Excel 部分,现在我们去 Powerpoint 部分。如何计划创建您的 Powerpoint,您要存储哪些信息,要显示,每张幻灯片图片?每张幻灯片有几张照片?您可以做的是,创建您的模板 Powerpoint 并循环浏览它
foreach (PowerPoint.Slide slide in presentation.Slides)
{
slide.Select();
slide.Shapes.AddPicture(temporaryFilePath + ".bmp", MsoTriState.msoTrue, MsoTriState.msoTrue, pptleft, ppttop, pptwidth, pptheight);
}
这实际上会在每张幻灯片上添加一张图片。如果你想自己创建一个新的幻灯片,你必须定义一个新的对象,要么是表格,要么是图片,不管是概念。
PowerPoint.Table objTable = null;
objTable = presentation.Slides[slide.SlideIndex].Shapes.AddTable(amountrowsshown, pptshape.Table.Columns.Count, topsize, leftsize, slide.Master.Width - widthsize, slide.Master.Height - heightsize).Table;
presentation.Slides.Add(slide.SlideIndex + newaddslidecounter, NetOffice.PowerPointApi.Enums.PpSlideLayout.ppLayoutClipArtAndVerticalText);
到目前为止,我们已经了解了如何让 Excel 使用范围,现在,您的工作将应用于您想要使用的特定范围。您知道如何遍历所有幻灯片以及如何在需要时添加新幻灯片。缺少的部分是保存 Excel 和 Powerpoint。
presentation.SaveAs("myfile.pptx");
presentation.Close();
ppApp.Quit();
workbook.SaveAs("myfile.xlsx");
workbook.Close();
xlsApp.Quit();