@leankylin-sheet/excel 5.2.29 → 5.2.31

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
  },
@@ -5079,17 +5079,18 @@ var formatHyperlink = function formatHyperlink(address) {
5079
5079
  var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5080
5080
  var cellArr = table === null || table === void 0 ? void 0 : table.data;
5081
5081
  if (!Array.isArray(cellArr)) return;
5082
- console.log('cellArr', cellArr);
5083
5082
  cellArr.forEach(function (row, rowid) {
5084
5083
  var _table$config, _table$config$rowlen;
5085
5084
  var dbrow = worksheet.getRow(rowid + 1);
5086
- 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;
5087
5087
  row.every(function (cell, columnid) {
5088
5088
  var _cell$ct7;
5089
5089
  if (rowid === 0) {
5090
5090
  var _table$config2, _table$config2$column;
5091
5091
  var dobCol = worksheet.getColumn(columnid + 1);
5092
- 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;
5093
5094
  }
5094
5095
  if (!cell) return true;
5095
5096
  function getFa() {
@@ -5152,12 +5153,14 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5152
5153
  var numVal = +cell.v;
5153
5154
  v = Number.isNaN(numVal) ? cell.v : numVal;
5154
5155
  if (((_cell$ct8 = cell.ct) === null || _cell$ct8 === void 0 ? void 0 : _cell$ct8.fa) && cell.ct.fa !== "General") {
5155
- numFmt = getFa();
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
  },
@@ -5091,17 +5091,18 @@ var formatHyperlink = function formatHyperlink(address) {
5091
5091
  var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5092
5092
  var cellArr = table === null || table === void 0 ? void 0 : table.data;
5093
5093
  if (!Array.isArray(cellArr)) return;
5094
- console.log('cellArr', cellArr);
5095
5094
  cellArr.forEach(function (row, rowid) {
5096
5095
  var _table$config, _table$config$rowlen;
5097
5096
  var dbrow = worksheet.getRow(rowid + 1);
5098
- 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;
5099
5099
  row.every(function (cell, columnid) {
5100
5100
  var _cell$ct7;
5101
5101
  if (rowid === 0) {
5102
5102
  var _table$config2, _table$config2$column;
5103
5103
  var dobCol = worksheet.getColumn(columnid + 1);
5104
- 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;
5105
5106
  }
5106
5107
  if (!cell) return true;
5107
5108
  function getFa() {
@@ -5164,12 +5165,14 @@ var setStyleAndValue = function setStyleAndValue(table, worksheet) {
5164
5165
  var numVal = +cell.v;
5165
5166
  v = Number.isNaN(numVal) ? cell.v : numVal;
5166
5167
  if (((_cell$ct8 = cell.ct) === null || _cell$ct8 === void 0 ? void 0 : _cell$ct8.fa) && cell.ct.fa !== "General") {
5167
- numFmt = getFa();
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.29",
3
+ "version": "5.2.31",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.esm.js",