本文介绍了如何在Open XML中放大子弹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用适用于.NET的Open XML SDK生成docx文件

I'm generating docx files using the Open XML SDK for .NET

我列表中的项目符号太小了,但我不知道为什么.所以这就是我所做的:

The bullets in my lists are super tiny but I can't figure out why. So here's what I've done:

  1. 使用单个项目符号项生成文档
  2. 使用单个项目符号项从Word创建文档
  3. 使用Open XML生产力工具比较两个文件
  4. 我一生无法看到任何差异

如果我同时单击两个项目符号,则显示字体和大小的位置都相同!我看不到xml的编号部分或与此相关的任何地方的任何区别.也许我缺少基本知识.

If I click on the bullet in both, to where it shows the font and size, they are both the same! I don't see any differences in the numbering section of the xml, or anywhere for that matter. Perhaps I'm missing something elementary.

以下是numbering部分的一些代码:

Here's some code for the numbering part:

  var abstractNumberId = part.Numbering.Elements<AbstractNum>().Count() + 1;
  var abstractNum = new AbstractNum { AbstractNumberId = abstractNumberId };
  if (initialIndent == 0)
  {
      initialIndent = 1;
  }

  var start1 = (initialIndent * 720);

  abstractNum.SetAttribute(new OpenXmlAttribute("w15", "restartNumberingAfterBreak", "http://schemas.microsoft.com/office/word/2012/wordml", "1"));
  var multiLevelType = new MultiLevelType { Val = MultiLevelValues.HybridMultilevel };
  var templateCode = new TemplateCode { Val = "48A2E570" };

  var level = new Level { LevelIndex = 0, TemplateCode = "0409000F" };
  var startNumberingValue = new StartNumberingValue { Val = 1 };
  var restartValue = new LevelRestart() { Val = 0 };
  var numberingFormat = new NumberingFormat { Val = NumberFormatValues.Bullet };
  var levelText = new LevelText { Val = "%1." };
  var levelJustification = new LevelJustification { Val = LevelJustificationValues.Left };
  var previousParagraphProperties = new PreviousParagraphProperties();
  var indentation = new Indentation { Start = start1.ToString(), Hanging = "360" };

  previousParagraphProperties.Append(indentation);

  level.Append(startNumberingValue);
  level.Append(numberingFormat);
  level.Append(restartValue);
  level.Append(levelText);
  level.Append(levelJustification);
  level.Append(previousParagraphProperties);

  abstractNum.Append(multiLevelType);
  abstractNum.Append(templateCode);
  abstractNum.Append(level);



  var numberId = part.Numbering.Elements<NumberingInstance>().Count() + 1;
  var numberingInstance = new NumberingInstance { NumberID = numberId };
  var abstractNumId = new AbstractNumId { Val = abstractNumberId };
  numberingInstance.Append(abstractNumId);


  if (abstractNumberId == 1)
  {
    part.Numbering.Append(abstractNum);
  }
  else
  {
    var lastAbstractNum = part.Numbering.Elements<AbstractNum>().Last();
    part.Numbering.InsertAfter(abstractNum, lastAbstractNum);
  }

  if (numberId == 1)
  {
    part.Numbering.Append(numberingInstance);
  }
  else
  {
    var lastNumberingInstance = part.Numbering.Elements<NumberingInstance>().Last();
    part.Numbering.InsertAfter(numberingInstance, lastNumberingInstance);
  }


  return numberId;

这是大项目符号的XML:

