@chenchaolong/plugin-trade-compliance-workbench 1.0.33 → 1.0.34

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.
@@ -32,13 +32,85 @@ function toUniverSnapshot(workbook) {
32
32
  const rowIndex = rowNumber - 1; const columnIndex = columnNumber - 1
33
33
  cellData[rowIndex] ||= {}
34
34
  const raw = cell.value && typeof cell.value === 'object' && 'result' in cell.value ? cell.value.result : cell.value
35
- cellData[rowIndex][columnIndex] = { v: raw instanceof Date ? raw.toISOString().slice(0, 10) : raw == null ? '' : String(raw), t: typeof raw === 'number' ? 2 : 1 }
35
+ cellData[rowIndex][columnIndex] = { v: raw instanceof Date ? raw.toISOString().slice(0, 10) : raw == null ? '' : String(raw), t: typeof raw === 'number' ? 2 : 1, s: cellStyle(cell) }
36
36
  }))
37
- sheets[id] = { id, name: worksheet.name, rowCount: Math.max(worksheet.rowCount + 20, 100), columnCount: Math.max(worksheet.columnCount + 5, 26), cellData, mergeData: [] }
37
+ sheets[id] = { id, name: worksheet.name, rowCount: Math.max(worksheet.rowCount + 20, 100), columnCount: Math.max(worksheet.columnCount + 5, 26), cellData, mergeData: mergeData(worksheet), rowData: rowData(worksheet), columnData: columnData(worksheet) }
38
38
  })
39
39
  return { id: `trade-${Date.now()}`, name: '销售文件审核', appVersion: '1.0.0', locale: 'zhCN', sheetOrder, sheets }
40
40
  }
41
41
 
42
+ function mergeData(worksheet) {
43
+ return Object.values(worksheet._merges || {}).map(merge => {
44
+ const model = merge.model || merge
45
+ return { startRow: model.top - 1, endRow: model.bottom - 1, startColumn: model.left - 1, endColumn: model.right - 1 }
46
+ }).filter(range => range.endRow >= range.startRow && range.endColumn >= range.startColumn)
47
+ }
48
+
49
+ function rowData(worksheet) {
50
+ const rows = {}
51
+ worksheet.eachRow({ includeEmpty: true }, row => {
52
+ if (row.height) rows[row.number - 1] = { h: row.height * 96 / 72 }
53
+ })
54
+ return rows
55
+ }
56
+
57
+ function columnData(worksheet) {
58
+ const columns = {}
59
+ worksheet.columns.forEach((column, index) => {
60
+ if (column.width) columns[index] = { w: Math.max(1, Math.floor(column.width * 7 + 5)) }
61
+ })
62
+ return columns
63
+ }
64
+
65
+ function cellStyle(cell) {
66
+ const style = {}
67
+ const font = cell.font || {}
68
+ const alignment = cell.alignment || {}
69
+ const fill = cell.fill || {}
70
+ const border = cell.border || {}
71
+ if (font.name) style.ff = font.name
72
+ if (font.size) style.fs = font.size
73
+ if (font.bold) style.bl = 1
74
+ if (font.italic) style.it = 1
75
+ if (font.underline) style.ul = { s: 1 }
76
+ if (font.strike) style.st = { s: 1 }
77
+ const fontColor = color(font.color)
78
+ if (fontColor) style.cl = { rgb: fontColor }
79
+ const fillColor = color(fill.fgColor || fill.bgColor)
80
+ if (fillColor) style.bg = { rgb: fillColor }
81
+ const horizontal = horizontalAlign(alignment.horizontal)
82
+ if (horizontal) style.ht = horizontal
83
+ const vertical = verticalAlign(alignment.vertical)
84
+ if (vertical) style.vt = vertical
85
+ if (alignment.wrapText) style.tb = 2
86
+ const borders = borderStyle(border)
87
+ if (borders) style.bd = borders
88
+ return Object.keys(style).length ? style : undefined
89
+ }
90
+
91
+ function color(value) {
92
+ const argb = typeof value?.argb === 'string' ? value.argb : ''
93
+ return argb.length === 8 ? argb.slice(2) : argb || undefined
94
+ }
95
+
96
+ function horizontalAlign(value) {
97
+ return { left: 1, center: 2, right: 3, justify: 4 }[value] || undefined
98
+ }
99
+
100
+ function verticalAlign(value) {
101
+ return { top: 1, middle: 2, bottom: 3 }[value] || undefined
102
+ }
103
+
104
+ function borderStyle(border) {
105
+ const result = {}
106
+ const map = { top: 't', right: 'r', bottom: 'b', left: 'l' }
107
+ for (const [excelKey, univerKey] of Object.entries(map)) {
108
+ const side = border[excelKey]
109
+ if (side?.style) result[univerKey] = { s: side.style === 'medium' || side.style === 'thick' ? 2 : 1, cl: { rgb: color(side.color) || '000000' } }
110
+ }
111
+ return Object.keys(result).length ? result : undefined
112
+ }
113
+
42
114
  function applyUniverSnapshot(workbook, snapshot) {
43
115
  for (const id of snapshot.sheetOrder || Object.keys(snapshot.sheets || {})) {
44
116
  const source = snapshot.sheets[id]; const target = workbook.getWorksheet(source.name)