安装、作为组件或库使用、公式语法、组件门面 API、IO 读写、事件——最后附一个可现场编辑并立刻运行的 playground。Install, use as a component or a library, formula syntax, the facade API, IO, events — and a live playground you can edit and run on the spot.
<!-- 注册 <cmx-megasheet> -->
<script type="module">
import './dist/index.js'
const el = document.getElementById('sheet')
el.setTheme('light')
el.loadWorkbook((wb) => {
wb.clearSheets()
const s = new CmxMegaSheet.Worksheet('Sheet1', {
rowCount: 100, colCount: 26, styleSheet: wb.styleSheet })
s.getCell(0,0).value('销售')
s.getCell(1,0).value(100)
s.getCell(2,0).formula('=A2*1.1')
wb.appendSheet(s)
})
</script>
import {
Workbook, Worksheet,
FormulaEngine, workbookToJSON
} from '@cmx/megasheet'
const wb = new Workbook({ sheetCount: 0 })
const ws = new Worksheet('Sheet1', {
rowCount: 20, colCount: 10, styleSheet: wb.styleSheet })
wb.appendSheet(ws)
ws.setValue(0,0, 42)
ws.setFormula(1,0, 'SUM(A1:A1)*2')
new FormulaEngine(wb).recalcAll() // A2 → 84
const json = workbookToJSON(wb) // 中性快照
npm install # 装 devDeps(typescript / vitest)
npm run build # tsc → dist(含 .d.ts)
npm test # vitest(945 单测)
node demo/check-demo.mjs # headless Chrome 逐页自检 + 零 console error
约 150 个方法,按域分组(工具栏留宿主,组件边界 = 公式栏 + 画布 + 页签栏 + 主题)。~150 methods grouped by domain (toolbar left to host; boundary = formula bar + canvas + tabs + theme).
loadWorkbook · setReportModel · setCellValues · getWorkbook(逃生舱escape hatch) · recalcapplySelectionStyle · applySelectionBorder · applySelectionFill(图案/渐变pattern/gradient) · setCellsLockedundo/redo/undoSteps · merge/unmergeSelection · insert/deleteRows/Columns · copyFormat/pasteFormatcopySelection · pasteSpecial(值/公式/格式/转置/运算/跳空values/formulas/formats/transpose/op/skip-blanks)sortRange · setAutoFilter · find/replaceAll · textToColumns · removeDuplicates · consolidatefreezePanes · freezeTrailing(尾冻结trailing) · splitPanes · showCell · setZoomsetDataValidation · setCheckbox · setHyperlink · addConditionalRule · setRichTextinsertChart(11 类11 types) · insertImage · insertShape · addComment · setSparklineexportXlsx/importXlsx · exportCsv/importCsv · exportHtml · exportPdf · getWorkbookJson/setWorkbookJsonsetTheme(light/dark/auto) · setEditable · showFormulaBar/showHeaders/showGridlines/showTabs直接求值不落格:el.evaluateFormula("SUM(A1:A5)")。Evaluate without writing a cell: el.evaluateFormula("SUM(A1:A5)").
# 相对 / 绝对
=A1 + $B$2
# 跨表 · 整列 · 整行
=Sheet1!A1 =SUM(A:A) =SUM(1:1)
# 数组字面量 · 命名区域
=SUM({1,2;3,4}) # → 10
=SUM(SALES) # defineName('SALES','A1:A5')
# 查找 · 多条件聚合
=VLOOKUP(40, A1:B5, 2, FALSE)
=SUMIFS(A1:A5, B1:B5, "x")
el.addEventListener('cmx-cell-selected', e => {
console.log(e.detail.addr) // 'B2'
})
cmx-cell-selected · cmx-cell-edited · cmx-sheet-changed · cmx-col-resized · cmx-row-resized · cmx-edit-rejected报表取数 QM/QC/JE/FS/REF 的真值由后端算好经 setReportValueMap 下发,引擎只做聚合层重算。Report fetches QM/QC/JE/FS/REF get their truth from the backend via setReportValueMap; the engine only re-aggregates.
改左边代码点「运行」,右边真 <cmx-megasheet> 立即重铺。M = CmxMegaSheet,el = 表格元素。Edit the code and hit Run; the real <cmx-megasheet> on the right re-renders. M = CmxMegaSheet, el = the element.