Here's the XML for the large bullet:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
 <w:body>
  <w:p w14:paraId="6279EAE9" w14:textId="5895C066" w:rsidR="008070A4" w:rsidRPr="009228DC" w:rsidRDefault="00281441" w:rsidP="00984CDF">
   <w:pPr>
    <w:pStyle w:val="ListParagraph"/>
    <w:numPr>
     <w:ilvl w:val="0"/>
     <w:numId w:val="5"/>
    </w:numPr>
    <w:ind w:left="0"/>
    <w:rPr>
     <w:rFonts w:cstheme="minorHAnsi"/>
    </w:rPr>
   </w:pPr>
   <w:bookmarkStart w:id="0" w:name="_GoBack"/>
   <w:bookmarkEnd w:id="0"/>
   <w:r w:rsidRPr="009228DC">
    <w:rPr>
     <w:rFonts w:cstheme="minorHAnsi"/>
    </w:rPr>
    <w:t>
     Large bullet
    </w:t>
   </w:r>
  </w:p>
  <w:sectPr w:rsidR="008070A4" w:rsidRPr="009228DC">
   <w:pgSz w:w="12240" w:h="15840"/>
   <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
   <w:cols w:space="720"/>
   <w:docGrid w:linePitch="360"/>
  </w:sectPr>
 </w:body>
</w:document>

这是小文件的xml:

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex" xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex" xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex" xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex" xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex" xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex" xmlns:cx6="http://schemas.microsoft.com/office/drawing/2016/5/12/chartex" xmlns:cx7="http://schemas.microsoft.com/office/drawing/2016/5/13/chartex" xmlns:cx8="http://schemas.microsoft.com/office/drawing/2016/5/14/chartex" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:aink="http://schemas.microsoft.com/office/drawing/2016/ink" xmlns:am3d="http://schemas.microsoft.com/office/drawing/2017/model3d" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:w16cid="http://schemas.microsoft.com/office/word/2016/wordml/cid" xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 w16se w16cid wp14">
 <w:body>
  <w:p w14:paraId="6279EAE9" w14:textId="4866CD41" w:rsidR="008070A4" w:rsidRPr="009228DC" w:rsidRDefault="00221689" w:rsidP="008C6B6F">
   <w:pPr>
    <w:pStyle w:val="ListParagraph"/>
    <w:numPr>
     <w:ilvl w:val="0"/>
     <w:numId w:val="1"/>
    </w:numPr>
    <w:ind w:left="0"/>
    <w:rPr>
     <w:rFonts w:cstheme="minorHAnsi"/>
    </w:rPr>
   </w:pPr>
   <w:bookmarkStart w:id="0" w:name="_GoBack"/>
   <w:bookmarkEnd w:id="0"/>
   <w:r w:rsidRPr="009228DC">
    <w:rPr>
     <w:rFonts w:cstheme="minorHAnsi"/>
    </w:rPr>
    <w:t>
     This is a bulleted list
    </w:t>
   </w:r>
  </w:p>
  <w:sectPr w:rsidR="008070A4" w:rsidRPr="009228DC">
   <w:pgSz w:w="12240" w:h="15840"/>
   <w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="720" w:footer="720" w:gutter="0"/>
   <w:cols w:space="720"/>
   <w:docGrid w:linePitch="360"/>
  </w:sectPr>
 </w:body>
</w:document>

推荐答案

项目符号和数字的格式在w:numbering根元素中包含的w:abstractNum元素(或确切地说是其后代)中定义. NumberingDefinitionsPart的. MainDocumentPartw:document根元素可能完全相同.不过,就您而言,您至少应该看到w:numId元素具有不同的w:val属性值,这意味着它们指向不同的编号实例和相关的项目符号定义.

The formatting of bullets and numbers is defined in the w:abstractNum elements (or by their descendants to be precise) that are contained in the w:numbering root element of the NumberingDefinitionsPart. Your w:document root element of the MainDocumentPart could be completely identical. In your case, though, you should at least see that the w:numId elements have different w:val attribute values, meaning they are pointing to different numbering instances and related bullet definitions.

因此,您需要正确设置编号定义,然后从您的主要文档部分引用它.

Thus, you need to set up your numbering definitions correctly and then reference that from your main document part.

这篇关于如何在Open XML中放大子弹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:57