Skip to content

Content in different sections #1299

@SystemError7

Description

@SystemError7

I'm trying to add a new section with start_type = WD_SECTION.NEW_PAGE to generate a new page with a second section, then, I add a html to the body of the document with the following code:

    package = word.part.package
    partname = package.next_partname('/word/altChunk%d.html')
    AltPart = Part(partname, 'text/html', html.__str__().encode(), package)
    r_id = word.part.relate_to(AltPart, RT.A_F_CHUNK)
    altChunk = OxmlElement('w:altChunk')
    altChunk.set(qn('r:id'), r_id)
    word.element.body.addprevious(altChunk)

Expecting that the first page will have the first section, and the other pages will have the second section.

But all the content have the first section and, the last page (in blank) have the second section.
And if I add the section after, it does the same.

The problem is that it doesn't insert the content as tables, paragraphs or images. All the content is in the tag <w:altChunk>. As you can see bellow:

<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" 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: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 wp14">
  <w:altChunk r:id="rId9"/>
  <w:body>
    <w:p>
      <w:pPr>
        <w:sectPr>
          <w:pgSz w:w="11906" w:h="16838"/>
          <w:pgMar w:top="0" w:right="0" w:bottom="567" w:left="0" w:header="720" w:footer="720" w:gutter="0"/>
          <w:cols w:space="720"/>
          <w:docGrid w:linePitch="360"/>
        </w:sectPr>
      </w:pPr>
    </w:p>
    <w:sectPr w:rsidR="00FC693F" w:rsidRPr="0006063C" w:rsidSect="00034616">
      <w:pgSz w:w="16838" w:h="11906" w:orient="landscape"/>
      <w:pgMar w:top="1134" w:right="0" w:bottom="567" w:left="0" 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>

Each <w:sectPr> represents the sections in the document.
So if I do a word.element.body.addnext(altChunk) it would have the first page in blank with the first section, and the rest of the pages with the html content with the second section.

So, how can I do to achieve what I expect??

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions