Skip to content

Commit f30a0d9

Browse files
committed
[IMP] style: rotation xlsx export
1 parent cae0741 commit f30a0d9

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

packages/o-spreadsheet-engine/src/xlsx/conversion/style_conversion.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export function convertStyle(
9898
align: styleStruct.alignment?.horizontal
9999
? H_ALIGNMENT_CONVERSION_MAP[styleStruct.alignment.horizontal]
100100
: undefined,
101+
rotation: styleStruct.alignment?.textRotation
102+
? (styleStruct.alignment?.textRotation * Math.PI) / 180
103+
: undefined,
101104
// In xlsx fills, bgColor is the color of the fill, and fgColor is the color of the pattern above the background, except in solid fills
102105
fillColor:
103106
styleStruct.fillStyle?.patternType === "solid"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ export function addStyles(styles: XLSXStyle[]): XMLString {
154154
if (style.alignment && style.alignment.wrapText) {
155155
alignAttrs.push(["wrapText", "1"]);
156156
}
157+
if (style.alignment && style.alignment.textRotation) {
158+
alignAttrs.push(["textRotation", style.alignment.textRotation]);
159+
}
157160

158161
if (alignAttrs.length > 0) {
159162
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
@@ -139,6 +139,7 @@ export function extractStyle(
139139
? V_ALIGNMENT_EXPORT_CONVERSION_MAP[style.verticalAlign]
140140
: undefined,
141141
wrapText: style.wrapping === "wrap" || content?.includes(NEWLINE) ? true : undefined,
142+
textRotation: style.rotation ? Math.round((style.rotation / Math.PI) * 180) : undefined,
142143
},
143144
};
144145

@@ -161,6 +162,7 @@ export function normalizeStyle(construct: XLSXStructure, styles: ExtractedStyle)
161162
vertical: styles.alignment.vertical,
162163
horizontal: styles.alignment.horizontal,
163164
wrapText: styles.alignment.wrapText,
165+
textRotation: styles.alignment.textRotation,
164166
},
165167
} as XLSXStyle;
166168

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

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26895,53 +26895,60 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2689526895
</v>
2689626896
</c>
2689726897
</row>
26898-
<row r="12">
26899-
<c r="D12" t="s">
26898+
<row r="11">
26899+
<c r="F11" s="12" t="s">
2690026900
<v>
2690126901
12
2690226902
</v>
2690326903
</c>
2690426904
</row>
26905-
<row r="20">
26906-
<c r="C20" s="12" t="s">
26905+
<row r="12">
26906+
<c r="D12" t="s">
2690726907
<v>
2690826908
13
2690926909
</v>
2691026910
</c>
26911-
<c r="E20" s="13" t="s">
26911+
</row>
26912+
<row r="20">
26913+
<c r="C20" s="13" t="s">
2691226914
<v>
2691326915
14
2691426916
</v>
2691526917
</c>
26916-
<c r="G20" s="14" t="s">
26918+
<c r="E20" s="14" t="s">
2691726919
<v>
2691826920
15
2691926921
</v>
2692026922
</c>
26923+
<c r="G20" s="15" t="s">
26924+
<v>
26925+
16
26926+
</v>
26927+
</c>
2692126928
</row>
2692226929
<row r="21">
2692326930
<c r="A21" t="s">
2692426931
<v>
26925-
16
26932+
17
2692626933
</v>
2692726934
</c>
2692826935
</row>
2692926936
<row r="23">
26930-
<c r="C23" s="15">
26937+
<c r="C23" s="16">
2693126938
<v>
2693226939
0.43
2693326940
</v>
2693426941
</c>
2693526942
</row>
2693626943
<row r="24">
26937-
<c r="C24" s="16">
26944+
<c r="C24" s="17">
2693826945
<v>
2693926946
10
2694026947
</v>
2694126948
</c>
2694226949
</row>
2694326950
<row r="25">
26944-
<c r="C25" s="16">
26951+
<c r="C25" s="17">
2694526952
<v>
2694626953
10.123
2694726954
</v>
@@ -26950,70 +26957,70 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2695026957
<row r="27">
2695126958
<c r="A27" t="s">
2695226959
<v>
26953-
17
26960+
18
2695426961
</v>
2695526962
</c>
2695626963
</row>
2695726964
<row r="28">
2695826965
<c r="A28" t="s">
2695926966
<v>
26960-
18
26967+
19
2696126968
</v>
2696226969
</c>
2696326970
</row>
2696426971
<row r="29">
2696526972
<c r="A29" t="s">
2696626973
<v>
26967-
19
26974+
20
2696826975
</v>
2696926976
</c>
2697026977
</row>
2697126978
<row r="30">
2697226979
<c r="A30" t="s">
2697326980
<v>
26974-
20
26981+
21
2697526982
</v>
2697626983
</c>
2697726984
</row>
2697826985
<row r="31">
2697926986
<c r="A31" t="s">
2698026987
<v>
26981-
21
26988+
22
2698226989
</v>
2698326990
</c>
2698426991
</row>
2698526992
<row r="32">
2698626993
<c r="A32" t="s">
2698726994
<v>
26988-
22
26995+
23
2698926996
</v>
2699026997
</c>
2699126998
</row>
2699226999
<row r="33">
2699327000
<c r="A33" t="s">
2699427001
<v>
26995-
23
27002+
24
2699627003
</v>
2699727004
</c>
2699827005
</row>
2699927006
<row r="34">
2700027007
<c r="A34" t="s">
2700127008
<v>
27002-
24
27009+
25
2700327010
</v>
2700427011
</c>
2700527012
</row>
2700627013
<row r="35">
2700727014
<c r="A35" t="s">
2700827015
<v>
27009-
25
27016+
26
2701027017
</v>
2701127018
</c>
2701227019
</row>
2701327020
<row r="36">
2701427021
<c r="A36" t="s">
2701527022
<v>
27016-
26
27023+
27
2701727024
</v>
2701827025
</c>
2701927026
</row>
@@ -27040,7 +27047,7 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2704027047
<row r="39">
2704127048
<c r="A39" t="s">
2704227049
<v>
27043-
27
27050+
28
2704427051
</v>
2704527052
</c>
2704627053
</row>
@@ -27057,7 +27064,7 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2705727064
<row r="41">
2705827065
<c r="A41" t="s">
2705927066
<v>
27060-
28
27067+
29
2706127068
</v>
2706227069
</c>
2706327070
</row>
@@ -27287,7 +27294,7 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2728727294
</diagonal>
2728827295
</border>
2728927296
</borders>
27290-
<cellXfs count="17">
27297+
<cellXfs count="18">
2729127298
<xf numFmtId="0" fillId="0" fontId="0" borderId="0"/>
2729227299
<xf numFmtId="0" fillId="0" fontId="1" borderId="0"/>
2729327300
<xf numFmtId="0" fillId="0" fontId="2" borderId="0"/>
@@ -27308,6 +27315,9 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2730827315
<alignment wrapText="1"/>
2730927316
</xf>
2731027317
<xf numFmtId="0" fillId="0" fontId="0" borderId="6"/>
27318+
<xf numFmtId="0" fillId="0" fontId="0" borderId="0" applyAlignment="1">
27319+
<alignment textRotation="90"/>
27320+
</xf>
2731127321
<xf numFmtId="0" fillId="0" fontId="0" borderId="1"/>
2731227322
<xf numFmtId="0" fillId="0" fontId="0" borderId="2"/>
2731327323
<xf numFmtId="0" fillId="0" fontId="0" borderId="3"/>
@@ -27321,7 +27331,7 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2732127331
"path": "xl/styles.xml",
2732227332
},
2732327333
{
27324-
"content": "<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="29" uniqueCount="29">
27334+
"content": "<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="30" uniqueCount="30">
2732527335
<si>
2732627336
<t>
2732727337
Owl is awesome
@@ -27382,6 +27392,11 @@ exports[`Test XLSX export Generic sheets (style, hidden, size, cf) Simple model
2738227392
clipped text
2738327393
</t>
2738427394
</si>
27395+
<si>
27396+
<t>
27397+
rotated text
27398+
</t>
27399+
</si>
2738527400
<si>
2738627401
<t>
2738727402
this is a sum of sums

tests/xlsx/xlsx_export.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const simpleData = {
6161
F8: { content: "wrapped text", style: 10 },
6262
F9: { content: "overflow text", style: 9 },
6363
F10: { content: "clipped text", style: 11 },
64+
F11: { content: "rotated text", style: 12 },
6465
H2: { content: "merged content" },
6566
C20: { content: "left", border: 1 },
6667
E20: { content: "top", border: 2 },
@@ -114,6 +115,7 @@ const simpleData = {
114115
9: { wrapping: "overflow" },
115116
10: { wrapping: "wrap" },
116117
11: { wrapping: "clip" },
118+
12: { rotation: Math.PI / 2 },
117119
},
118120
borders: {
119121
1: { left: { style: "thin", color: "#000" } },

0 commit comments

Comments
 (0)