c# - NoTextEdit ShapeLock 不起作用 - OpenXML SDK

标签 c# openxml openxml-sdk

我正在尝试使用 OpenXML SDK 锁定 TextBox。我已经尝试过这种方法,但 TextBox NoTextEdit 不起作用。

public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
    DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();

    DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
    DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };

    DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
    Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};

    nonVisualShapeDrawingProperties1.Append(shapeLocks1);

    ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
    PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U   };

    applicationNonVisualDrawingProperties1.Append(placeholderShape1);

    nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
    nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
    nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
    DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();

    DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
    Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
    Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
    Drawing.TextShape shp = new Drawing.TextShape();

    Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
    Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
    paragraph1.Append(GenerateRun(StrText));
    paragraph1.Append(endParagraphRunProperties1);

    textBody1.Append(bodyProperties1);
    textBody1.Append(listStyle1);
    textBody1.Append(paragraph1);

    shape1.Append(nonVisualShapeProperties1);
    shape1.Append(shapeProperties1);
    shape1.Append(textBody1);
    return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{

    Drawing.Run run1 = new Drawing.Run();

    Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false  };
    runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
    Drawing.Text text1 = new Drawing.Text();
    text1.Text = StrText;
    Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
    Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();

    string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
    Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").

    solidFill2.Append(rgbColorModelHex2);
    runProperties1.Append(solidFill2);


    Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
    run1.Append(runProperties1);
    run1.Append(text1);

    return run1;

}

除了编辑之外,一切正常。 用户仍然可以通过双击来编辑文本框值。我怎样才能避免这种情况?

有什么永久的解决方案可以防止编辑吗?请帮助我找到更好的解决方案。

提前致谢

最佳答案

通过研究和与 MVP 团队的沟通,我指出没有办法保护 TextBox 不被编辑。 正如 Cindy Meister 在评论中提到的,

Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.

如果您不想更改文本,只需将其更改为图像,然后使用 NoSelection=true/1NoMove=true/1 属性锁定它。如果启用这些属性,用户将无法删除也无法更改其位置。

供您引用:https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869

关于c# - NoTextEdit ShapeLock 不起作用 - OpenXML SDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59728774/

相关文章:

C# 使用代码对程序集进行签名

c# - 缺少 App1.Pages.SetPageDetail 的默认构造函数(位置 12 :18)

c# - 如何将 C++ 结构传递给 C# DLL?

php - 将 JSON 字符串或数组转换为 Excel 文件?

c# - OpenXML 如何添加指向另一个工作表的超链接

openxml - 检索对评论 OpenXML 的引用

c# - 创建新的空 Word 文档

c# - OpenXML - 不从一行中读取空白单元格 C#

c# - 使用自定义流 (IEnumerable<T>)

c# - YASR - 另一个搜索和替换问题