Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b247766

Browse files
committed
Fix Issue #1075
1 parent 1c3ea65 commit b247766

File tree

7 files changed

+22
-1
lines changed

7 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ worksheet.properties.defaultRowHeight = 15;
326326
| outlineLevelCol | 0 | The worksheet column outline level |
327327
| outlineLevelRow | 0 | The worksheet row outline level |
328328
| defaultRowHeight | 15 | Default row height |
329+
| defaultColWidth | (optional) | Default column width |
329330
| dyDescent | 55 | TBD |
330331

331332
### Worksheet Metrics

README_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ worksheet.properties.defaultRowHeight = 15;
273273
| outlineLevelCol | 0 | 工作表列大纲级别 |
274274
| outlineLevelRow | 0 | 工作表行大纲级别 |
275275
| defaultRowHeight | 15 | 默认行高 |
276+
| defaultColWidth | (optional) | TBD |
276277
| dyDescent | 55 | TBD |
277278

278279
### 工作表指标

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,11 @@ export interface WorksheetProperties {
11981198
*/
11991199
defaultRowHeight: number;
12001200

1201+
/**
1202+
* Default column width (optional)
1203+
*/
1204+
defaultColWidth?: number;
1205+
12011206
/**
12021207
* default: 55
12031208
*/

lib/stream/xlsx/worksheet-writer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ class WorksheetWriter {
464464
outlineLevelRow: properties.outlineLevelRow,
465465
}
466466
: undefined;
467+
if (properties.defaultColWidth) {
468+
sheetFormatPropertiesModel.defaultColWidth = properties.defaultColWidth;
469+
}
467470

468471
xmlBuf.addText(xform.sheetFormatProperties.toXml(sheetFormatPropertiesModel));
469472
}

lib/xlsx/xform/sheet/sheet-format-properties-xform.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class SheetFormatPropertiesXform extends BaseXform {
1414
outlineLevelCol: model.outlineLevelCol,
1515
'x14ac:dyDescent': model.dyDescent,
1616
};
17+
if (model.defaultColWidth) {
18+
attributes.defaultColWidth = model.defaultColWidth;
19+
}
1720

1821
// default value for 'defaultRowHeight' is 15, this should not be 'custom'
1922
if (!model.defaultRowHeight || (model.defaultRowHeight !== 15)) {
@@ -34,6 +37,9 @@ class SheetFormatPropertiesXform extends BaseXform {
3437
outlineLevelRow: parseInt(node.attributes.outlineLevelRow || '0', 10),
3538
outlineLevelCol: parseInt(node.attributes.outlineLevelCol || '0', 10),
3639
};
40+
if (node.attributes.defaultColWidth) {
41+
this.model.defaultColWidth = parseFloat(node.attributes.defaultColWidth);
42+
}
3743
return true;
3844
}
3945
return false;

lib/xlsx/xform/sheet/worksheet-xform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ class WorkSheetXform extends BaseXform {
205205
outlineLevelRow: model.properties.outlineLevelRow,
206206
}
207207
: undefined;
208+
if (model.properties && model.properties.defaultColWidth) {
209+
sheetFormatPropertiesModel.defaultColWidth = model.properties.defaultColWidth;
210+
}
208211
const sheetPropertiesModel = {
209212
outlineProperties: model.properties && model.properties.outlineProperties,
210213
tabColor: model.properties && model.properties.tabColor,

spec/unit/xlsx/xform/sheet/sheet-format-properties-xform.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ const expectations = [
1010
},
1111
preparedModel: {
1212
defaultRowHeight: 14.4,
13+
defaultColWidth: 2.17,
1314
dyDescent: 0.55,
1415
outlineLevelRow: 5,
1516
outlineLevelCol: 2,
1617
},
1718
xml:
18-
'<sheetFormatPr defaultRowHeight="14.4" customHeight="1" outlineLevelRow="5" outlineLevelCol="2" x14ac:dyDescent="0.55"/>',
19+
'<sheetFormatPr defaultRowHeight="14.4" defaultColWidth="2.17" customHeight="1" outlineLevelRow="5" outlineLevelCol="2" x14ac:dyDescent="0.55"/>',
1920
parsedModel: {
2021
defaultRowHeight: 14.4,
22+
defaultColWidth: 2.17,
2123
dyDescent: 0.55,
2224
outlineLevelRow: 5,
2325
outlineLevelCol: 2,

0 commit comments

Comments
 (0)