// Creates an Endnotes instance and adds its children.
        public static Endnotes CreateDefaultEndnotes()
        {
            Endnotes endnotes1 = new Endnotes()
            {
                MCAttributes = new MarkupCompatibilityAttributes()
                {
                    Ignorable = "w14 w15 w16se w16cid w16 w16cex wp14"
                }
            };

            endnotes1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
            endnotes1.AddNamespaceDeclaration("cx", "http://schemas.microsoft.com/office/drawing/2014/chartex");
            endnotes1.AddNamespaceDeclaration("cx1", "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex");
            endnotes1.AddNamespaceDeclaration("cx2", "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex");
            endnotes1.AddNamespaceDeclaration("cx3", "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex");
            endnotes1.AddNamespaceDeclaration("cx4", "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex");
            endnotes1.AddNamespaceDeclaration("cx5", "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex");
            endnotes1.AddNamespaceDeclaration("cx6", "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex");
            endnotes1.AddNamespaceDeclaration("cx7", "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex");
            endnotes1.AddNamespaceDeclaration("cx8", "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex");
            endnotes1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
            endnotes1.AddNamespaceDeclaration("aink", "http://schemas.microsoft.com/office/drawing/2016/ink");
            endnotes1.AddNamespaceDeclaration("am3d", "http://schemas.microsoft.com/office/drawing/2017/model3d");
            endnotes1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
            endnotes1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
            endnotes1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
            endnotes1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
            endnotes1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
            endnotes1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
            endnotes1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
            endnotes1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            endnotes1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
            endnotes1.AddNamespaceDeclaration("w15", "http://schemas.microsoft.com/office/word/2012/wordml");
            endnotes1.AddNamespaceDeclaration("w16cex", "http://schemas.microsoft.com/office/word/2018/wordml/cex");
            endnotes1.AddNamespaceDeclaration("w16cid", "http://schemas.microsoft.com/office/word/2016/wordml/cid");
            endnotes1.AddNamespaceDeclaration("w16", "http://schemas.microsoft.com/office/word/2018/wordml");
            endnotes1.AddNamespaceDeclaration("w16se", "http://schemas.microsoft.com/office/word/2015/wordml/symex");
            endnotes1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
            endnotes1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
            endnotes1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
            endnotes1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");

            Endnote endnote1 = new Endnote()
            {
                Type = FootnoteEndnoteValues.Separator, Id = -1
            };
            string rsidAdditionGuid = OfficeHelpers.CreateNewRsid();
            string rsidPropsGuid    = OfficeHelpers.CreateNewRsid();

            Paragraph paragraph1 = new Paragraph()
            {
                RsidParagraphAddition = rsidAdditionGuid, RsidParagraphProperties = rsidPropsGuid, RsidRunAdditionDefault = rsidAdditionGuid, ParagraphId = OfficeHelpers.CreateNewRsid(), TextId = "77777777"
            };

            ParagraphProperties paragraphProperties1 = new ParagraphProperties();
            SpacingBetweenLines spacingBetweenLines1 = new SpacingBetweenLines()
            {
                After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto
            };

            paragraphProperties1.Append(spacingBetweenLines1);

            Run           run1           = new Run();
            SeparatorMark separatorMark1 = new SeparatorMark();

            run1.Append(separatorMark1);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);

            endnote1.Append(paragraph1);

            Endnote endnote2 = new Endnote()
            {
                Type = FootnoteEndnoteValues.ContinuationSeparator, Id = 0
            };

            Paragraph paragraph2 = new Paragraph()
            {
                RsidParagraphAddition = rsidAdditionGuid, RsidParagraphProperties = rsidPropsGuid, RsidRunAdditionDefault = rsidAdditionGuid, ParagraphId = OfficeHelpers.CreateNewRsid(), TextId = "77777777"
            };

            ParagraphProperties paragraphProperties2 = new ParagraphProperties();
            SpacingBetweenLines spacingBetweenLines2 = new SpacingBetweenLines()
            {
                After = "0", Line = "240", LineRule = LineSpacingRuleValues.Auto
            };

            paragraphProperties2.Append(spacingBetweenLines2);

            Run run2 = new Run();
            ContinuationSeparatorMark continuationSeparatorMark1 = new ContinuationSeparatorMark();

            run2.Append(continuationSeparatorMark1);

            paragraph2.Append(paragraphProperties2);
            paragraph2.Append(run2);

            endnote2.Append(paragraph2);

            endnotes1.Append(endnote1);
            endnotes1.Append(endnote2);
            return(endnotes1);
        }
Пример #2
0
        private void BtnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor = Cursors.WaitCursor;

                bool   value;
                int    num;
                double number;

                switch (CbType.SelectedItem)
                {
                case "YesNo":
                    if (rdoNo.Checked)
                    {
                        value = false;
                    }
                    else
                    {
                        value = true;
                    }

                    if (isBatch == true)
                    {
                        foreach (string f in bFiles)
                        {
                            OfficeHelpers.SetCustomProperty(f, TxtName.Text, value, OfficeHelpers.PropertyTypes.YesNo, fType);
                            LoggingHelper.Log(f + StringResources.customPropSaved);
                        }
                    }
                    else
                    {
                        OfficeHelpers.SetCustomProperty(fName, TxtName.Text, value, OfficeHelpers.PropertyTypes.YesNo, fType);
                    }

                    break;

                case "Date":
                    if (isBatch == true)
                    {
                        foreach (string f in bFiles)
                        {
                            OfficeHelpers.SetCustomProperty(f, TxtName.Text, DtDateTime.Value, OfficeHelpers.PropertyTypes.DateTime, fType);
                            LoggingHelper.Log(f + StringResources.customPropSaved);
                        }
                    }
                    else
                    {
                        OfficeHelpers.SetCustomProperty(fName, TxtName.Text, DtDateTime.Value, OfficeHelpers.PropertyTypes.DateTime, fType);
                    }

                    break;

                case "Number":
                    if (Int32.TryParse(TxtBoxNumber.Text, out num))
                    {
                        if (isBatch == true)
                        {
                            foreach (string f in bFiles)
                            {
                                OfficeHelpers.SetCustomProperty(f, TxtName.Text, num, OfficeHelpers.PropertyTypes.NumberInteger, fType);
                                LoggingHelper.Log(f + StringResources.customPropSaved);
                            }
                        }
                        else
                        {
                            OfficeHelpers.SetCustomProperty(fName, TxtName.Text, num, OfficeHelpers.PropertyTypes.NumberInteger, fType);
                        }
                    }
                    else if (Double.TryParse(TxtBoxNumber.Text, out number))
                    {
                        if (isBatch == true)
                        {
                            foreach (string f in bFiles)
                            {
                                OfficeHelpers.SetCustomProperty(f, TxtName.Text, number, OfficeHelpers.PropertyTypes.NumberDouble, fType);
                                LoggingHelper.Log(f + StringResources.customPropSaved);
                            }
                        }
                        else
                        {
                            OfficeHelpers.SetCustomProperty(fName, TxtName.Text, number, OfficeHelpers.PropertyTypes.NumberDouble, fType);
                        }
                    }
                    else
                    {
                        // if the value isn't an int or double, just use text format
                        MessageBox.Show("The value entered is not a valid number and will be stored as text.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        if (isBatch == true)
                        {
                            foreach (string f in bFiles)
                            {
                                OfficeHelpers.SetCustomProperty(f, TxtName.Text, TxtBoxNumber.Text, OfficeHelpers.PropertyTypes.Text, fType);
                                LoggingHelper.Log(f + StringResources.customPropSaved);
                            }
                        }
                        else
                        {
                            OfficeHelpers.SetCustomProperty(fName, TxtName.Text, TxtBoxNumber.Text, OfficeHelpers.PropertyTypes.Text, fType);
                        }
                    }
                    break;

                default:
                    // Text is default
                    if (isBatch == true)
                    {
                        foreach (string f in bFiles)
                        {
                            OfficeHelpers.SetCustomProperty(f, TxtName.Text, TxtBoxText.Text, OfficeHelpers.PropertyTypes.Text, fType);
                            LoggingHelper.Log(f + StringResources.customPropSaved);
                        }
                    }
                    else
                    {
                        OfficeHelpers.SetCustomProperty(fName, TxtName.Text, TxtBoxText.Text, OfficeHelpers.PropertyTypes.Text, fType);
                    }

                    break;
                }

                Close();
            }
            catch (InvalidDataException ide)
            {
                LoggingHelper.Log("SetCustomProperty: Invalid Property Value");
                LoggingHelper.Log(ide.Message);
            }
            catch (Exception ex)
            {
                LoggingHelper.Log("BtnOKCustomProps Error: " + ex.Message);
                Close();
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }