MCPcopy
hub / github.com/exceljs/exceljs / fillFormula

Method fillFormula

lib/doc/worksheet.js:681–724  ·  view source on GitHub ↗
(range, formula, results, shareType = 'shared')

Source from the content-addressed store, hash-verified

679 // ===========================================================================
680 // Shared/Array Formula
681 fillFormula(range, formula, results, shareType = 'shared') {
682 // Define formula for top-left cell and share to rest
683 const decoded = colCache.decode(range);
684 const {top, left, bottom, right} = decoded;
685 const width = right - left + 1;
686 const masterAddress = colCache.encodeAddress(top, left);
687 const isShared = shareType === 'shared';
688
689 // work out result accessor
690 let getResult;
691 if (typeof results === 'function') {
692 getResult = results;
693 } else if (Array.isArray(results)) {
694 if (Array.isArray(results[0])) {
695 getResult = (row, col) => results[row - top][col - left];
696 } else {
697 // eslint-disable-next-line no-mixed-operators
698 getResult = (row, col) => results[(row - top) * width + (col - left)];
699 }
700 } else {
701 getResult = () => undefined;
702 }
703 let first = true;
704 for (let r = top; r <= bottom; r++) {
705 for (let c = left; c <= right; c++) {
706 if (first) {
707 this.getCell(r, c).value = {
708 shareType,
709 formula,
710 ref: range,
711 result: getResult(r, c),
712 };
713 first = false;
714 } else {
715 this.getCell(r, c).value = isShared
716 ? {
717 sharedFormula: masterAddress,
718 result: getResult(r, c),
719 }
720 : getResult(r, c);
721 }
722 }
723 }
724 }
725
726 // =========================================================================
727 // Images

Callers

nothing calls this directly

Calls 2

getCellMethod · 0.95
decodeMethod · 0.65

Tested by

no test coverage detected