C#将PPT形状(msoPicture)保存为带有Office.Interop的图像

时间:2017-02-24 15:41:44

标签: c# powerpoint office-interop

我有一张带有多张图像的PPT幻灯片。我正在遍历每个幻灯片和每个形状。我想将msoPicture类型的每个形状保存为图像:

            foreach (PPT.Slide slide in pptDoc.Slides)
            {
                foreach (PPT.Shape shape in slide.Shapes)
                {
                    if (shape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                    {

                        Image img;
                        //???? Save shape as image
                        img.Save(filename);
                    }
                }
            }

1 个答案:

答案 0 :(得分:1)

您可以使用Shape.Export() method从单个形状创建图像。

例如:

DateTime dateTest = DateTime.ParseExact("02/17/2017 10:10:10", "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

using (FileStream fs = new FileStream(@"C:\temp\test.xlsx", FileMode.Create, FileAccess.Write))
{
    IWorkbook workbook = new XSSFWorkbook();
    ISheet sheet = workbook.CreateSheet("sheet");

    IRow row = sheet.CreateRow(0);

    ICell cell = row.CreateCell(0);
    ICellStyle cellStyle = workbook.CreateCellStyle();
    cellStyle.DataFormat = workbook.CreateDataFormat().GetFormat("MM/dd/yy"); 
    cell.CellStyle = cellStyle;
    cell.SetCellValue(dateTest);

    workbook.Write(fs);
}