@leankylin-sheet/excel 5.2.28 → 5.2.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,3 @@
1
1
  declare function setHiddenRowCol(table: any, worksheet: any): void;
2
- export { setHiddenRowCol };
2
+ declare function setFreeze(table: any, worksheet: any): void;
3
+ export { setHiddenRowCol, setFreeze };
package/dist/index.esm.js CHANGED
@@ -1598,12 +1598,12 @@ function rgb2hex(color) {
1598
1598
  if (_a2 === 0) {
1599
1599
  return "#FFFFFFFF";
1600
1600
  }
1601
- var alphaValue = 25 - clampedA * 255;
1601
+ var alphaValue = Math.round(clampedA * 255);
1602
1602
  var aHex = toHex(alphaValue);
1603
1603
  var rHex = toHex(clampedR);
1604
1604
  var gHex = toHex(clampedG);
1605
1605
  var bHex = toHex(clampedB);
1606
- return "#".concat(rHex).concat(gHex).concat(bHex).concat(aHex);
1606
+ return "#".concat(aHex).concat(rHex).concat(gHex).concat(bHex);
1607
1607
  }
1608
1608
  return "#FFFFFFFF";
1609
1609
  }
@@ -5015,7 +5015,7 @@ var fontConvert = function fontConvert() {
5015
5015
  };
5016
5016
  var color = rgb2hex(fc);
5017
5017
  var font = {
5018
- size: fs,
5018
+ size: Number.isFinite(fs) && fs > 0 ? fs : 10,
5019
5019
  color: {
5020
5020
  argb: color.replace("#", "")
5021
5021
  },
@@ -5082,13 +5082,15 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5082
5082
  cellArr.forEach(function (row, rowid) {
5083
5083
  var _table$config, _table$config$rowlen;
5084
5084
  var dbrow = worksheet.getRow(rowid + 1);
5085
- dbrow.height = (((_table$config = table.config) === null || _table$config === void 0 ? void 0 : (_table$config$rowlen = _table$config.rowlen) === null || _table$config$rowlen === void 0 ? void 0 : _table$config$rowlen[rowid]) || 19) / 1.2;
5085
+ var rowHeight = (((_table$config = table.config) === null || _table$config === void 0 ? void 0 : (_table$config$rowlen = _table$config.rowlen) === null || _table$config$rowlen === void 0 ? void 0 : _table$config$rowlen[rowid]) || 19) / 1.2;
5086
+ dbrow.height = Number.isFinite(rowHeight) && rowHeight > 0 ? rowHeight : 19 / 1.2;
5086
5087
  row.every(function (cell, columnid) {
5087
5088
  var _cell$ct7;
5088
5089
  if (rowid === 0) {
5089
5090
  var _table$config2, _table$config2$column;
5090
5091
  var dobCol = worksheet.getColumn(columnid + 1);
5091
- dobCol.width = (((_table$config2 = table.config) === null || _table$config2 === void 0 ? void 0 : (_table$config2$column = _table$config2.columnlen) === null || _table$config2$column === void 0 ? void 0 : _table$config2$column[columnid]) || 73) / 8;
5092
+ var colWidth = (((_table$config2 = table.config) === null || _table$config2 === void 0 ? void 0 : (_table$config2$column = _table$config2.columnlen) === null || _table$config2$column === void 0 ? void 0 : _table$config2$column[columnid]) || 73) / 8;
5093
+ dobCol.width = Number.isFinite(colWidth) && colWidth > 0 ? colWidth : 73 / 8;
5092
5094
  }
5093
5095
  if (!cell) return true;
5094
5096
  function getFa() {
@@ -5147,17 +5149,18 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5147
5149
  v += val.v;
5148
5150
  });
5149
5151
  } else if (cell.ct && ctT === "n") {
5150
- if (v !== undefined) {
5151
- var _cell$v;
5152
- v = (_cell$v = cell.v) !== null && _cell$v !== void 0 ? _cell$v : +cell.v;
5153
- }
5154
- if (cell.ct !== "General") {
5155
- numFmt = getFa();
5152
+ var _cell$ct8;
5153
+ var numVal = +cell.v;
5154
+ v = Number.isNaN(numVal) ? cell.v : numVal;
5155
+ if (((_cell$ct8 = cell.ct) === null || _cell$ct8 === void 0 ? void 0 : _cell$ct8.fa) && cell.ct.fa !== "General") {
5156
+ var fa = getFa();
5157
+ if (fa) numFmt = fa;
5156
5158
  }
5157
5159
  } else if (cell.ct && ctT === "d") {
5158
5160
  var mockDate = isTime(cell.ct.fa) ? "2000-01-01 " : "";
5159
5161
  v = new Date(mockDate + cell.m);
5160
- numFmt = getFa();
5162
+ var _fa = getFa();
5163
+ if (_fa) numFmt = _fa;
5161
5164
  } else {
5162
5165
  v = cell.v;
5163
5166
  }
@@ -6401,6 +6404,38 @@ function setHiddenRowCol(table, worksheet) {
6401
6404
  worksheet.getColumn(parseInt(col) + 1).hidden = true;
6402
6405
  }
6403
6406
  }
6407
+ function setFreeze(table, worksheet) {
6408
+ var _frozen$range, _frozen$range2;
6409
+ var frozen = table === null || table === void 0 ? void 0 : table.frozen;
6410
+ if (!frozen || !frozen.type) return;
6411
+ var row_focus = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range = frozen.range) === null || _frozen$range === void 0 ? void 0 : _frozen$range.row_focus) || 0;
6412
+ var column_focus = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range2 = frozen.range) === null || _frozen$range2 === void 0 ? void 0 : _frozen$range2.column_focus) || 0;
6413
+ var xSplit = 0;
6414
+ var ySplit = 0;
6415
+ switch (frozen.type) {
6416
+ case "row":
6417
+ case "rangeRow":
6418
+ ySplit = row_focus + 1;
6419
+ break;
6420
+ case "column":
6421
+ case "rangeColumn":
6422
+ xSplit = column_focus + 1;
6423
+ break;
6424
+ case "both":
6425
+ case "rangeBoth":
6426
+ xSplit = column_focus + 1;
6427
+ ySplit = row_focus + 1;
6428
+ break;
6429
+ default:
6430
+ return;
6431
+ }
6432
+ if (xSplit === 0 && ySplit === 0) return;
6433
+ worksheet.views = [{
6434
+ state: "frozen",
6435
+ xSplit: xSplit,
6436
+ ySplit: ySplit
6437
+ }];
6438
+ }
6404
6439
 
