Добавления колонтитула в xml

Рейтинг: 0Ответов: 1Опубликовано: 06.02.2023

Нужно добавить колонтитул в документ с номером страницы. Условно будим считать что страниц у нас N-количество. Документ "odf" LibreOffice. Изначально документ не имеет колонтитула. Думал это как-то можно сделать с помощью qt но не вышло. Пытаюсь понять как это сделать в ручном режиме после сделаю программу. Как понял документ можно разархивировать с помощью unzip. После в папке будут находиться следующие файлы content.xml, mimetype, manifest, Picture1. Как понимаю нужно править content.xml.

Я попытался добавить следующий код:

<office:automatic-styles>
<style:style style:name="Footer" style:family="paragraph" style:parent-style-name="Header_20_and_20_Footer" style:class="extra">
<style:paragraph-properties text:number-lines="false" text:line-number="0">
<style:tab-stops>
<style:tab-stop style:position="8.5cm" style:type="center"/>
<style:tab-stop style:position="17cm" style:type="right"/>
</style:tab-stops>
</style:paragraph-properties>
</style:style>
</office:automatic-styles>

  </office:body>
  <style:footer-style>
  <style:header-footer-properties fo:min-height="0cm" fo:margin-top="0.499cm" fo:background-color="transparent" draw:fill="none"/>
  </style:footer-style>
  <style:footer>
  <text:p text:style-name="p4">
  <text:page-number text:select-page="current">1</text:page-number>
  </text:p>
  </style:footer>
</office:document-content>

После запаковки назад, колонтитула не обнаружил. Может кто подскажет как добавлять колонтитулы в документ. Примерами или расскажет алгоритм.

Ответы

▲ 0

вот решение моей проблемы:

    <style:page-layout style:name="pm1">
    <style:page-layout-properties fo:page-width="21.59cm" fo:page-height="27.94cm" style:num-format="1" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm" style:writing-mode="lr-tb" style:layout-grid-color="#c0c0c0" style:layout-grid-lines="44" style:layout-grid-base-height="0.55cm" style:layout-grid-ruby-height="0cm" style:layout-grid-mode="none" style:layout-grid-ruby-below="false" style:layout-grid-print="true" style:layout-grid-display="true" style:footnote-max-height="0cm">
    <style:footnote-sep style:width="0.018cm" style:distance-before-sep="0.101cm" style:distance-after-sep="0.101cm" style:line-style="none" style:adjustment="left" style:rel-width="25%" style:color="#000000"/>
    </style:page-layout-properties>
    <style:header-style>
    <style:header-footer-properties fo:min-height="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-bottom="0.499cm"/> // 
    </style:header-style>
    <style:footer-style>
    <style:header-footer-properties fo:min-height="0cm" fo:margin-left="0cm" fo:margin-right="0cm" fo:margin-top="0.499cm"/>
    </style:footer-style>
    </style:page-layout>
    
  </office:automatic-styles> // как понял использовать в качестве опорной точки
  
   <office:master-styles>
  <style:master-page style:name="Standard" style:page-layout-name="pm1">
   <style:header>
    <table:table table:name="Table3" table:style-name="Table3">
     <table:table-column table:style-name="Table3.A" table:number-columns-repeated="3"/>
     <table:table-row table:style-name="TableLine94266545094448">
      <table:table-cell table:style-name="Table3.A1" office:value-type="string">
       <text:p text:style-name="Header">Company: <text:placeholder text:placeholder-type="text">&lt;company.rec_name&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table3.A1" office:value-type="string">
       <text:p text:style-name="P1">General Journal</text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table3.A1" office:value-type="string">
       <text:p text:style-name="P2">Print Date: <text:placeholder text:placeholder-type="text">&lt;format_date(datetime.date.today(), user.language)&gt;</text:placeholder><text:s/>at <text:placeholder text:placeholder-type="text">&lt;datetime.datetime.now().strftime(&apos;%H:%M:%S&apos;)&gt;</text:placeholder></text:p>
      </table:table-cell>
     </table:table-row>
    </table:table>
   </style:header>
   <style:footer>
    <table:table table:name="Table2" table:style-name="Table2">
     <table:table-column table:style-name="Table2.A"/>
     <table:table-column table:style-name="Table2.B"/>
     <table:table-row table:style-name="TableLine94266545229984">
      <table:table-cell table:style-name="Table2.A1" office:value-type="string">
       <text:p text:style-name="Footer">User: <text:placeholder text:placeholder-type="text">&lt;user.rec_name&gt;</text:placeholder></text:p>
      </table:table-cell>
      <table:table-cell table:style-name="Table2.A1" office:value-type="string">
       <text:p text:style-name="P3"><text:page-number text:select-page="current">1</text:page-number>/<text:page-count>1</text:page-count></text:p>
      </table:table-cell>
     </table:table-row>
    </table:table>
   </style:footer>  
  </style:master-page>
 </office:master-styles>