单词的OpenXml项目符号列表属性

时间:2013-09-18 11:01:41

标签: c# ms-word openxml

我正在使用OpenXML为word doc生成子弹列表,它的工作正常,但我需要在margin和bullet字符,项目符号和段落之间设置缩进

NumberingProperties _bulletsNumberingProp = new NumberingProperties();
                NumberingLevelReference _bulletNumberingLevelRef = new NumberingLevelReference();
                _bulletNumberingLevelRef.Val = _level; // level comes here 

                NumberingId _bulletNumberingId = new NumberingId();
                //if (_level != 3)
                //{
                //iParentID = TemplateElementID;
                //_bulletNumberingId.Val = iParentID;
                _bulletNumberingId.Val = TemplateElementID;
                //}
                //else
                //{
                //    _bulletNumberingId.Val = _pId;
                //    iParentID = _pId;
                //}
                _bulletsNumberingProp.Append(_bulletNumberingLevelRef);
                _bulletsNumberingProp.Append(_bulletNumberingId);




                GenerateNumberingDefinitionPart(numberingPart, ctcObj, _pId, _level, numbering, TemplateElementID, iParentID);

这里是生成编号列表的方法

private void GenerateNumberingDefinitionPart(NumberingDefinitionsPart numberingPart, CAPSTemplateClass ctcObj, int _pId, int _level, Numbering numbering, int tempElementId, int iParentID)
    {
        //iParentID = _pId;
        iParentID = tempElementId;
        string charUniCode = Convert.ToString(ctcObj.BulletData.BulletCharacterUnicode);
        NumberingFormat _numberingFormat = new NumberingFormat();
        switch (charUniCode)
        {
            case "49":
                _numberingFormat.Val = NumberFormatValues.Decimal;
                break;
            case "65":
                _numberingFormat.Val = NumberFormatValues.UpperLetter;
                break;
            case "97":
                _numberingFormat.Val = NumberFormatValues.LowerLetter;
                break;
            case "73":
                _numberingFormat.Val = NumberFormatValues.UpperRoman;
                break;
            case "105":
                _numberingFormat.Val = NumberFormatValues.LowerRoman;
                break;

        }

        AbstractNum abstractNum1 = new AbstractNum() { AbstractNumberId = iParentID }; //tempElementId 
        MultiLevelType multiLevelType1 = new MultiLevelType() { Val = MultiLevelValues.HybridMultilevel };
        TemplateCode templateCode1 = new TemplateCode() { Val = "BCF81B36" };

        Level level0 = new Level() { LevelIndex = 0 };
        StartNumberingValue startNumberingValue0 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat0 = new NumberingFormat();
        numberingFormat0.Val = _numberingFormat.Val;
        LevelText levelText0 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%1" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification0 = new LevelJustification() { Val = LevelJustificationValues.Left };

        PreviousParagraphProperties previousParagraphProperties0 = new PreviousParagraphProperties();
        Indentation indentation0 = new Indentation() { Start = "720", Hanging = "360" };

        previousParagraphProperties0.Append(indentation0);
        //Level lvl = SetNumBulletsLevel(_level, ctcObj);
        //abstractNum1.Append();
        level0.Append(startNumberingValue0);
        level0.Append(numberingFormat0);
        level0.Append(levelText0);
        level0.Append(levelJustification0);
        level0.Append(previousParagraphProperties0);

        Level level1 = new Level() { LevelIndex = 1, TemplateCode = "04090019", Tentative = true };
        StartNumberingValue startNumberingValue1 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat1 = new NumberingFormat();
        numberingFormat1.Val = _numberingFormat.Val;
        LevelText levelText1 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%2" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification1 = new LevelJustification() { Val = LevelJustificationValues.Left };

        //lvlrst.Append(
        //level1.LevelRestart = level0;
        PreviousParagraphProperties previousParagraphProperties1 = new PreviousParagraphProperties();
        Indentation indentation1 = new Indentation() { Start = "1440", Hanging = "360" };

        previousParagraphProperties1.Append(indentation1);

        level1.Append(startNumberingValue1);
        level1.Append(numberingFormat1);
        level1.Append(levelText1);
        level1.Append(levelJustification1);
        level1.Append(previousParagraphProperties1);
        //level1.Append(indentation1);
        //LevelRestart lvlrestart = new LevelRestart();
        //lvlrestart.Append(level0);
        //level1.LevelRestart = lvlrestart;
        Level level2 = new Level() { LevelIndex = 2, TemplateCode = "0409001B", Tentative = true };
        StartNumberingValue startNumberingValue2 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat2 = new NumberingFormat();
        numberingFormat2.Val = _numberingFormat.Val;
        LevelText levelText2 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%3" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification2 = new LevelJustification() { Val = LevelJustificationValues.Right };

        PreviousParagraphProperties previousParagraphProperties2 = new PreviousParagraphProperties();
        Indentation indentation2 = new Indentation() { Start = "2160", Hanging = "360" };

        previousParagraphProperties2.Append(indentation2);

        level2.Append(startNumberingValue2);
        level2.Append(numberingFormat2);
        level2.Append(levelText2);
        level2.Append(levelJustification2);
        level2.Append(previousParagraphProperties2);
        //level2.Append(indentation2);

        Level level3 = new Level() { LevelIndex = 3, TemplateCode = "0409000F", Tentative = true };
        StartNumberingValue startNumberingValue3 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat3 = new NumberingFormat();
        numberingFormat3.Val = _numberingFormat.Val;
        LevelText levelText3 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%4" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification3 = new LevelJustification() { Val = LevelJustificationValues.Left };

        PreviousParagraphProperties previousParagraphProperties3 = new PreviousParagraphProperties();
        Indentation indentation3 = new Indentation() { Start = "2880", Hanging = "360" };

        previousParagraphProperties3.Append(indentation3);

        level3.Append(startNumberingValue3);
        level3.Append(numberingFormat3);
        level3.Append(levelText3);
        level3.Append(levelJustification3);
        level3.Append(previousParagraphProperties3);
        //level3.Append(indentation3);

        Level level4 = new Level() { LevelIndex = 4, TemplateCode = "04090019", Tentative = true };
        StartNumberingValue startNumberingValue4 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat4 = new NumberingFormat();
        numberingFormat4.Val = _numberingFormat.Val;
        LevelText levelText4 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%5" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification4 = new LevelJustification() { Val = LevelJustificationValues.Left };

        PreviousParagraphProperties previousParagraphProperties4 = new PreviousParagraphProperties();
        Indentation indentation4 = new Indentation() { Start = "3600", Hanging = "360" };

        previousParagraphProperties4.Append(indentation4);

        level4.Append(startNumberingValue4);
        level4.Append(numberingFormat4);
        level4.Append(levelText4);
        level4.Append(levelJustification4);
        level4.Append(previousParagraphProperties4);


        Level level5 = new Level() { LevelIndex = 5, TemplateCode = "0409001B", Tentative = true };
        StartNumberingValue startNumberingValue5 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat5 = new NumberingFormat();
        numberingFormat5.Val = _numberingFormat.Val;
        LevelText levelText5 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%6" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification5 = new LevelJustification() { Val = LevelJustificationValues.Right };

        PreviousParagraphProperties previousParagraphProperties5 = new PreviousParagraphProperties();
        Indentation indentation5 = new Indentation() { Start = "4320", Hanging = "180" };

        previousParagraphProperties5.Append(indentation5);

        level5.Append(startNumberingValue5);
        level5.Append(numberingFormat5);
        level5.Append(levelText5);
        level5.Append(levelJustification5);
        level5.Append(previousParagraphProperties5);

        Level level6 = new Level() { LevelIndex = 6, TemplateCode = "0409000F", Tentative = true };
        StartNumberingValue startNumberingValue6 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat6 = new NumberingFormat();
        numberingFormat6.Val = _numberingFormat.Val;
        LevelText levelText6 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%7" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification6 = new LevelJustification() { Val = LevelJustificationValues.Left };

        PreviousParagraphProperties previousParagraphProperties6 = new PreviousParagraphProperties();
        Indentation indentation6 = new Indentation() { Start = "5040", Hanging = "360" };

        previousParagraphProperties6.Append(indentation6);

        level6.Append(startNumberingValue6);
        level6.Append(numberingFormat6);
        level6.Append(levelText6);
        level6.Append(levelJustification6);
        level6.Append(previousParagraphProperties6);

        Level level7 = new Level() { LevelIndex = 7, TemplateCode = "04090019", Tentative = true };
        StartNumberingValue startNumberingValue7 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat7 = new NumberingFormat();
        numberingFormat7.Val = _numberingFormat.Val;
        LevelText levelText7 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%8" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification7 = new LevelJustification() { Val = LevelJustificationValues.Left };

        PreviousParagraphProperties previousParagraphProperties7 = new PreviousParagraphProperties();
        Indentation indentation7 = new Indentation() { Start = "5760", Hanging = "360" };

        previousParagraphProperties7.Append(indentation7);

        level7.Append(startNumberingValue7);
        level7.Append(numberingFormat7);
        level7.Append(levelText7);
        level7.Append(levelJustification7);
        level7.Append(previousParagraphProperties7);

        Level level8 = new Level() { LevelIndex = 8, TemplateCode = "0409001B", Tentative = true };
        StartNumberingValue startNumberingValue8 = new StartNumberingValue() { Val = 1 };
        NumberingFormat numberingFormat8 = new NumberingFormat();
        numberingFormat8.Val = _numberingFormat.Val;
        LevelText levelText8 = new LevelText() { Val = (ctcObj.BulletData.PrefixText + "%9" + ctcObj.BulletData.PostfixText) };
        LevelJustification levelJustification8 = new LevelJustification() { Val = LevelJustificationValues.Right };

        PreviousParagraphProperties previousParagraphProperties8 = new PreviousParagraphProperties();
        Indentation indentation8 = new Indentation() { Start = "6480", Hanging = "180" };

        previousParagraphProperties8.Append(indentation8);

        level8.Append(startNumberingValue8);
        level8.Append(numberingFormat8);
        level8.Append(levelText8);
        level8.Append(levelJustification8);
        level8.Append(previousParagraphProperties8);

        abstractNum1.Append(multiLevelType1);
        abstractNum1.Append(templateCode1);
        abstractNum1.Append(level0);
        abstractNum1.Append(level1);
        abstractNum1.Append(level2);
        abstractNum1.Append(level3);
        abstractNum1.Append(level4);
        abstractNum1.Append(level5);
        abstractNum1.Append(level6);
        abstractNum1.Append(level7);
        abstractNum1.Append(level8);

        //tempElementId = numbId;

        NumberingInstance numberingInstance1 = new NumberingInstance() { NumberID = iParentID }; //tempElementId
        AbstractNumId abstractNumId1 = new AbstractNumId() { Val = iParentID };
        //numbId = numbId + 1;

        numberingInstance1.Append(abstractNumId1);

        numbering.Append(abstractNum1);


        numInstance.Add(numberingInstance1);
    }
  

默认情况下我会得到如下结果

     
      
  1. Bullet1
  2.         

    但是我需要在数字值之前和之后设置缩进,如下所示   大段引用           1. Bullet1

1 个答案:

答案 0 :(得分:3)

尝试手动创建所需的结构,并在OpenXML Productivity工具中打开它以获取代码。

您可以从此处获取开放xml生产力工具以及Open XML SDK http://www.microsoft.com/en-in/download/details.aspx?id=5124

希望这有帮助。