我正在为 word doc 使用 OpenXML 生成项目符号列表,它工作得很好,但我需要在边距和项目符号字符、项目符号字符和段落之间设置缩进
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
但我需要在数字值之前和之后设置缩进,如下面的 Blockquote 1. Bullet1