Skip to content

Commit a855821

Browse files
committed
[IMP] xlsx: export clip
closes #7836 Task: 5368130 X-original-commit: 2c591c5 Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com> Signed-off-by: Florian Damhaut (flda) <flda@odoo.com> Signed-off-by: Pierre Rousseau (pro) <pro@odoo.com>
1 parent 552671f commit a855821

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

packages/o-spreadsheet-engine/src/xlsx/functions/styles.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export function addStyles(styles: XLSXStyle[]): XMLString {
157157
if (style.alignment && style.alignment.textRotation) {
158158
alignAttrs.push(["textRotation", style.alignment.textRotation]);
159159
}
160+
if (style.alignment && style.alignment.shrinkToFit) {
161+
alignAttrs.push(["shrinkToFit", "1"]);
162+
}
160163

161164
if (alignAttrs.length > 0) {
162165
attributes.push(["applyAlignment", "1"]); // for Libre Office

packages/o-spreadsheet-engine/src/xlsx/helpers/content_helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export function extractStyle(
156156
: undefined,
157157
wrapText: style.wrapping === "wrap" || content?.includes(NEWLINE) ? true : undefined,
158158
textRotation: style.rotation ? rotationToXLSX(style.rotation) : undefined,
159+
shrinkToFit: style.wrapping === "clip" ? true : undefined,
159160
},
160161
};
161162

@@ -201,6 +202,7 @@ export function normalizeStyle(construct: XLSXStructure, styles: ExtractedStyle)
201202
horizontal: styles.alignment.horizontal,
202203
wrapText: styles.alignment.wrapText,
203204
textRotation: styles.alignment.textRotation,
205+
shrinkToFit: styles.alignment.shrinkToFit,
204206
},
205207
} as XLSXStyle;
206208

tests/xlsx/__snapshots__/xlsx_export.test.ts.snap

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27771,14 +27771,14 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2777127771
</c>
2777227772
</row>
2777327773
<row r="10">
27774-
<c r="F10" t="s">
27774+
<c r="F10" s="12" t="s">
2777527775
<v>
2777627776
11
2777727777
</v>
2777827778
</c>
2777927779
</row>
2778027780
<row r="11">
27781-
<c r="F11" s="12" t="s">
27781+
<c r="F11" s="13" t="s">
2778227782
<v>
2778327783
12
2778427784
</v>
@@ -27790,38 +27790,38 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2779027790
13
2779127791
</v>
2779227792
</c>
27793-
<c r="F12" s="13" t="s">
27793+
<c r="F12" s="14" t="s">
2779427794
<v>
2779527795
14
2779627796
</v>
2779727797
</c>
2779827798
</row>
2779927799
<row r="13">
27800-
<c r="F13" s="14" t="s">
27800+
<c r="F13" s="15" t="s">
2780127801
<v>
2780227802
15
2780327803
</v>
2780427804
</c>
2780527805
</row>
2780627806
<row r="14">
27807-
<c r="F14" s="15" t="s">
27807+
<c r="F14" s="16" t="s">
2780827808
<v>
2780927809
16
2781027810
</v>
2781127811
</c>
2781227812
</row>
2781327813
<row r="20">
27814-
<c r="C20" s="16" t="s">
27814+
<c r="C20" s="17" t="s">
2781527815
<v>
2781627816
17
2781727817
</v>
2781827818
</c>
27819-
<c r="E20" s="17" t="s">
27819+
<c r="E20" s="18" t="s">
2782027820
<v>
2782127821
18
2782227822
</v>
2782327823
</c>
27824-
<c r="G20" s="18" t="s">
27824+
<c r="G20" s="19" t="s">
2782527825
<v>
2782627826
19
2782727827
</v>
@@ -27835,21 +27835,21 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2783527835
</c>
2783627836
</row>
2783727837
<row r="23">
27838-
<c r="C23" s="19">
27838+
<c r="C23" s="20">
2783927839
<v>
2784027840
0.43
2784127841
</v>
2784227842
</c>
2784327843
</row>
2784427844
<row r="24">
27845-
<c r="C24" s="20">
27845+
<c r="C24" s="21">
2784627846
<v>
2784727847
10
2784827848
</v>
2784927849
</c>
2785027850
</row>
2785127851
<row r="25">
27852-
<c r="C25" s="20">
27852+
<c r="C25" s="21">
2785327853
<v>
2785427854
10.123
2785527855
</v>
@@ -28195,7 +28195,7 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2819528195
</diagonal>
2819628196
</border>
2819728197
</borders>
28198-
<cellXfs count="21">
28198+
<cellXfs count="22">
2819928199
<xf numFmtId="0" fillId="0" fontId="0" borderId="0"/>
2820028200
<xf numFmtId="0" fillId="0" fontId="1" borderId="0"/>
2820128201
<xf numFmtId="0" fillId="0" fontId="2" borderId="0"/>
@@ -28216,6 +28216,9 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2821628216
<alignment wrapText="1"/>
2821728217
</xf>
2821828218
<xf numFmtId="0" fillId="0" fontId="0" borderId="6"/>
28219+
<xf numFmtId="0" fillId="0" fontId="0" borderId="0" applyAlignment="1">
28220+
<alignment shrinkToFit="1"/>
28221+
</xf>
2821928222
<xf numFmtId="0" fillId="0" fontId="0" borderId="0" applyAlignment="1">
2822028223
<alignment textRotation="135"/>
2822128224
</xf>

0 commit comments

Comments
 (0)