Skip to content

v0.1.2 — preserve empty-cell formatting

Choose a tag to compare

@SonAIengine SonAIengine released this 15 Apr 06:05
· 22 commits to main since this release

Fix

Empty cells still lost formatting in v0.1.1.

The previous fix only covered cells that already had runs. Empty cells still fell back to cell.text = value, which silently dropped font information stored in <a:endParaRPr> (PPTX) and <w:pPr><w:rPr> (DOCX). Real-world templates stash font/size/bold there so unfilled cells still render with the template style — v0.1.1 was writing into them but losing that style in the process.

PPTX empty-cell path

When the text frame has no runs, manually build an <a:r> inside the existing <a:p>, clone <a:endParaRPr> into the new run's <a:rPr>, and write the value into <a:t>. Preserves lang, sz, b, latin typeface, etc.

<!-- before set_cell -->
<a:p>
  <a:endParaRPr lang="en-US" sz="1800" b="1">
    <a:latin typeface="Microsoft Sans Serif"/>
  </a:endParaRPr>
</a:p>

<!-- after v0.1.2 set_cell(..., "V-2024-001") -->
<a:p>
  <a:endParaRPr lang="en-US" sz="1800" b="1">
    <a:latin typeface="Microsoft Sans Serif"/>
  </a:endParaRPr>
  <a:r>
    <a:rPr lang="en-US" sz="1800" b="1">
      <a:latin typeface="Microsoft Sans Serif"/>
    </a:rPr>
    <a:t>V-2024-001</a:t>
  </a:r>
</a:p>

DOCX empty-cell path

Use paragraphs[0].add_run(value) instead of cell.text, then clone <w:pPr><w:rPr> into the new run's <w:rPr>. Preserves rFonts, sz, bold that templates stash on the paragraph marker.

Tests

  • test_pptx_empty_cell_preserves_endpararpr — crafts a cell with only <a:endParaRPr> (sz=1800, b=1, Microsoft Sans Serif), calls set_cell, asserts the new run carries the cloned rPr
  • test_docx_empty_cell_preserves_ppr_rpr — crafts a cell with only <w:pPr><w:rPr> (Malgun Gothic, sz=36, bold), calls set_cell, asserts the new run carries the cloned rPr

All 13 smoke tests pass. Reverting either fix to the old cell.text fallback makes the new tests fail with new run lost its rPr — confirmed they actually catch the regression.

Upgrade

pip install --upgrade document-adapter  # >= 0.1.2

If you were keeping a downstream monkey-patch for the empty-cell case, you can now remove it.