我正在尝试查找或计算比例高度&使用PowerPoint演示文稿PPTX文件中图片的OpenXML SDK的宽度值。
我将图像作为
Picture = DocumentFormat.OpenXml.Presentation.Picture
我看过ShapeProperties和NonVisualPictureProperties,但却无法追踪这些值。
这是我在PowerPoint中看到的时候以编程方式获取的内容
有人能告诉我这些值隐藏在哪里吗?
由于
答案 0 :(得分:1)
检查DocumentFormat.OpenXml.Drawing
- > ShapeProperties.Transform2D.Extents
。 (Extent documentation)。在精彩的OpenXML EMU(1 in = 914400 EMU,1 cm = 360000 EMU)中,这是一个绝对大小,而不是百分比。据我所知,这是你如何设置图像比例(绝对值,而不是百分比)。
使用OpenXML SDK工具反映示例的代码:新的speadsheet,插入图像,保存。然后在openxml sdk->反映代码,ctrl + f" Transform2D"应该得到你需要的东西。例如:
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Presentation;
using DocumentFormat.OpenXml;
using A = DocumentFormat.OpenXml.Drawing;
using P14 = DocumentFormat.OpenXml.Office2010.PowerPoint;
using P15 = DocumentFormat.OpenXml.Office2013.PowerPoint;
using A14 = DocumentFormat.OpenXml.Office2010.Drawing;
using Thm15 = DocumentFormat.OpenXml.Office2013.Theme;
using Ap = DocumentFormat.OpenXml.ExtendedProperties;
using Vt = DocumentFormat.OpenXml.VariantTypes;
// Generates content of slidePart1.
private void GenerateSlidePart1Content(SlidePart slidePart1)
{
Slide slide1 = new Slide();
slide1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");
slide1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
slide1.AddNamespaceDeclaration("p", "http://schemas.openxmlformats.org/presentationml/2006/main");
CommonSlideData commonSlideData1 = new CommonSlideData();
ShapeTree shapeTree1 = new ShapeTree();
NonVisualGroupShapeProperties nonVisualGroupShapeProperties1 = new NonVisualGroupShapeProperties();
NonVisualDrawingProperties nonVisualDrawingProperties1 = new NonVisualDrawingProperties(){ Id = (UInt32Value)1U, Name = "" };
NonVisualGroupShapeDrawingProperties nonVisualGroupShapeDrawingProperties1 = new NonVisualGroupShapeDrawingProperties();
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
nonVisualGroupShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualGroupShapeProperties1.Append(nonVisualGroupShapeDrawingProperties1);
nonVisualGroupShapeProperties1.Append(applicationNonVisualDrawingProperties1);
GroupShapeProperties groupShapeProperties1 = new GroupShapeProperties();
A.TransformGroup transformGroup1 = new A.TransformGroup();
A.Offset offset1 = new A.Offset(){ X = 0L, Y = 0L };
A.Extents extents1 = new A.Extents(){ Cx = 0L, Cy = 0L };
A.ChildOffset childOffset1 = new A.ChildOffset(){ X = 0L, Y = 0L };
A.ChildExtents childExtents1 = new A.ChildExtents(){ Cx = 0L, Cy = 0L };
transformGroup1.Append(offset1);
transformGroup1.Append(extents1);
transformGroup1.Append(childOffset1);
transformGroup1.Append(childExtents1);
groupShapeProperties1.Append(transformGroup1);
Picture picture1 = new Picture();
NonVisualPictureProperties nonVisualPictureProperties1 = new NonVisualPictureProperties();
NonVisualDrawingProperties nonVisualDrawingProperties2 = new NonVisualDrawingProperties(){ Id = (UInt32Value)4U, Name = "Picture 3" };
NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 = new NonVisualPictureDrawingProperties();
A.PictureLocks pictureLocks1 = new A.PictureLocks(){ NoChangeAspect = true };
nonVisualPictureDrawingProperties1.Append(pictureLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties2 = new ApplicationNonVisualDrawingProperties();
nonVisualPictureProperties1.Append(nonVisualDrawingProperties2);
nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);
nonVisualPictureProperties1.Append(applicationNonVisualDrawingProperties2);
BlipFill blipFill1 = new BlipFill();
A.Blip blip1 = new A.Blip(){ Embed = "rId2" };
A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();
A.BlipExtension blipExtension1 = new A.BlipExtension(){ Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };
A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi(){ Val = false };
useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
blipExtension1.Append(useLocalDpi1);
blipExtensionList1.Append(blipExtension1);
blip1.Append(blipExtensionList1);
A.Stretch stretch1 = new A.Stretch();
A.FillRectangle fillRectangle1 = new A.FillRectangle();
stretch1.Append(fillRectangle1);
blipFill1.Append(blip1);
blipFill1.Append(stretch1);
ShapeProperties shapeProperties1 = new ShapeProperties();
A.Transform2D transform2D1 = new A.Transform2D();
A.Offset offset2 = new A.Offset(){ X = 1524000L, Y = 0L };
A.Extents extents2 = new A.Extents(){ Cx = 9144000L, Cy = 6858000L };
transform2D1.Append(offset2);
transform2D1.Append(extents2);
A.PresetGeometry presetGeometry1 = new A.PresetGeometry(){ Preset = A.ShapeTypeValues.Rectangle };
A.AdjustValueList adjustValueList1 = new A.AdjustValueList();
presetGeometry1.Append(adjustValueList1);
shapeProperties1.Append(transform2D1);
shapeProperties1.Append(presetGeometry1);
picture1.Append(nonVisualPictureProperties1);
picture1.Append(blipFill1);
picture1.Append(shapeProperties1);
shapeTree1.Append(nonVisualGroupShapeProperties1);
shapeTree1.Append(groupShapeProperties1);
shapeTree1.Append(picture1);
CommonSlideDataExtensionList commonSlideDataExtensionList1 = new CommonSlideDataExtensionList();
CommonSlideDataExtension commonSlideDataExtension1 = new CommonSlideDataExtension(){ Uri = "{BB962C8B-B14F-4D97-AF65-F5344CB8AC3E}" };
P14.CreationId creationId1 = new P14.CreationId(){ Val = (UInt32Value)568547621U };
creationId1.AddNamespaceDeclaration("p14", "http://schemas.microsoft.com/office/powerpoint/2010/main");
commonSlideDataExtension1.Append(creationId1);
commonSlideDataExtensionList1.Append(commonSlideDataExtension1);
commonSlideData1.Append(shapeTree1);
commonSlideData1.Append(commonSlideDataExtensionList1);
ColorMapOverride colorMapOverride1 = new ColorMapOverride();
A.MasterColorMapping masterColorMapping1 = new A.MasterColorMapping();
colorMapOverride1.Append(masterColorMapping1);
slide1.Append(commonSlideData1);
slide1.Append(colorMapOverride1);
slidePart1.Slide = slide1;
}