[英]How to apply margin in Presentation Document using OpenXml
I wrote code to create Presentation Document using open-xml SDK. I follow this sample code.我编写代码使用 open-xml SDK 创建演示文档。我遵循此示例代码。 MSDD Sample Code .
MSDD 示例代码。 Now i need to apply margin before starting my text.
现在我需要在开始我的文本之前应用边距。 I've tried below code but didn't get expected result.
我试过下面的代码但没有得到预期的结果。
slidePart1.Slide = new Slide(
new CommonSlideData(
new ShapeTree(
new P.NonVisualGroupShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
new P.NonVisualGroupShapeDrawingProperties(),
new ApplicationNonVisualDrawingProperties()),
new GroupShapeProperties(new A.TransformGroup()),
new P.Shape(
new P.NonVisualShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "Title 1" },
new P.NonVisualShapeDrawingProperties(new D.ShapeLocks() { NoGrouping = true }),
new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
new P.ShapeProperties(),
new P.TextBody(
new D.BodyProperties(),
new D.ListStyle(),
new A.Paragraph(new D.EndParagraphRunProperties() { Language = "en-US" }, new D.ParagraphProperties() { LeftMargin = 10 }),
//new A.Paragraph(new A.Run(new A.RunProperties() { Bold = true, Italic = true, Underline = D.TextUnderlineValues.Single }, new A.Text()
//{ Text = text })))))),
new A.Paragraph(textListWithStyle.ToArray()))))),
new ColorMapOverride(new D.MasterColorMapping()));
My generated PPT File looks like:我生成的 PPT 文件如下所示:
No left margin applied but in code i applied 10 left margin.没有应用左边距,但在代码中我应用了 10 个左边距。
It seems not so easy to add an indented paragraph using Open XML SDK. With Aspose.Slides for .NET , this can be done like this:使用 Open XML SDK 添加缩进段落似乎不是那么容易。使用Aspose.Slides for .NET ,可以这样做:
// Create a new presentation.
using var presentation = new Presentation();
// Add a text box to the first slide.
var slide = presentation.Slides[0];
var rectangle = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 20, 20, 200, 150);
// Create a new paragraph.
var paragraph = new Paragraph();
paragraph.Text = "Some text.";
// Set left margin for the paragraph.
paragraph.ParagraphFormat.MarginLeft = 10;
// Add the paragraph to the text box.
rectangle.TextFrame.Paragraphs.Add(paragraph);
// Save the presentation to PPTX format.
presentation.Save("example.pptx", SaveFormat.Pptx);
This is a paid product, but you can get a temporary license to evaluate all features of this library.这是付费产品,但您可以获得临时许可证来评估此库的所有功能。 I work as a Support Developer at Aspose.
我在 Aspose 担任支持开发人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.