6405
6440
  function exportSheetExcel(_x, _x2) {
6406
6441
  return _exportSheetExcel.apply(this, arguments);
@@ -6423,6 +6458,7 @@ function _exportSheetExcel() {
6423
6458
  setMerge(table === null || table === void 0 ? void 0 : (_table$config = table.config) === null || _table$config === void 0 ? void 0 : _table$config.merge, worksheet);
6424
6459
  setBorder(table, worksheet);
6425
6460
  setHiddenRowCol(table, worksheet);
6461
+ setFreeze(table, worksheet);
6426
6462
  return true;
6427
6463
  });
6428
6464
  _context.next = 5;
package/dist/index.js CHANGED
@@ -1610,12 +1610,12 @@ function rgb2hex(color) {
1610
1610
  if (_a2 === 0) {
1611
1611
  return "#FFFFFFFF";
1612
1612
  }
1613
- var alphaValue = 25 - clampedA * 255;
1613
+ var alphaValue = Math.round(clampedA * 255);
1614
1614
  var aHex = toHex(alphaValue);
1615
1615
  var rHex = toHex(clampedR);
1616
1616
  var gHex = toHex(clampedG);
1617
1617
  var bHex = toHex(clampedB);
1618
- return "#".concat(rHex).concat(gHex).concat(bHex).concat(aHex);
1618
+ return "#".concat(aHex).concat(rHex).concat(gHex).concat(bHex);
1619
1619
  }
1620
1620
  return "#FFFFFFFF";
1621
1621
  }
@@ -5027,7 +5027,7 @@ var fontConvert = function fontConvert() {
5027
5027
  };
5028
5028
  var color = rgb2hex(fc);
