@trebco/treb 26.0.3 → 26.0.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "26.0.3",
3
+ "version": "26.0.5",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -510,6 +510,66 @@ export class Exporter {
510
510
  }
511
511
  */
512
512
 
513
+ /**
514
+ * FIXME: we might not always need this.
515
+ */
516
+ public SheetStyle(sheet: SerializedSheet, style_cache: StyleCache) {
517
+
518
+ if (!sheet.sheet_style) {
519
+ return 0;
520
+ }
521
+
522
+ const options = style_cache.StyleOptionsFromProperties(sheet.sheet_style);
523
+ return style_cache.EnsureStyle(options);
524
+
525
+ }
526
+
527
+ public RowStyle(sheet: SerializedSheet, style_cache: StyleCache, row: number) {
528
+
529
+ const cell_style_refs = sheet.styles || sheet.cell_style_refs || [];
530
+ const list: Style.Properties[] = [sheet.sheet_style];
531
+
532
+ if (sheet.row_style) {
533
+ let style = sheet.row_style[row];
534
+ if (typeof style === 'number') {
535
+ style = cell_style_refs[style];
536
+ if (style) {
537
+ list.push(style);
538
+ }
539
+ }
540
+ else if (style) {
541
+ list.push(style);
542
+ }
543
+ }
544
+
545
+ const options = style_cache.StyleOptionsFromProperties(Style.Composite(list));
546
+ return style_cache.EnsureStyle(options);
547
+
548
+ }
549
+
550
+ public ColumnStyle(sheet: SerializedSheet, style_cache: StyleCache, column: number) {
551
+
552
+ const cell_style_refs = sheet.styles || sheet.cell_style_refs || [];
553
+ const list: Style.Properties[] = [sheet.sheet_style];
554
+
555
+ if (sheet.column_style) {
556
+ let style = sheet.column_style[column];
557
+ if (typeof style === 'number') {
558
+ style = cell_style_refs[style];
559
+ if (style) {
560
+ list.push(style);
561
+ }
562
+ }
563
+ else if (style) {
564
+ list.push(style);
565
+ }
566
+ }
567
+
568
+ const options = style_cache.StyleOptionsFromProperties(Style.Composite(list));
569
+ return style_cache.EnsureStyle(options);
570
+
571
+ }
572
+
513
573
  public StyleFromCell(sheet: SerializedSheet, style_cache: StyleCache, row: number, column: number, style: Style.Properties = {}) {
514
574
 
515
575
  //if (row === 2 && column === 5)
@@ -1205,6 +1265,8 @@ export class Exporter {
1205
1265
  const cells = new Cells();
1206
1266
  cells.FromJSON(sheet.data, cell_style_refs);
1207
1267
 
1268
+ // console.info({ss: sheet.sheet_style, sheet});
1269
+
1208
1270
  // these are cells with style but no contents
1209
1271
 
1210
1272
  for (const entry of sheet.cell_styles) {
@@ -1249,7 +1311,20 @@ export class Exporter {
1249
1311
 
1250
1312
  // --
1251
1313
 
1314
+ //
1315
+ // this is a map of column number -> column style. we need this
1316
+ // for two things: (1) so we can skip cells that are empty, but
1317
+ // have a style from the column; and (2) so we can create the list
1318
+ // of columns, including styles.
1319
+ //
1320
+ const column_style_map: number[] = [];
1321
+
1322
+ const sheet_style = this.SheetStyle(sheet, style_cache);
1323
+
1252
1324
  for (let r = 0; r < cells.data.length; r++ ) {
1325
+
1326
+ const row_style = this.RowStyle(sheet, style_cache, r);
1327
+
1253
1328
  if (cells.data[r] && cells.data[r].length) {
1254
1329
 
1255
1330
  // push out the extent (reversed)
@@ -1262,6 +1337,11 @@ export class Exporter {
1262
1337
  const row: any = [];
1263
1338
 
1264
1339
  for (let c = 0; c < cells.data[r].length; c++) {
1340
+
1341
+ if (!column_style_map[c]) {
1342
+ column_style_map[c] = this.ColumnStyle(sheet, style_cache, c);
1343
+ }
1344
+
1265
1345
  const cell = cells.data[r][c];
1266
1346
  if (cell) {
1267
1347
 
@@ -1447,6 +1527,17 @@ export class Exporter {
1447
1527
  // s is style, index into the style table
1448
1528
  const s: number|undefined = this.StyleFromCell(sheet, style_cache, r, c, cell.style);
1449
1529
 
1530
+ if (cell.type === ValueType.undefined) {
1531
+
1532
+ // you can skip if (1) there's a row style, and style === row style;
1533
+ // (2) there's a column style, no row style, and style === column style
1534
+
1535
+ if ((row_style && s === row_style) ||
1536
+ (!row_style && (column_style_map[c] && s === column_style_map[c]))) {
1537
+ continue; // can skip
1538
+ }
1539
+ }
1540
+
1450
1541
  // v (child element) is the value
1451
1542
  let v: CellValue = undefined;
1452
1543
  let t: string|undefined;
@@ -1516,7 +1607,13 @@ export class Exporter {
1516
1607
  element.a$.t = t;
1517
1608
  }
1518
1609
  if (s !== undefined) {
1610
+
1611
+ // we could skip this if it's equal to row style,
1612
+ // or there is no row style and it's equal to column style
1613
+ // or there is no column style and it's equal to sheet style
1614
+
1519
1615
  element.a$.s = s;
1616
+
1520
1617
  }
1521
1618
  if (f !== undefined) {
1522
1619
  element.f = f;
@@ -1530,11 +1627,12 @@ export class Exporter {
1530
1627
  }
1531
1628
  }
1532
1629
 
1533
- if (row.length) {
1630
+ if (row.length || (row_style && row_style !== sheet_style)) {
1631
+
1534
1632
  const row_data: any = {
1535
1633
  a$: {
1536
1634
  r: r + 1,
1537
- spans: `${span.start + 1}:${span.end + 1}`,
1635
+ spans: `${span.start + 1}:${span.end + 1}`, // this works out to 0:0 for an empty row, will that work?
1538
1636
  },
1539
1637
  c: row,
1540
1638
  };
@@ -1546,6 +1644,11 @@ export class Exporter {
1546
1644
  row_data.a$.ht = sheet.row_height[r] * 3 / 4;
1547
1645
  }
1548
1646
 
1647
+ if (row_style && row_style !== sheet_style) {
1648
+ row_data.a$.s = row_style;
1649
+ row_data.a$.customFormat = 1;
1650
+ }
1651
+
1549
1652
  sheet_data.row.push(row_data);
1550
1653
  }
1551
1654
 
@@ -1563,6 +1666,10 @@ export class Exporter {
1563
1666
  index: number;
1564
1667
  }> = [];
1565
1668
 
1669
+ // we only need to include column style if it's !== sheet style,
1670
+ // because we'll have a default entry for columns that have the
1671
+ // sheet style. this is only for columns that are different.
1672
+
1566
1673
  if (sheet.default_column_width) {
1567
1674
  dom.worksheet.sheetFormatPr.a$.defaultColWidth = // sheet.default_column_width * one_hundred_pixels / 100;
1568
1675
  PixelsToColumnWidth(sheet.default_column_width);
@@ -1582,7 +1689,14 @@ export class Exporter {
1582
1689
 
1583
1690
  }
1584
1691
 
1692
+ let style = column_style_map[c];
1693
+ if (style && style !== sheet_style) {
1694
+ entry.style = style;
1695
+ }
1696
+
1697
+ /*
1585
1698
  let style = sheet.column_style[c];
1699
+
1586
1700
  if (typeof style === 'number') {
1587
1701
  style = cell_style_refs[style];
1588
1702
  if (style) {
@@ -1592,6 +1706,7 @@ export class Exporter {
1592
1706
  else if (style) {
1593
1707
  entry.style = style_cache.EnsureStyle(style_cache.StyleOptionsFromProperties(style));
1594
1708
  }
1709
+ */
1595
1710
 
1596
1711
  //if (sheet.column_style[c]) {
1597
1712
  // entry.style = style_cache.EnsureStyle(style_cache.StyleOptionsFromProperties(sheet.column_style[c]));
@@ -1605,8 +1720,73 @@ export class Exporter {
1605
1720
  // we're short-cutting here, these should be arranged in blocks if
1606
1721
  // there's overlap. not sure how much of an issue that is though.
1607
1722
 
1608
- if (column_entries.length) {
1609
- for (const entry of column_entries) {
1723
+ if (column_entries.length || sheet_style) {
1724
+
1725
+ const filled: any[] = [];
1726
+ const default_column_width = PixelsToColumnWidth(sheet.default_column_width || 90);
1727
+
1728
+ // FIXME: can merge these two branches
1729
+
1730
+ { // if (sheet_style) {
1731
+
1732
+ let start_index = 0;
1733
+ for (const entry of column_entries) {
1734
+ if (!entry) { continue; }
1735
+
1736
+ // fill with defaults
1737
+
1738
+ if (sheet_style && (entry.index > start_index + 1)) {
1739
+ filled.push({
1740
+ a$: {
1741
+ min: start_index + 1,
1742
+ max: entry.index,
1743
+ style: sheet_style,
1744
+ width: default_column_width,
1745
+ },
1746
+ });
1747
+ }
1748
+
1749
+ const a$: any = {
1750
+ min: entry.index + 1,
1751
+ max: entry.index + 1,
1752
+ };
1753
+ if (entry.style === undefined) {
1754
+ a$.style = sheet_style;
1755
+ }
1756
+ else {
1757
+ a$.style = entry.style;
1758
+ }
1759
+ if (entry.width !== undefined) {
1760
+ a$.width = entry.width;
1761
+ a$.customWidth = 1;
1762
+ }
1763
+ else {
1764
+ a$.width = default_column_width;
1765
+ }
1766
+
1767
+ filled.push({a$});
1768
+
1769
+ start_index = entry.index;
1770
+
1771
+ }
1772
+
1773
+ if (sheet_style && (start_index < 16384)) { // OK, sure why not
1774
+ filled.push({
1775
+ a$: {
1776
+ min: start_index + 1,
1777
+ max: 16384,
1778
+ style: sheet_style,
1779
+ width: default_column_width,
1780
+ },
1781
+ });
1782
+ }
1783
+
1784
+ dom.worksheet.cols.col = filled;
1785
+
1786
+ }
1787
+
1788
+ /*
1789
+ else {
1610
1790
  dom.worksheet.cols.col = column_entries.map(entry => {
1611
1791
  const a$: any = {
1612
1792
  min: entry.index + 1,
@@ -1621,12 +1801,15 @@ export class Exporter {
1621
1801
  }
1622
1802
  else {
1623
1803
  a$.width = // (sheet.default_column_width || 100) / 100 * one_hundred_pixels;
1624
- PixelsToColumnWidth(sheet.default_column_width || 90);
1804
+ default_column_width; // PixelsToColumnWidth(sheet.default_column_width || 90);
1625
1805
  }
1626
1806
  return {a$};
1627
1807
  });
1628
1808
  }
1809
+ console.info({cols: dom.worksheet.cols});
1810
+ */
1629
1811
  }
1812
+
1630
1813
  else {
1631
1814
  delete dom.worksheet.cols;
1632
1815
  }