5029
5029
  var font = {
5030
- size: fs,
5030
+ size: Number.isFinite(fs) && fs > 0 ? fs : 10,
5031
5031
  color: {
5032
5032
  argb: color.replace("#", "")
5033
5033
  },
@@ -5094,13 +5094,15 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5094
5094
  cellArr.forEach(function (row, rowid) {
5095
5095
  var _table$config, _table$config$rowlen;
5096
5096
  var dbrow = worksheet.getRow(rowid + 1);
5097
- dbrow.height = (((_table$config = table.config) === null || _table$config === void 0 ? void 0 : (_table$config$rowlen = _table$config.rowlen) === null || _table$config$rowlen === void 0 ? void 0 : _table$config$rowlen[rowid]) || 19) / 1.2;
5097
+ var rowHeight = (((_table$config = table.config) === null || _table$config === void 0 ? void 0 : (_table$config$rowlen = _table$config.rowlen) === null || _table$config$rowlen === void 0 ? void 0 : _table$config$rowlen[rowid]) || 19) / 1.2;
5098
+ dbrow.height = Number.isFinite(rowHeight) && rowHeight > 0 ? rowHeight : 19 / 1.2;
5098
5099
  row.every(function (cell, columnid) {
5099
5100
  var _cell$ct7;
5100
5101
  if (rowid === 0) {
5101
5102
  var _table$config2, _table$config2$column;
5102
5103
  var dobCol = worksheet.getColumn(columnid + 1);
5103
- dobCol.width = (((_table$config2 = table.config) === null || _table$config2 === void 0 ? void 0 : (_table$config2$column = _table$config2.columnlen) === null || _table$config2$column === void 0 ? void 0 : _table$config2$column[columnid]) || 73) / 8;
5104
+ var colWidth = (((_table$config2 = table.config) === null || _table$config2 === void 0 ? void 0 : (_table$config2$column = _table$config2.columnlen) === null || _table$config2$column === void 0 ? void 0 : _table$config2$column[columnid]) || 73) / 8;
5105
+ dobCol.width = Number.isFinite(colWidth) && colWidth > 0 ? colWidth : 73 / 8;
5104
5106
  }
5105
5107
  if (!cell) return true;
5106
5108
  function getFa() {
@@ -5159,17 +5161,18 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5159
5161
  v += val.v;
5160
5162
  });
5161
5163
  } else if (cell.ct && ctT === "n") {
5162
- if (v !== undefined) {
5163
- var _cell$v;
5164
- v = (_cell$v = cell.v) !== null && _cell$v !== void 0 ? _cell$v : +cell.v;
5165
- }
5166
- if (cell.ct !== "General") {
5167
- numFmt = getFa();
5164
+ var _cell$ct8;
5165
+ var numVal = +cell.v;
5166
+ v = Number.isNaN(numVal) ? cell.v : numVal;
5167
+ if (((_cell$ct8 = cell.ct) === null || _cell$ct8 === void 0 ? void 0 : _cell$ct8.fa) && cell.ct.fa !== "General") {
5168
+ var fa = getFa();
5169
+ if (fa) numFmt = fa;
5168
5170
  }
5169
5171
  } else if (cell.ct && ctT === "d") {
5170
5172
  var mockDate = isTime(cell.ct.fa) ? "2000-01-01 " : "";
5171
5173
  v = new Date(mockDate + cell.m);
5172
- numFmt = getFa();
5174
+ var _fa = getFa();
5175
+ if (_fa) numFmt = _fa;
5173
5176
  } else {
5174
5177
  v = cell.v;
5175
5178
  }
@@ -6413,6 +6416,38 @@ function setHiddenRowCol(table, worksheet) {
6413
6416
  worksheet.getColumn(parseInt(col) + 1).hidden = true;
6414
6417
  }
6415
6418
  }
6419
+ function setFreeze(table, worksheet) {
6420
+ var _frozen$range, _frozen$range2;
6421
+ var frozen = table === null || table === void 0 ? void 0 : table.frozen;
6422
+ if (!frozen || !frozen.type) return;
6423
+ var row_focus = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range = frozen.range) === null || _frozen$range === void 0 ? void 0 : _frozen$range.row_focus) || 0;
6424
+ var column_focus = (frozen === null || frozen === void 0 ? void 0 : (_frozen$range2 = frozen.range) === null || _frozen$range2 === void 0 ? void 0 : _frozen$range2.column_focus) || 0;
6425
+ var xSplit = 0;
6426
+ var ySplit = 0;
6427
+ switch (frozen.type) {
6428
+ case "row":
6429
+ case "rangeRow":
6430
+ ySplit = row_focus + 1;
6431
+ break;
6432
+ case "column":
6433
+ case "rangeColumn":
6434
+ xSplit = column_focus + 1;
6435
+ break;
6436
+ case "both":
6437
+ case "rangeBoth":
6438
+ xSplit = column_focus + 1;
6439
+ ySplit = row_focus + 1;
6440
+ break;
6441
+ default:
6442
+ return;
6443
+ }
6444
+ if (xSplit === 0 && ySplit === 0) return;
6445
+ worksheet.views = [{
6446
+ state: "frozen",
6447
+ xSplit: xSplit,
6448
+ ySplit: ySplit
6449
+ }];
6450
+ }
6416
6451
 
6417
6452
  function exportSheetExcel(_x, _x2) {
6418
6453
  return _exportSheetExcel.apply(this, arguments);
@@ -6435,6 +6470,7 @@ function _exportSheetExcel() {
6435
6470
  setMerge(table === null || table === void 0 ? void 0 : (_table$config = table.config) === null || _table$config === void 0 ? void 0 : _table$config.merge, worksheet);
6436
6471
  setBorder(table, worksheet);
6437
6472
  setHiddenRowCol(table, worksheet);
6473
+ setFreeze(table, worksheet);
6438
6474
  return true;
6439
6475
  });
6440
6476
  _context.next = 5;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leankylin-sheet/excel",
3
- "version": "5.2.28",
3
+ "version": "5.2.30",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.esm.js",