1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173 |
- import {
- $u,
- Ao,
- Ar,
- Bt,
- Bu,
- Co,
- D,
- Do,
- F,
- Fn,
- Fr,
- Fu,
- Hn,
- Id,
- Ir,
- Iu,
- Jn,
- Kn,
- Ku,
- Lo,
- Me,
- Mn,
- Mr,
- Ne,
- Nl,
- Oe,
- Ol,
- Ou,
- Q,
- Rh,
- So,
- St,
- Te,
- Th,
- Tl,
- Ur,
- Vn,
- Wo,
- Wr,
- Ye,
- Zr,
- _h,
- al as al2,
- an,
- ba,
- bh,
- ch,
- ct,
- de,
- fe,
- fh,
- fr as fr2,
- fu,
- he,
- hl,
- ho,
- iu,
- jn,
- ju,
- ke,
- ko,
- kr,
- nl,
- ol,
- on,
- po,
- pr as pr2,
- re as re2,
- sl,
- un,
- vd,
- ve,
- vr,
- we as we2,
- wu as wu2,
- xs,
- yr,
- ze
- } from "./chunk-BW43Z7N3.js";
- import {
- Pr,
- fn,
- fr,
- pc,
- pr
- } from "./chunk-QRYBFJ3R.js";
- import {
- De,
- Fe,
- Fi,
- Mt,
- Nn,
- Ot,
- Pt,
- Q_,
- Tn,
- UE,
- Vr,
- Xt,
- Ze,
- Zt,
- _n,
- al,
- bE,
- ci,
- cr,
- en,
- fC,
- hi,
- hn,
- kt,
- mC,
- ot,
- pi,
- qt,
- re,
- vC,
- va,
- we,
- wu,
- xf,
- xn,
- yu
- } from "./chunk-23V3HWTR.js";
- // node_modules/.pnpm/@univerjs+sheets@0.5.5_@grpc+grpc-js@1.13.4_react@18.3.1_rxjs@7.8.1/node_modules/@univerjs/sheets/lib/es/facade.js
- var Ge = Object.defineProperty;
- var qe = (r, e, t) => e in r ? Ge(r, e, { enumerable: true, configurable: true, writable: true, value: t }) : r[e] = t;
- var b = (r, e, t) => qe(r, typeof e != "symbol" ? e + "" : e, t);
- var $t = Object.defineProperty;
- var Gt = Object.getOwnPropertyDescriptor;
- var qt2 = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? Gt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && $t(e, t, s), s;
- };
- var w = (r, e) => (t, n) => e(t, n, r);
- function Kt(r, e, t) {
- const n = t.getDefinedNameMap(r);
- if (n == null)
- return e.t("definedName.defaultName") + 1;
- const i = Array.from(Object.values(n)).length + 1, o = e.t("definedName.defaultName") + i;
- if (t.getValueByName(r, o) == null)
- return o;
- let h = i + 1;
- for (; ; ) {
- const a = e.t("definedName.defaultName") + h;
- if (t.getValueByName(r, a) == null)
- return a;
- h++;
- }
- }
- var V = class {
- constructor() {
- b(this, "_definedNameParam");
- this._definedNameParam = {
- id: qt(10),
- unitId: "",
- name: "",
- formulaOrRefString: ""
- };
- }
- /**
- * Sets the name of the defined name builder.
- * @param {string} name The name of the defined name.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setName('MyDefinedName')
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setName(e) {
- return this._definedNameParam.name = e, this;
- }
- /**
- * Sets the formula of the defined name builder.
- * @param {string }formula The formula of the defined name.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setFormula('SUM(Sheet1!$A$1)')
- * .setName('MyDefinedName')
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setFormula(e) {
- return this._definedNameParam.formulaOrRefString = `=${e}`, this;
- }
- /**
- * Sets the reference of the defined name builder.
- * @param {string} a1Notation The reference of the defined name.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setRef('Sheet1!$A$1')
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setRef(e) {
- return this._definedNameParam.formulaOrRefString = e, this;
- }
- /**
- * Sets the reference of the defined name builder by range .
- * @param {number} row The start row of the range.
- * @param {number} column The start column of the range.
- * @param {number} numRows The number of rows in the range.
- * @param {number} numColumns The number of columns in the range.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setRefByRange(1, 3, 2, 5)
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setRefByRange(e, t, n, s) {
- return this._definedNameParam.formulaOrRefString = fr({
- startRow: e,
- endRow: e + (n != null ? n : 1) - 1,
- startColumn: t,
- endColumn: t + (s != null ? s : 1) - 1
- }), this;
- }
- /**
- * Sets the comment of the defined name builder.
- * @param {string} comment The comment of the defined name.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setComment('This is a comment')
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setComment(e) {
- return this._definedNameParam.comment = e, this;
- }
- /**
- * Sets the hidden status of the defined name builder.
- * @param {boolean} hidden The hidden status of the defined name.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setHidden(true)
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- setHidden(e) {
- return this._definedNameParam.hidden = e, this;
- }
- /**
- * Builds the defined name.
- * @returns {FDefinedNameBuilder} The defined name mutation parameter.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedNameBuilder = univerAPI.newDefinedName()
- * .setRef('Sheet1!$A$1')
- * .setName('MyDefinedName')
- * .build();
- * workbook.insertDefinedNameBuilder(definedNameBuilder);
- * ```
- */
- build() {
- return this._definedNameParam;
- }
- load(e) {
- return this._definedNameParam = e, this;
- }
- };
- var F2 = class extends Fi {
- constructor(r, e, t, n, s, i, o, h, a, d) {
- super(), this._definedNameParam = r, this._injector = e, this._commandService = t, this._permissionService = n, this._worksheetProtectionRuleModel = s, this._rangeProtectionRuleModel = i, this._worksheetProtectionPointRuleModel = o, this._authzIoService = h, this._localeService = a, this._definedNamesService = d;
- }
- _apply() {
- this._definedNameParam.name === "" && (this._definedNameParam.name = Kt(this._definedNameParam.unitId, this._localeService, this._definedNamesService)), this._commandService.syncExecuteCommand(Ur.id, this._definedNameParam);
- }
- /**
- * Gets the name of the defined name.
- * @returns {string} The name of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * console.log(definedName.getName());
- * ```
- */
- getName() {
- return this._definedNameParam.name;
- }
- /**
- * Sets the name of the defined name.
- * @param {string} name The name of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedName('MyDefinedName');
- * definedName.setName('NewDefinedName');
- * ```
- */
- setName(r) {
- this._definedNameParam.name = r, this._apply();
- }
- /**
- * Sets the formula of the defined name.
- * @param {string} formula The formula of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedName('MyDefinedName');
- * definedName.setFormula('SUM(Sheet1!$A$1)');
- * ```
- */
- setFormula(r) {
- this._definedNameParam.formulaOrRefString = `=${r}`, this._apply();
- }
- /**
- * Sets the reference of the defined name.
- * @param {string} refString The reference of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setRef('Sheet1!$A$1');
- * ```
- */
- setRef(r) {
- this._definedNameParam.formulaOrRefString = r, this._apply();
- }
- /**
- * Gets the reference of the defined name.
- * @returns {string} The reference of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * console.log(definedName.getFormulaOrRefString());
- * ```
- */
- getFormulaOrRefString() {
- return this._definedNameParam.formulaOrRefString;
- }
- /**
- * Sets the reference of the defined name by range.
- * @param {number} row The start row of the range.
- * @param {number} column The start column of the range.
- * @param {number} numRows The number of rows in the range.
- * @param {number} numColumns The number of columns in the range.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setRefByRange(1, 3, 2, 5);
- * ```
- */
- setRefByRange(r, e, t, n) {
- this._definedNameParam.formulaOrRefString = fr({
- startRow: r,
- endRow: r + (t != null ? t : 1) - 1,
- startColumn: e,
- endColumn: e + (n != null ? n : 1) - 1
- }), this._apply();
- }
- /**
- * Gets the comment of the defined name.
- * @returns {string | undefined} The comment of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * console.log(definedName.getComment());
- * ```
- */
- getComment() {
- return this._definedNameParam.comment;
- }
- /**
- * Sets the comment of the defined name.
- * @param {string} comment The comment of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setComment('This is a comment');
- * ```
- */
- setComment(r) {
- this._definedNameParam.comment = r, this._apply();
- }
- /**
- * Sets the scope of the defined name to the worksheet.
- * @param {FWorksheet} worksheet The worksheet to set the scope to.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getWorksheets[0];
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setScopeToWorksheet(worksheet);
- * ```
- */
- setScopeToWorksheet(r) {
- this._definedNameParam.localSheetId = r.getSheetId(), this._apply();
- }
- /**
- * Sets the scope of the defined name to the workbook.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setScopeToWorkbook();
- * ```
- */
- setScopeToWorkbook() {
- this._definedNameParam.localSheetId = ch, this._apply();
- }
- /**
- * Sets the hidden status of the defined name.
- * @param {boolean} hidden The hidden status of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.setHidden(true);
- * ```
- */
- setHidden(r) {
- this._definedNameParam.hidden = r, this._apply();
- }
- /**
- * Deletes the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * definedName.delete();
- * ```
- */
- delete() {
- this._commandService.syncExecuteCommand(Ir.id, this._definedNameParam);
- }
- /**
- * Gets the local sheet id of the defined name.
- * @returns {string | undefined} The local sheet id of the defined name.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * console.log(definedName.getLocalSheetId());
- * ```
- */
- getLocalSheetId() {
- return this._definedNameParam.localSheetId;
- }
- /**
- * Checks if the defined name is in the workbook scope.
- * @returns {boolean} True if the defined name is in the workbook scope, false otherwise.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * console.log(definedName.isWorkbookScope());
- * ```
- */
- isWorkbookScope() {
- return this._definedNameParam.localSheetId === ch;
- }
- /**
- * Converts the defined name to a defined name builder.
- * @returns {FDefinedNameBuilder} The defined name builder.
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const definedName = workbook.getDefinedNames[0];
- * const definedNameBuilder = definedName.toBuilder();
- * const param definedNameBuilder.setName('NewDefinedName').setFormula('SUM(Sheet1!$A$1)').build();
- * workbook.updateDefinedNameBuilder(param);
- * ```
- */
- toBuilder() {
- const r = this._injector.createInstance(V);
- return r.load(this._definedNameParam), r;
- }
- };
- F2 = qt2([
- w(1, ot(Ot)),
- w(2, Pt),
- w(3, UE),
- w(4, ot(Ye)),
- w(5, ot(de)),
- w(6, ot(un)),
- w(7, ot(bE)),
- w(8, ot(Vr)),
- w(9, pr)
- ], F2);
- var Yt = Object.defineProperty;
- var Jt = Object.getOwnPropertyDescriptor;
- var Qt = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? Jt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Yt(e, t, s), s;
- };
- var R = (r, e) => (t, n) => e(t, n, r);
- var j = class extends Fi {
- constructor(e, t, n, s, i, o, h) {
- super();
- b(this, "permissionPointsDefinition", bh);
- b(this, "rangeRuleChangedAfterAuth$");
- b(this, "sheetRuleChangedAfterAuth$");
- this._injector = e, this._commandService = t, this._permissionService = n, this._worksheetProtectionRuleModel = s, this._rangeProtectionRuleModel = i, this._worksheetProtectionPointRuleModel = o, this._authzIoService = h, this.rangeRuleChangedAfterAuth$ = this._rangeProtectionRuleModel.ruleRefresh$, this.sheetRuleChangedAfterAuth$ = this._worksheetProtectionRuleModel.ruleRefresh$;
- }
- /**
- * Configures a specific permission point for a workbook.
- *
- * This function sets or updates a permission point for a workbook identified by `unitId`.
- * It creates a new permission point if it does not already exist, and updates the point with the provided value.
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
- * @param {WorkbookPermissionPointConstructor} FPointClass - The constructor function for creating a permission point instance. Other point constructors can See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
- * @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
- */
- setWorkbookPermissionPoint(e, t, n) {
- const s = new t(e);
- this._permissionService.getPermissionPoint(s.id) || this._permissionService.addPermissionPoint(s), this._permissionService.updatePermissionPoint(s.id, n);
- }
- /**
- * This function is used to set whether the workbook can be edited
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
- * @param {boolean} value - A value that controls whether the workbook can be edited
- */
- setWorkbookEditPermission(e, t) {
- this.setWorkbookPermissionPoint(e, Me, t);
- }
- /**
- * This function is used to add a base permission for a worksheet.
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
- * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
- * @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission is successfully added. If the operation fails or no result is returned, it resolves to `undefined`.
- */
- async addWorksheetBasePermission(e, t) {
- if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
- throw new Error("sheet protection cannot intersect with range protection");
- const s = await this._authzIoService.create({
- objectType: D.Worksheet,
- worksheetObject: {
- collaborators: [],
- unitID: e,
- strategies: [],
- name: "",
- scope: void 0
- }
- });
- if (this._commandService.syncExecuteCommand(ct.id, {
- unitId: e,
- subUnitId: t,
- rule: {
- permissionId: s,
- unitType: D.Worksheet,
- unitId: e,
- subUnitId: t
- }
- }))
- return s;
- }
- /**
- * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
- * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
- * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
- */
- removeWorksheetPermission(e, t) {
- this._commandService.syncExecuteCommand(St.id, {
- unitId: e,
- subUnitId: t
- }), [...we2(), ...ke()].forEach((n) => {
- const s = new n(e, t);
- this._permissionService.updatePermissionPoint(s.id, true);
- }), this._worksheetProtectionPointRuleModel.deleteRule(e, t);
- }
- /**
- * Sets the worksheet permission point by updating or adding the permission point for the worksheet.
- * If the worksheet doesn't have a base permission, it creates one to used render
- * @param {string} unitId - The unique identifier of the workbook.
- * @param {string} subUnitId - The unique identifier of the worksheet.
- * @param {WorkSheetPermissionPointConstructor} FPointClass - The constructor for the permission point class.
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
- * @param {boolean} value - The new permission value to be set for the worksheet.
- * @returns {Promise<string | undefined>} - Returns the `permissionId` if the permission point is successfully set or created. If no permission is set, it resolves to `undefined`.
- */
- async setWorksheetPermissionPoint(e, t, n, s) {
- const i = this._worksheetProtectionRuleModel.getRule(e, t);
- let o;
- if (n === Te || n === Hn)
- if (i)
- o = i.permissionId;
- else {
- if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
- throw new Error("sheet protection cannot intersect with range protection");
- o = await this.addWorksheetBasePermission(e, t);
- }
- else {
- const c = this._worksheetProtectionPointRuleModel.getRule(e, t);
- c ? o = c.permissionId : (o = await this._authzIoService.create({
- objectType: D.Worksheet,
- worksheetObject: {
- collaborators: [],
- unitID: e,
- strategies: [],
- name: "",
- scope: void 0
- }
- }), this._commandService.syncExecuteCommand(Ao.id, { unitId: e, subUnitId: t, permissionId: o }));
- }
- const a = new n(e, t);
- return this._permissionService.getPermissionPoint(a.id) || this._permissionService.addPermissionPoint(a), this._permissionService.updatePermissionPoint(a.id, s), o;
- }
- /**
- * Adds a range protection to the worksheet.
- * @param {string} unitId - The unique identifier of the workbook.
- * @param {string} subUnitId - The unique identifier of the worksheet.
- * @param {IRange[]} ranges - The ranges to be protected.
- * @returns {Promise<{ permissionId: string, ruleId: string } | undefined>} - Returns an object containing the `permissionId` and `ruleId` if the range protection is successfully added. If the operation fails or no result is returned, it resolves to `undefined`. permissionId is used to stitch permission point ID,ruleId is used to store permission rules
- */
- async addRangeBaseProtection(e, t, n) {
- const s = await this._authzIoService.create({
- objectType: D.SelectRange,
- selectRangeObject: {
- collaborators: [],
- unitID: e,
- name: "",
- scope: void 0
- }
- }), i = `ruleId_${qt(6)}`;
- if (this._worksheetProtectionRuleModel.getRule(e, t))
- throw new Error("sheet protection cannot intersect with range protection");
- if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).some((c) => c.ranges.some((v) => n.some((k) => en.intersects(k, v)))))
- throw new Error("range protection cannot intersect");
- if (this._commandService.syncExecuteCommand(Ne.id, {
- unitId: e,
- subUnitId: t,
- rules: [{
- permissionId: s,
- unitType: D.SelectRange,
- unitId: e,
- subUnitId: t,
- ranges: n,
- id: i
- }]
- }))
- return {
- permissionId: s,
- ruleId: i
- };
- }
- /**
- * Removes the range protection from the worksheet.
- * @param {string} unitId - The unique identifier of the workbook.
- * @param {string} subUnitId - The unique identifier of the worksheet.
- * @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
- */
- removeRangeProtection(e, t, n) {
- this._commandService.syncExecuteCommand(ze.id, {
- unitId: e,
- subUnitId: t,
- ruleIds: n
- }) && this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(e, t), [...ke()].forEach((o) => {
- const h = new o(e, t);
- this._permissionService.updatePermissionPoint(h.id, h.value);
- }));
- }
- /**
- * Modify the permission points of a custom area
- * @param {string} unitId - The unique identifier of the workbook.
- * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
- * @param {string} permissionId - The unique identifier of the permission that controls access to the range.
- * @param {RangePermissionPointConstructor} FPointClass - The constructor for the range permission point class.
- * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
- * @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
- */
- setRangeProtectionPermissionPoint(e, t, n, s, i) {
- const o = new s(e, t, n);
- this._permissionService.getPermissionPoint(o.id) || this._permissionService.addPermissionPoint(o), this._permissionService.updatePermissionPoint(o.id, i);
- }
- /**
- * Sets the ranges for range protection in a worksheet.
- *
- * This method finds the rule by unitId, subUnitId, and ruleId, and updates the rule with the provided ranges.
- * It checks for overlaps with existing ranges in the same subunit and shows an error message if any overlap is detected.
- * If no overlap is found, it executes the command to update the range protection with the new ranges.
- * @param {string} unitId - The unique identifier of the workbook.
- * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
- * @param {string} ruleId - The ruleId of the range protection rule that is being updated.
- * @param {IRange[]} ranges - The array of new ranges to be set for the range protection rule.
- */
- setRangeProtectionRanges(e, t, n, s) {
- const i = this._rangeProtectionRuleModel.getRule(e, t, n);
- if (i) {
- if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).filter((a) => a.id !== n).some((a) => a.ranges.some((d) => s.some((c) => en.intersects(c, d)))))
- throw new Error("range protection cannot intersect");
- this._commandService.syncExecuteCommand(he.id, {
- unitId: e,
- subUnitId: t,
- ruleId: n,
- rule: {
- ...i,
- ranges: s
- }
- });
- }
- }
- };
- j = Qt([
- R(0, ot(Ot)),
- R(1, Pt),
- R(2, UE),
- R(3, ot(Ye)),
- R(4, ot(de)),
- R(5, ot(un)),
- R(6, ot(bE))
- ], j);
- function Xt2(r) {
- switch (r) {
- case "left":
- return Xt.LEFT;
- case "center":
- return Xt.CENTER;
- case "normal":
- return Xt.RIGHT;
- default:
- throw new Error(`Invalid horizontal alignment: ${r}`);
- }
- }
- function Zt2(r) {
- switch (r) {
- case Xt.LEFT:
- return "left";
- case Xt.CENTER:
- return "center";
- case Xt.RIGHT:
- return "normal";
- default:
- throw new Error(`Invalid horizontal alignment: ${r}`);
- }
- }
- function en2(r) {
- switch (r) {
- case "top":
- return hn.TOP;
- case "middle":
- return hn.MIDDLE;
- case "bottom":
- return hn.BOTTOM;
- default:
- throw new Error(`Invalid vertical alignment: ${r}`);
- }
- }
- function tn(r) {
- switch (r) {
- case hn.TOP:
- return "top";
- case hn.MIDDLE:
- return "middle";
- case hn.BOTTOM:
- return "bottom";
- default:
- throw new Error(`Invalid vertical alignment: ${r}`);
- }
- }
- function O(r) {
- return vC(r) ? {
- f: r,
- v: null,
- p: null
- } : mC(r) ? {
- v: r,
- p: null,
- f: null
- } : (fC(r), r);
- }
- function Pe(r, e) {
- const t = new kt(), { startRow: n, startColumn: s, endRow: i, endColumn: o } = e;
- if (re.isArray(r))
- for (let h = 0; h <= i - n; h++)
- for (let a = 0; a <= o - s; a++)
- t.setValue(h + n, a + s, O(r[h][a]));
- else
- new kt(r).forValue((a, d, c) => {
- t.setValue(a, d, O(c));
- });
- return t.getMatrix();
- }
- function G(r, e) {
- return {
- startRow: r.startRow,
- endRow: r.endRow,
- startColumn: 0,
- endColumn: e.getColumnCount() - 1,
- rangeType: De.ROW
- };
- }
- function q(r, e) {
- return {
- startRow: 0,
- endRow: e.getRowCount() - 1,
- startColumn: r.startColumn,
- endColumn: r.endColumn,
- rangeType: De.COLUMN
- };
- }
- var nn = Object.defineProperty;
- var rn = Object.getOwnPropertyDescriptor;
- var sn = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? rn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && nn(e, t, s), s;
- };
- var K = (r, e) => (t, n) => e(t, n, r);
- var S = class extends al {
- constructor(r, e, t, n, s, i) {
- super(n), this._workbook = r, this._worksheet = e, this._range = t, this._injector = n, this._commandService = s, this._formulaDataModel = i;
- }
- /**
- * Get the unit ID of the current workbook
- * @returns {string} The unit ID of the workbook
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getUnitId()
- * ```
- */
- getUnitId() {
- return this._workbook.getUnitId();
- }
- /**
- * Gets the name of the worksheet
- * @returns {string} The name of the worksheet
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getSheetName()
- * ```
- */
- getSheetName() {
- return this._worksheet.getName();
- }
- /**
- * Gets the ID of the worksheet
- * @returns {string} The ID of the worksheet
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getSheetId()
- * ```
- */
- getSheetId() {
- return this._worksheet.getSheetId();
- }
- /**
- * Gets the area where the statement is applied
- * @returns {IRange} The area where the statement is applied
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getRange()
- * ```
- */
- getRange() {
- return this._range;
- }
- /**
- * Gets the starting row number of the applied area
- * @returns {number} The starting row number of the area
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getRow()
- * ```
- */
- getRow() {
- return this._range.startRow;
- }
- /**
- * Gets the starting column number of the applied area
- * @returns {number} The starting column number of the area
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getColumn()
- * ```
- */
- getColumn() {
- return this._range.startColumn;
- }
- /**
- * Gets the width of the applied area
- * @returns {number} The width of the area
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getWidth()
- * ```
- */
- getWidth() {
- return this._range.endColumn - this._range.startColumn + 1;
- }
- /**
- * Gets the height of the applied area
- * @returns {number} The height of the area
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getHeight()
- * ```
- */
- getHeight() {
- return this._range.endRow - this._range.startRow + 1;
- }
- /**
- * Return range whether this range is merged
- * @returns {boolean} if true is merged
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .isMerged()
- * ```
- */
- isMerged() {
- const { startColumn: r, startRow: e, endColumn: t, endRow: n } = this._range;
- return this._worksheet.getMergedCellRange(e, r, n, t).some((i) => en.equals(i, this._range));
- }
- /**
- * Return first cell style data in this range
- * @returns {IStyleData | null} The cell style data
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellStyleData()
- * ```
- */
- getCellStyleData() {
- var t;
- const r = this.getCellData(), e = this._workbook.getStyles();
- return r && e && (t = e.getStyleByCell(r)) != null ? t : null;
- }
- /**
- * Return first cell style in this range
- * @returns {TextStyleValue | null} The cell style
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellStyle()
- * ```
- */
- getCellStyle() {
- const r = this.getCellStyleData();
- return r ? cr.create(r) : null;
- }
- /**
- * Returns the cell styles for the cells in the range.
- * @returns {Array<Array<TextStyleValue | null>>} A two-dimensional array of cell styles.
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellStyles()
- * ```
- */
- getCellStyles() {
- const r = this.getCellDatas(), e = this._workbook.getStyles();
- return r.map((t) => t.map((n) => {
- if (!n)
- return null;
- const s = e.getStyleByCell(n);
- return s ? cr.create(s) : null;
- }));
- }
- getValue(r) {
- var e, t;
- return r ? this.getValueAndRichTextValue() : (t = (e = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) == null ? void 0 : e.v) != null ? t : null;
- }
- getValues(r) {
- var o, h;
- r && this.getValueAndRichTextValues();
- const { startRow: e, endRow: t, startColumn: n, endColumn: s } = this._range, i = [];
- for (let a = e; a <= t; a++) {
- const d = [];
- for (let c = n; c <= s; c++)
- d.push((h = (o = this._worksheet.getCell(a, c)) == null ? void 0 : o.v) != null ? h : null);
- i.push(d);
- }
- return i;
- }
- /**
- * Return first cell model data in this range
- * @returns {ICellData | null} The cell model data
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellData()
- * ```
- */
- getCellData() {
- var r;
- return (r = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) != null ? r : null;
- }
- /**
- * Alias for getCellDataGrid.
- * @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellDatas()
- * ```
- */
- getCellDatas() {
- return this.getCellDataGrid();
- }
- /**
- * Returns the cell data for the cells in the range.
- * @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCellDataGrid()
- * ```
- */
- getCellDataGrid() {
- const { startRow: r, endRow: e, startColumn: t, endColumn: n } = this._range, s = [];
- for (let i = r; i <= e; i++) {
- const o = [];
- for (let h = t; h <= n; h++)
- o.push(this._worksheet.getCellRaw(i, h));
- s.push(o);
- }
- return s;
- }
- /**
- * Returns the rich text value for the cell at the start of this range.
- * @returns {Nullable<RichTextValue>} The rich text value
- * @internal
- * @beta
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getRichTextValue()
- * ```
- */
- getRichTextValue() {
- const r = this.getCellData();
- return r != null && r.p ? new Zt(r.p) : null;
- }
- /**
- * Returns the rich text value for the cells in the range.
- * @returns {Nullable<RichTextValue>[][]} A two-dimensional array of RichTextValue objects.
- * @internal
- * @beta
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getRichTextValues()
- * ```
- */
- getRichTextValues() {
- return this.getCellDataGrid().map((e) => e.map((t) => t != null && t.p ? new Zt(t.p) : null));
- }
- /**
- * Returns the value and rich text value for the cell at the start of this range.
- * @returns {Nullable<CellValue | RichTextValue>} The value and rich text value
- * @internal
- * @beta
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getValueAndRichTextValue()
- * ```
- */
- getValueAndRichTextValue() {
- const r = this.getCellData();
- return r != null && r.p ? new Zt(r.p) : r == null ? void 0 : r.v;
- }
- /**
- * Returns the value and rich text value for the cells in the range.
- * @returns {Nullable<CellValue | RichTextValue>[][]} A two-dimensional array of value and rich text value
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getValueAndRichTextValues()
- * ```
- */
- getValueAndRichTextValues() {
- return this.getCellDatas().map((e) => e.map((t) => t != null && t.p ? new Zt(t.p) : t == null ? void 0 : t.v));
- }
- /**
- * Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are empty strings for cells with no formula.
- * @returns {string[][]} A two-dimensional array of formulas in string format.
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getFormulas()
- * ```
- */
- getFormulas() {
- const r = [], { startRow: e, endRow: t, startColumn: n, endColumn: s } = this._range, i = this._worksheet.getSheetId(), o = this._workbook.getUnitId();
- for (let h = e; h <= t; h++) {
- const a = [];
- for (let d = n; d <= s; d++) {
- const c = this._formulaDataModel.getFormulaStringByCell(h, d, i, o);
- a.push(c || "");
- }
- r.push(a);
- }
- return r;
- }
- /**
- * Returns true if the cell wrap is enabled
- * @returns {boolean} True if the cell wrap is enabled
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getWrap()
- * ```
- */
- getWrap() {
- return this._worksheet.getRange(this._range).getWrap() === we.TRUE;
- }
- /**
- * Returns the text wrapping strategy for the top left cell of the range.
- * @returns {WrapStrategy} The text wrapping strategy
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getWrapStrategy()
- * ```
- */
- getWrapStrategy() {
- return this._worksheet.getRange(this._range).getWrapStrategy();
- }
- /**
- * Returns the horizontal alignment for the top left cell of the range.
- * @returns {string} The horizontal alignment
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getHorizontalAlignment()
- * ```
- */
- getHorizontalAlignment() {
- return Zt2(this._worksheet.getRange(this._range).getHorizontalAlignment());
- }
- /**
- * Returns the vertical alignment for the top left cell of the range.
- * @returns {string} The vertical alignment
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getVerticalAlignment()
- * ```
- */
- getVerticalAlignment() {
- return tn(this._worksheet.getRange(this._range).getVerticalAlignment());
- }
- /**
- * Set custom meta data for first cell in current range.
- * @param {CustomData} data The custom meta data
- * @returns {FRange} This range, for chaining
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setCustomMetaData({ key: 'value' });
- * ```
- */
- setCustomMetaData(r) {
- return this.setValue({
- custom: r
- });
- }
- /**
- * Set custom meta data for current range.
- * @param {CustomData[][]} datas The custom meta data
- * @returns {FRange} This range, for chaining
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setCustomMetaDatas([[{ key: 'value' }]]);
- * ```
- */
- setCustomMetaDatas(r) {
- return this.setValues(r.map((e) => e.map((t) => ({ custom: t }))));
- }
- /**
- * Returns the custom meta data for the cell at the start of this range.
- * @returns {CustomData | null} The custom meta data
- * @example
- * ```
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCustomMetaData()
- * ```
- */
- getCustomMetaData() {
- var e;
- const r = this.getCellData();
- return (e = r == null ? void 0 : r.custom) != null ? e : null;
- }
- /**
- * Returns the custom meta data for the cells in the range.
- * @returns {CustomData[][]} A two-dimensional array of custom meta data
- * @example
- * ```
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .getCustomMetaDatas()
- * ```
- */
- getCustomMetaDatas() {
- return this.getCellDataGrid().map((e) => e.map((t) => {
- var n;
- return (n = t == null ? void 0 : t.custom) != null ? n : null;
- }));
- }
- /**
- * Sets basic border properties for the current range.
- * @param {BorderType} type The type of border to apply
- * @param {BorderStyleTypes} style The border style
- * @param {string} [color] Optional border color in CSS notation
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');
- * ```
- */
- setBorder(r, e, t) {
- return this._commandService.syncExecuteCommand(Ou.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- value: {
- type: r,
- style: e,
- color: t
- }
- }), this;
- }
- // #region editing
- /**
- * Set background color for current range.
- * @param {string} color The background color
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setBackgroundColor('red')
- * ```
- */
- setBackgroundColor(r) {
- return this._commandService.syncExecuteCommand(fe.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: {
- type: "bg",
- value: {
- rgb: r
- }
- }
- }), this;
- }
- /**
- * Set background color for current range.
- * @param {string} color The background color
- * @returns {FRange} This range, for chaining
- * @example
- * ```typescript
- * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')
- * ```
- */
- setBackground(r) {
- return this.setBackgroundColor(r), this;
- }
- /**
- * Set new value for current cell, first cell in this range.
- * @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
- * @returns {FRange} This range, for chaining
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setValue(1);
- * ```
- */
- setValue(r) {
- const e = O(r);
- if (!e)
- throw new Error("Invalid value");
- return this._commandService.syncExecuteCommand(on.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: e
- }), this;
- }
- /**
- * Set new value for current cell, first cell in this range.
- * @param {CellValue | ICellData} value The value can be a number, string, boolean, or standard cell format. If it begins with `=`, it is interpreted as a formula. The value is tiled to all cells in the range.
- * @returns {FRange} This range, for chaining
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setValueForCell(1);
- * ```
- */
- setValueForCell(r) {
- const e = O(r);
- if (!e)
- throw new Error("Invalid value");
- return this._commandService.syncExecuteCommand(on.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: {
- startColumn: this._range.startColumn,
- startRow: this._range.startRow,
- endColumn: this._range.endColumn,
- endRow: this._range.endRow
- },
- value: e
- }), this;
- }
- /**
- * Set the rich text value for the cell at the start of this range.
- * @param {RichTextValue | IDocumentData} value The rich text value
- * @returns {FRange} The range
- * @example
- * ```
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setRichTextValueForCell(new RichTextValue().insertText('Hello'));
- * ```
- */
- setRichTextValueForCell(r) {
- const e = r instanceof Zt ? r.getData() : r, t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: {
- startColumn: this._range.startColumn,
- startRow: this._range.startRow,
- endColumn: this._range.endColumn,
- endRow: this._range.endRow
- },
- value: { p: e }
- };
- return this._commandService.syncExecuteCommand(on.id, t), this;
- }
- /**
- * Set the rich text value for the cells in the range.
- * @param {RichTextValue[][]} values The rich text value
- * @returns {FRange} The range
- * @example
- * ```ts
- * univerAPI
- * .getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setRichTextValues([[new RichTextValue().insertText('Hello')]]);
- * ```
- */
- setRichTextValues(r) {
- const e = r.map((s) => s.map((i) => i && { p: i instanceof Zt ? i.getData() : i })), t = Pe(e, this._range), n = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: t
- };
- return this._commandService.syncExecuteCommand(on.id, n), this;
- }
- /**
- * Set the cell wrap of the given range.
- * Cells with wrap enabled (the default) resize to display their full content. Cells with wrap disabled display as much as possible in the cell without resizing or running to multiple lines.
- * @param {boolean} isWrapEnabled Whether to enable wrap
- * @returns {FRange} this range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setWrap(true);
- * ```
- */
- setWrap(r) {
- return this._commandService.syncExecuteCommand(sl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: r ? xn.WRAP : xn.UNSPECIFIED
- }), this;
- }
- /**
- * Sets the text wrapping strategy for the cells in the range.
- * @param {WrapStrategy} strategy The text wrapping strategy
- * @returns {FRange} this range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setWrapStrategy(WrapStrategy.WRAP);
- * ```
- */
- setWrapStrategy(r) {
- return this._commandService.syncExecuteCommand(sl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: r
- }), this;
- }
- /**
- * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
- * @param {"top" | "middle" | "bottom"} alignment The vertical alignment
- * @returns {FRange} this range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setVerticalAlignment('top');
- * ```
- */
- setVerticalAlignment(r) {
- return this._commandService.syncExecuteCommand(nl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: en2(r)
- }), this;
- }
- /**
- * Set the horizontal (left to right) alignment for the given range (left/center/right).
- * @param {"left" | "center" | "normal"} alignment The horizontal alignment
- * @returns {FRange} this range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setHorizontalAlignment('left');
- * ```
- */
- setHorizontalAlignment(r) {
- return this._commandService.syncExecuteCommand(ol.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: Xt2(r)
- }), this;
- }
- /**
- * Sets a different value for each cell in the range. The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats. If a value begins with `=`, it is interpreted as a formula.
- * @param {CellValue[][] | IObjectMatrixPrimitiveType<CellValue> | ICellData[][] | IObjectMatrixPrimitiveType<ICellData>} value The value can be a two-dimensional array or a standard range matrix (must match the dimensions of this range), consisting of numbers, strings, Boolean values or Composed of standard cell formats.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setValues([[1, 2], [3, 4]]);
- * ```
- */
- setValues(r) {
- const e = Pe(r, this._range);
- return this._commandService.syncExecuteCommand(on.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- value: e
- }), this;
- }
- /**
- * Sets the font weight for the given range (normal/bold),
- * @param {FontWeight|null} fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontWeight('bold');
- * ```
- */
- setFontWeight(r) {
- let e;
- if (r === "bold")
- e = we.TRUE;
- else if (r === "normal")
- e = we.FALSE;
- else if (r === null)
- e = null;
- else
- throw new Error("Invalid fontWeight");
- const t = {
- type: "bl",
- value: e
- }, n = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: t
- };
- return this._commandService.syncExecuteCommand(fe.id, n), this;
- }
- /**
- * Sets the font style for the given range ('italic' or 'normal').
- * @param {FontStyle|null} fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontStyle('italic');
- * ```
- */
- setFontStyle(r) {
- let e;
- if (r === "italic")
- e = we.TRUE;
- else if (r === "normal")
- e = we.FALSE;
- else if (r === null)
- e = null;
- else
- throw new Error("Invalid fontStyle");
- const t = {
- type: "it",
- value: e
- }, n = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: t
- };
- return this._commandService.syncExecuteCommand(fe.id, n), this;
- }
- /**
- * Sets the font line style of the given range ('underline', 'line-through', or 'none').
- * @param {FontLine|null} fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontLine('underline');
- * ```
- */
- setFontLine(r) {
- if (r === "underline")
- this._setFontUnderline({
- s: we.TRUE
- });
- else if (r === "line-through")
- this._setFontStrikethrough({
- s: we.TRUE
- });
- else if (r === "none")
- this._setFontUnderline({
- s: we.FALSE
- }), this._setFontStrikethrough({
- s: we.FALSE
- });
- else if (r === null)
- this._setFontUnderline(null), this._setFontStrikethrough(null);
- else
- throw new Error("Invalid fontLine");
- return this;
- }
- /**
- * Sets the font underline style of the given ITextDecoration
- * @param {ITextDecoration|null} value The font underline style of the given ITextDecoration; a null value resets the font underline style
- * @returns {void}
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontLine('underline');
- * ```
- */
- _setFontUnderline(r) {
- const e = {
- type: "ul",
- value: r
- }, t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: e
- };
- this._commandService.syncExecuteCommand(fe.id, t);
- }
- /**
- * Sets the font strikethrough style of the given ITextDecoration
- * @param {ITextDecoration|null} value The font strikethrough style of the given ITextDecoration; a null value resets the font strikethrough style
- * @returns {void}
- */
- _setFontStrikethrough(r) {
- const e = {
- type: "st",
- value: r
- }, t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: e
- };
- this._commandService.syncExecuteCommand(fe.id, t);
- }
- /**
- * Sets the font family, such as "Arial" or "Helvetica".
- * @param {string|null} fontFamily The font family to set; a null value resets the font family.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontFamily('Arial');
- * ```
- */
- setFontFamily(r) {
- const e = {
- type: "ff",
- value: r
- }, t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: e
- };
- return this._commandService.syncExecuteCommand(fe.id, t), this;
- }
- /**
- * Sets the font size, with the size being the point size to use.
- * @param {number|null} size A font size in point size. A null value resets the font size.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontSize(12);
- * ```
- */
- setFontSize(r) {
- const e = {
- type: "fs",
- value: r
- }, t = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: e
- };
- return this._commandService.syncExecuteCommand(fe.id, t), this;
- }
- /**
- * Sets the font color in CSS notation (such as '#ffffff' or 'white').
- * @param {string|null} color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * univerAPI.getActiveWorkbook()
- * .getActiveSheet()
- * .getActiveRange()
- * .setFontColor('#ff0000');
- * ```
- */
- setFontColor(r) {
- const t = {
- type: "cl",
- value: r === null ? null : { rgb: r }
- }, n = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- style: t
- };
- return this._commandService.syncExecuteCommand(fe.id, n), this;
- }
- // #endregion editing
- //#region Merge cell
- /**
- * Merge cells in a range into one merged cell
- * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const range = worksheet.getRange(0, 0, 2, 2);
- * const merge = range.merge();
- * const isMerged = merge.isMerged();
- * console.log('debugger', isMerged);
- * ```
- */
- merge(r = true) {
- const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
- return Th(this._injector, e, t, [this._range], r), this;
- }
- /**
- * Merges cells in a range horizontally.
- * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const range = worksheet.getRange(2, 2, 2, 2);
- * const merge = range.mergeAcross();
- * const allMerge = worksheet.getMergeData();
- * console.log(allMerge.length); // There will be two merged cells.
- * ```
- */
- mergeAcross(r = true) {
- const e = Zr([this._range], yu.ROWS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
- return Th(this._injector, t, n, e, r), this;
- }
- /**
- * Merges cells in a range vertically.
- * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const range = worksheet.getRange(4, 4, 2, 2);
- * const merge = range.mergeVertically();
- * const allMerge = worksheet.getMergeData();
- * console.log(allMerge.length); // There will be two merged cells.
- * ```
- */
- mergeVertically(r = true) {
- const e = Zr([this._range], yu.COLUMNS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
- return Th(this._injector, t, n, e, r), this;
- }
- /**
- * Returns true if cells in the current range overlap a merged cell.
- * @returns {boolean} is overlap with a merged cell
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const range = worksheet.getRange(0,0,2,2);
- * const merge = range.merge();
- * const anchor = worksheet.getRange(0,0);
- * const isPartOfMerge = anchor.isPartOfMerge();
- * console.log('debugger, isPartOfMerge) // true
- * ```
- */
- isPartOfMerge() {
- const { startRow: r, startColumn: e, endRow: t, endColumn: n } = this._range;
- return this._worksheet.getMergedCellRange(r, e, t, n).length > 0;
- }
- /**
- * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
- * @returns {FRange} This range, for chaining
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const range = worksheet.getRange(0,0,2,2);
- * const merge = range.merge();
- * const anchor = worksheet.getRange(0,0);
- * const isPartOfMergeFirst = anchor.isPartOfMerge();
- * console.log('debugger' isPartOfMergeFirst) // true
- * range.breakApart();
- * const isPartOfMergeSecond = anchor.isPartOfMerge();
- * console.log('debugger' isPartOfMergeSecond) // false
- * ```
- */
- breakApart() {
- return this._commandService.syncExecuteCommand(Iu.id, { ranges: [this._range] }), this;
- }
- //#endregion
- /**
- * Iterate cells in this range. Merged cells will be respected.
- * @param {Function} callback the callback function to be called for each cell in the range
- * @param {number} callback.row the row number of the cell
- * @param {number} callback.col the column number of the cell
- * @param {ICellData} callback.cell the cell data
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:B2');
- * fRange.forEach((row, col, cell) => {
- * console.log(row, col, cell);
- * });
- * ```
- */
- forEach(r) {
- const { startColumn: e, startRow: t, endColumn: n, endRow: s } = this._range;
- this._worksheet.getMatrixWithMergedCells(t, e, s, n).forValue((i, o, h) => {
- r(i, o, h);
- });
- }
- /**
- * Returns a string description of the range, in A1 notation.
- * @param {boolean} [withSheet] - If true, the sheet name is included in the A1 notation.
- * @returns {string} The A1 notation of the range.
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:B2');
- * console.log(fRange.getA1Notation()); // A1:B2
- * ```
- */
- getA1Notation(r) {
- return r ? pc(this._worksheet.getName(), this._range) : fr(this._range);
- }
- /**
- * Sets the specified range as the active range, with the top left cell in the range as the current cell.
- * @returns {FRange} This range, for chaining.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:B2');
- * fRange.activate(); // the active cell will be A1
- * ```
- */
- activate() {
- return this._injector.createInstance(f, this._workbook).setActiveRange(this), this;
- }
- /**
- * Sets the specified cell as the current cell.
- * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.
- * If the specified cell is not part of an existing range, then a new range is created with the cell as the active range and the current cell.
- * @returns {FRange} This range, for chaining.
- * @description If the range is not a single cell, an error will be thrown.
- */
- activateAsCurrentCell() {
- const r = this._worksheet.getMergedCell(this._range.startRow, this._range.startColumn);
- if (r && en.equals(r, this._range) || !r && this._range.startRow === this._range.endRow && this._range.startColumn === this._range.endColumn)
- return this.activate();
- throw new Error("The range is not a single cell");
- }
- /**
- * Splits a column of text into multiple columns based on a custom specified delimiter.
- * @param {boolean} [treatMultipleDelimitersAsOne] Whether to treat multiple continuous delimiters as one. The default value is false.
- * @param {SplitDelimiterEnum} [delimiter] The delimiter to use to split the text. The default delimiter is Tab(1)、Comma(2)、Semicolon(4)、Space(8)、Custom(16).A delimiter like 6 (SplitDelimiterEnum.Comma|SplitDelimiterEnum.Semicolon) means using Comma and Semicolon to split the text.
- * @param {string} [customDelimiter] The custom delimiter to split the text. An error will be thrown if custom delimiter is set but the customDelimiter is not a character.
- * @example Show how to split text to columns with combined delimiter. The bit operations are used to combine the delimiters.
- * // A1:A3 has following values:
- * // A | B | C
- * // 1;;2;3 | |
- * // 1;,2;3 | |
- * // After calling splitTextToColumns(false, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
- * // A | B | C | D
- * // 1 | | 2 | 3
- * // 1 | | 2 | 3
- * // After calling splitTextToColumns(true, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
- * // A | B | C
- * // 1 | 2 | 3
- * // 1 | 2 | 3
- * @example Show how to split text to columns with custom delimiter
- * // A1:A3 has following values:
- * // A | B | C
- * // 1#2#3 | |
- * // 4##5#6 | |
- * // After calling splitTextToColumns(false, SplitDelimiterEnum.Custom, '#'), the range will be:
- * // A | B | C | D
- * // 1 | 2 | 3 |
- * // 4 | | 5 | 6
- * // After calling splitTextToColumns(true, SplitDelimiterEnum.Custom, '#'), the range will be:
- * // A | B | C
- * // 1 | 2 | 3
- * // 4 | 5 | 6
- */
- splitTextToColumns(r, e, t) {
- this._commandService.syncExecuteCommand(Tl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- delimiter: e,
- customDelimiter: t,
- treatMultipleDelimitersAsOne: r
- });
- }
- /**
- * Set the theme style for the range.
- * @param {string|undefined} themeName The name of the theme style to apply.If a undefined value is passed, the theme style will be removed if it exist.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:E20');
- * fRange.useThemeStyle('default');
- * ```
- */
- useThemeStyle(r) {
- if (r == null) {
- const e = this.getUsedThemeStyle();
- e && this.removeThemeStyle(e);
- } else
- this._commandService.syncExecuteCommand(ba.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- themeName: r
- });
- }
- /**
- * Remove the theme style for the range.
- * @param {string} themeName The name of the theme style to remove.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:E20');
- * fRange.removeThemeStyle('default');
- * ```
- */
- removeThemeStyle(r) {
- this._commandService.syncExecuteCommand(iu.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range,
- themeName: r
- });
- }
- /**
- * Gets the theme style applied to the range.
- * @returns {string | undefined} The name of the theme style applied to the range or not exist.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fRange = fWorksheet.getRange('A1:E20');
- * fRange.useThemeStyle('default');
- * const themeStyle = fRange.getUsedThemeStyle();
- * console.log(themeStyle); // 'default'
- * ```
- */
- getUsedThemeStyle() {
- return this._injector.get(ho).getAppliedRangeThemeStyle({
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: this._range
- });
- }
- };
- S = sn([
- K(3, ot(Ot)),
- K(4, Pt),
- K(5, ot(Pr))
- ], S);
- var on2 = Object.defineProperty;
- var hn2 = Object.getOwnPropertyDescriptor;
- var an2 = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? hn2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && on2(e, t, s), s;
- };
- var dn = (r, e) => (t, n) => e(t, n, r);
- var L = class {
- constructor(r, e, t, n) {
- this._workbook = r, this._worksheet = e, this._selections = t, this._injector = n;
- }
- /**
- * Represents the active selection in the sheet. Which means the selection contains the active cell.
- * @returns {FRange | null} The active selection.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fSelection = fWorksheet.getSelection();
- * const activeRange = fSelection.getActiveRange();
- * console.log(activeRange);
- * ```
- */
- getActiveRange() {
- const r = this._selections.find((e) => !!e.primary);
- return r ? this._injector.createInstance(S, this._workbook, this._worksheet, r.range) : null;
- }
- /**
- * Represents the active selection list in the sheet.
- * @returns {FRange[]} The active selection list.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fSelection = fWorksheet.getSelection();
- * const activeRangeList = fSelection.getActiveRangeList();
- * console.log(activeRangeList);
- * ```
- */
- getActiveRangeList() {
- return this._selections.map((r) => this._injector.createInstance(S, this._workbook, this._worksheet, r.range));
- }
- /**
- * Represents the current select cell in the sheet.
- * @returns {ISelectionCell} The current select cell info.Pay attention to the type of the return value.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fSelection = fWorksheet.getSelection();
- * const currentCell = fSelection.getCurrentCell();
- * console.log(currentCell);
- * ```
- */
- getCurrentCell() {
- const r = this._selections.find((e) => !!e.primary);
- return r ? r.primary : null;
- }
- /**
- * Returns the active sheet in the spreadsheet.
- * @returns {FWorksheet} The active sheet in the spreadsheet.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fSelection = fWorksheet.getSelection();
- * const activeSheet = fSelection.getActiveSheet();
- * console.log(activeSheet.equalTo(fWorksheet)); // true
- * ```
- */
- getActiveSheet() {
- const r = this._injector.createInstance(f, this._workbook);
- return this._injector.createInstance(m, r, this._workbook, this._worksheet);
- }
- /**
- * Update the primary cell in the selection. if the primary cell not exists in selections, add it to the selections and clear the old selections.
- * @param {FRange} cell The new primary cell to update.
- * @returns {FSelection} The new selection after updating the primary cell.Because the selection is immutable, the return value is a new selection.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * const fSelection = fWorksheet.getSelection();
- * const cell = fWorksheet.getCell('A1');
- * const newSelection = fSelection.updatePrimaryCell(cell);
- * console.log(newSelection.getActiveRange().getA1Notation()); // A1
- * ```
- */
- updatePrimaryCell(r) {
- const e = this._injector.get(Pt);
- let t = [], n = false;
- for (const { range: i, style: o } of this._selections)
- en.contains(i, r.getRange()) ? (t.push({
- range: i,
- primary: ve(r.getRange(), this._worksheet),
- style: o
- }), n = true) : t.push({
- range: i,
- primary: null,
- style: o
- });
- n || (t = [
- {
- range: r.getRange(),
- primary: ve(r.getRange(), this._worksheet)
- }
- ]);
- const s = {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- selections: t
- };
- return e.syncExecuteCommand(re2.id, s), new L(this._workbook, this._worksheet, t, this._injector);
- }
- /**
- *Get the next primary cell in the specified direction. If the primary cell not exists in selections, return null.
- * @param {Direction} direction The direction to move the primary cell.The enum value is maybe one of the following: UP(0),RIGHT(1), DOWN(2), LEFT(3).
- * @returns {FRange | null} The next primary cell in the specified direction.
- * @example
- * ```ts
- * // import { Direction } from '@univerjs/core';
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * // make sure the active cell is A1 and selection is A1:C3
- * const fSelection = fWorksheet.getSelection();
- * const nextCell = fSelection.getNextDataRange(Direction.RIGHT);
- * console.log(nextCell?.getA1Notation()); // B1
- * ```
- */
- getNextDataRange(r) {
- if (!this._selections.find((n) => !!n.primary))
- return null;
- const t = _h(this._selections.concat(), r, this._worksheet);
- return t ? this._injector.createInstance(S, this._workbook, this._worksheet, t) : null;
- }
- };
- L = an2([
- dn(3, ot(Ot))
- ], L);
- var cn = Object.defineProperty;
- var un2 = Object.getOwnPropertyDescriptor;
- var gn = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? un2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && cn(e, t, s), s;
- };
- var B = (r, e) => (t, n) => e(t, n, r);
- var m = class extends al {
- /**
- * Creates a new worksheet facade instance
- * @param {FWorkbook} _fWorkbook - The facade workbook instance
- * @param {Workbook} _workbook - The workbook instance
- * @param {Worksheet} _worksheet - The worksheet instance
- * @param {Injector} _injector - The injector instance
- * @param {SheetsSelectionsService} _selectionManagerService - The selection manager service
- * @param {ILogService} _logService - The log service
- * @param {ICommandService} _commandService - The command service
- */
- constructor(e, t, n, s, i, o, h) {
- super(s);
- b(this, "setActiveSelection", this.setActiveRange);
- this._fWorkbook = e, this._workbook = t, this._worksheet = n, this._injector = s, this._selectionManagerService = i, this._logService = o, this._commandService = h;
- }
- /**
- * Returns the worksheet
- * @returns {Worksheet} The worksheet instance.
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet().getSheet();
- * ```
- */
- getSheet() {
- return this._worksheet;
- }
- /**
- * Returns the injector
- * @returns {Injector} The injector
- * @example
- * ```typescript
- * const injector = univerAPI.getActiveWorkbook().getActiveSheet().getInject();
- * ```
- */
- getInject() {
- return this._injector;
- }
- /**
- * Returns the workbook
- * @returns {Workbook} The workbook instance.
- * @example
- * ```typescript
- * const workbook = univerAPI.getActiveWorkbook().getWorkbook();
- * ```
- */
- getWorkbook() {
- return this._workbook;
- }
- /**
- * Returns the worksheet id.
- * @returns {string} The id of the worksheet.
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- * const id = sheet.getSheetId();
- * ```
- */
- getSheetId() {
- return this._worksheet.getSheetId();
- }
- /**
- * Returns the worksheet name.
- * @returns {string} The name of the worksheet.
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- * const name = sheet.getSheetName();
- * ```
- */
- getSheetName() {
- return this._worksheet.getName();
- }
- /**
- * Represents the selection ranges info of the worksheet.
- * @returns {FSelection} return the current selections of the worksheet or null if there is no selection.
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- * const selections = sheet.getSelection();
- * ```
- */
- getSelection() {
- const e = this._selectionManagerService.getCurrentSelections();
- return e ? this._injector.createInstance(L, this._workbook, this._worksheet, e) : null;
- }
- // #region rows
- // #region default style
- /**
- * Get the default style of the worksheet
- * @returns {IStyleData} Default style of the worksheet.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * const defaultStyle = sheet.getDefaultStyle();
- * ```
- */
- getDefaultStyle() {
- return this._worksheet.getDefaultCellStyle();
- }
- /**
- * Get the default style of the worksheet row
- * @param {number} index - The row index
- * @param {boolean} [keepRaw] - If true, return the raw style data maybe the style name or style data, otherwise return the data from row manager
- * @returns {(Nullable<IStyleData> | string)} The default style of the worksheet row name or style data
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- * // Get default style for row 0 (1)
- * const rowStyle = sheet.getRowDefaultStyle(0);
- * // Get raw style data for row 0
- * const rawRowStyle = sheet.getRowDefaultStyle(0, true);
- * ```
- */
- getRowDefaultStyle(e, t = false) {
- return this._worksheet.getRowStyle(e, t);
- }
- /**
- * Get the default style of the worksheet column
- * @param {number} index - The column index
- * @param {boolean} [keepRaw] - If true, return the raw style data maybe the style name or style data, otherwise return the data from col manager
- * @returns {(Nullable<IStyleData> | string)} The default style of the worksheet column name or style data
- * @example
- * ```typescript
- * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
- * // Get default style for column 0 (A)
- * const colStyle = sheet.getColumnDefaultStyle(0);
- * // Get raw style data for column 0
- * const rawColStyle = sheet.getColumnDefaultStyle(0, true);
- * ```
- */
- getColumnDefaultStyle(e, t = false) {
- return this._worksheet.getColumnStyle(e, t);
- }
- /**
- * Set the default style of the worksheet
- * @param {string} style - The style to set
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * fWorksheet.setDefaultStyle('default');
- * ```
- */
- setDefaultStyle(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
- return this._commandService.syncExecuteCommand(Bt.id, {
- unitId: t,
- subUnitId: n,
- defaultStyle: e
- }), this._worksheet.setDefaultCellStyle(e), this;
- }
- /**
- * Set the default style of the worksheet row
- * @param {number} index - The row index
- * @param {string | Nullable<IStyleData>} style - The style name or style data
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * fWorksheet.setRowDefaultStyle(0, 'default');
- * ```
- */
- setColumnDefaultStyle(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- unitId: n,
- subUnitId: s,
- columnData: {
- [e]: {
- s: t
- }
- }
- };
- return this._commandService.syncExecuteCommand($u.id, i), this;
- }
- /**
- * Set the default style of the worksheet column
- * @param {number} index - The column index
- * @param {string | Nullable<IStyleData>} style - The style name or style data
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorksheet = fWorkbook.getActiveSheet();
- * fWorksheet.setColumnDefaultStyle(0, 'default');
- * ```
- */
- setRowDefaultStyle(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- unitId: n,
- subUnitId: s,
- rowData: {
- [e]: {
- s: t
- }
- }
- };
- return this._commandService.syncExecuteCommand(Ku.id, i), this;
- }
- getRange(e, t, n, s) {
- let i, o;
- if (typeof e == "object")
- i = e, o = this._worksheet;
- else if (typeof e == "string") {
- const { range: h, sheetName: a } = fn(e), d = a ? this._workbook.getSheetBySheetName(a) : this._worksheet;
- if (!d)
- throw new Error("Range not found");
- o = d, i = {
- ...h,
- unitId: this._workbook.getUnitId(),
- sheetId: o.getSheetId(),
- // Use the current range instead of the future actual range to match Apps Script behavior.
- // Users can create the latest range in real time when needed.
- rangeType: De.NORMAL,
- startRow: h.rangeType === De.COLUMN ? 0 : h.startRow,
- endRow: h.rangeType === De.COLUMN ? o.getMaxRows() - 1 : h.endRow,
- startColumn: h.rangeType === De.ROW ? 0 : h.startColumn,
- endColumn: h.rangeType === De.ROW ? o.getMaxColumns() - 1 : h.endColumn
- };
- } else if (typeof e == "number" && t !== void 0)
- o = this._worksheet, i = {
- startRow: e,
- endRow: e + (n != null ? n : 1) - 1,
- startColumn: t,
- endColumn: t + (s != null ? s : 1) - 1,
- unitId: this._workbook.getUnitId(),
- sheetId: this._worksheet.getSheetId()
- };
- else
- throw new Error("Invalid range specification");
- return this._injector.createInstance(S, this._workbook, o, i);
- }
- /**
- * Returns the current number of columns in the sheet, regardless of content.
- * @returns {number} The maximum columns count of the sheet
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * const totalColumns = sheet.getMaxColumns();
- * console.log(`Sheet has ${totalColumns} columns`);
- * ```
- */
- getMaxColumns() {
- return this._worksheet.getMaxColumns();
- }
- /**
- * Returns the current number of rows in the sheet, regardless of content.
- * @returns {number}The maximum rows count of the sheet
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * const totalRows = sheet.getMaxRows();
- * console.log(`Sheet has ${totalRows} rows`);
- * ```
- */
- getMaxRows() {
- return this._worksheet.getMaxRows();
- }
- /**
- * Inserts a row after the given row position.
- * @param {number} afterPosition - The row after which the new row should be added, starting at 0 for the first row.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 rows at row index 2 (before the third row)
- * sheet.insertRowAfter(2);
- * // Insert 1 row at row index 0 (before the first row)
- * sheet.insertRowAfter(0);
- * ```
- */
- insertRowAfter(e) {
- return this.insertRowsAfter(e, 1);
- }
- /**
- * Inserts a row before the given row position.
- * @param {number} beforePosition - The row before which the new row should be added, starting at 0 for the first row.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 rows at row index 2 (before the third row)
- * sheet.insertRowBefore(2);
- * // Insert 1 row at row index 0 (before the first row)
- * sheet.insertRowBefore(0);
- * ```
- */
- insertRowBefore(e) {
- return this.insertRowsBefore(e, 1);
- }
- /**
- * Inserts one or more consecutive blank rows in a sheet starting at the specified location.
- * @param {number} rowIndex - The index indicating where to insert a row, starting at 0 for the first row.
- * @param {number} numRows - The number of rows to insert.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 rows at row index 2 (before the third row)
- * sheet.insertRows(2, 3);
- * // Insert 1 row at row index 0 (before the first row)
- * sheet.insertRows(0);
- * ```
- */
- insertRows(e, t = 1) {
- return this.insertRowsBefore(e, t);
- }
- /**
- * Inserts a number of rows after the given row position.
- * @param {number} afterPosition - The row after which the new rows should be added, starting at 0 for the first row.
- * @param {number} howMany - The number of rows to insert.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 rows at row index 2 (before the third row)
- * sheet.insertRowsAfter(2, 3);
- * // Insert 1 row at row index 0 (before the first row)
- * sheet.insertRowsAfter(0);
- * ```
- */
- insertRowsAfter(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = wu.DOWN, o = e + 1, h = e + t, a = 0, d = this._worksheet.getColumnCount() - 1, c = Vn(this._worksheet, o, h, a, d, true, e);
- return this._commandService.syncExecuteCommand(fr2.id, {
- unitId: n,
- subUnitId: s,
- direction: i,
- range: {
- startRow: o,
- endRow: h,
- startColumn: a,
- endColumn: d
- },
- cellValue: c
- }), this;
- }
- /**
- * Inserts a number of rows before the given row position.
- * @param {number} beforePosition - The row before which the new rows should be added, starting at 0 for the first row.
- * @param {number} howMany - The number of rows to insert.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 rows at row index 2 (before the third row)
- * sheet.insertRowsBefore(2, 3);
- * // Insert 1 row at row index 0 (before the first row)
- * sheet.insertRowsBefore(0);
- * ```
- */
- insertRowsBefore(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = wu.UP, o = e, h = e + t - 1, a = 0, d = this._worksheet.getColumnCount() - 1, c = Vn(this._worksheet, o, h, a, d, true, e - 1);
- return this._commandService.syncExecuteCommand(fr2.id, {
- unitId: n,
- subUnitId: s,
- direction: i,
- range: {
- startRow: o,
- endRow: h,
- startColumn: a,
- endColumn: d
- },
- cellValue: c
- }), this;
- }
- /**
- * Deletes the row at the given row position.
- * @param {number} rowPosition - The position of the row, starting at 0 for the first row.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Delete 3 rows at row index 2 (rows 3-5)
- * sheet.deleteRow(2);
- * // Delete 1 row at row index 0 (first row)
- * sheet.deleteRow(0);
- * ```
- */
- deleteRow(e) {
- return this.deleteRows(e, 1);
- }
- /**
- * Deletes a number of rows starting at the given row position.
- * @param {number} rowPosition - The position of the first row to delete, starting at 0 for the first row.
- * @param {number} howMany - The number of rows to delete.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Delete 3 rows at row index 2 (rows 3-5)
- * sheet.deleteRows(2, 3);
- * // Delete 1 row at row index 0 (first row)
- * sheet.deleteRows(0);
- * ```
- */
- deleteRows(e, t) {
- const n = {
- startRow: e,
- endRow: e + t - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- };
- return this._commandService.syncExecuteCommand(vr.id, {
- range: n,
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId()
- }), this;
- }
- /**
- * Moves the rows selected by the given range to the position indicated by the destinationIndex. The rowSpec itself does not have to exactly represent an entire row or group of rows to move—it selects all rows that the range spans.
- * @param {FRange} rowSpec - A range spanning the rows that should be moved.
- * @param {number} destinationIndex - The index that the rows should be moved to. Note that this index is based on the coordinates before the rows are moved. Existing data is shifted down to make room for the moved rows while the source rows are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Move 3 rows at row index 2 (rows 3-5) to row index 0
- * sheet.moveRows(rowSpec, 0);
- * // Move 1 row at row index 0 (first row) to row index 2
- * sheet.moveRows(rowSpec, 2);
- * ```
- */
- moveRows(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = G(e.getRange(), this._worksheet), o = i, h = {
- startRow: t,
- endRow: t,
- startColumn: i.startColumn,
- endColumn: i.endColumn
- };
- return this._commandService.syncExecuteCommand(Fn.id, {
- unitId: n,
- subUnitId: s,
- range: i,
- fromRange: o,
- toRange: h
- }), this;
- }
- /**
- * Hides the rows in the given range.
- * @param {FRange} row - The row range to hide.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Hide 3 rows starting from row index 1 (rows 2-4)
- * sheet.hideRow(1);
- * // Hide single row at index 0 (first row)
- * sheet.hideRow(0);
- * ```
- */
- hideRow(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = G(e.getRange(), this._worksheet);
- return this._commandService.syncExecuteCommand(kr.id, {
- unitId: t,
- subUnitId: n,
- ranges: [s]
- }), this;
- }
- /**
- * Hides one or more consecutive rows starting at the given index. Use 0-index for this method
- * @param {number} rowIndex - The starting index of the rows to hide
- * @param {number} numRow - The number of rows to hide
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Hide 3 rows starting from row index 1 (rows 2-4)
- * sheet.hideRows(1, 3);
- * // Hide single row at index 0 (first row)
- * sheet.hideRows(0);
- * ```
- */
- hideRows(e, t = 1) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- startRow: e,
- endRow: e + t - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1,
- rangeType: De.ROW
- };
- return this._commandService.syncExecuteCommand(kr.id, {
- unitId: n,
- subUnitId: s,
- ranges: [i]
- }), this;
- }
- /**
- * Make the row in the given range visible.
- * @param {FRange} row - The range to unhide, if hidden.
- * @returns {FWorksheet} This sheet, for chaining.
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Unhide 3 rows starting from row index 1 (rows 2-4)
- * sheet.unhideRow(1);
- * // Unhide single row at index 0 (first row)
- * sheet.unhideRow(0);
- * ```
- */
- unhideRow(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = G(e.getRange(), this._worksheet);
- return this._commandService.syncExecuteCommand(Jn.id, {
- unitId: t,
- subUnitId: n,
- ranges: [s]
- }), this;
- }
- /**
- * Scrolling sheet to make specific rows visible.
- * @param {number} rowIndex - The starting index of the rows
- * @param {number} numRow - The number of rows
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Show 3 rows starting from row index 1 (rows 2-4)
- * sheet.showRows(1);
- * // Show single row at index 0 (first row)
- * sheet.showRows(0);
- * ```
- */
- showRows(e, t = 1) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- startRow: e,
- endRow: e + t - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1,
- rangeType: De.ROW
- };
- return this._commandService.syncExecuteCommand(Jn.id, {
- unitId: n,
- subUnitId: s,
- ranges: [i]
- }), this;
- }
- /**
- * Sets the row height of the given row in pixels. By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
- * @param {number} rowPosition - The row position to change.
- * @param {number} height - The height in pixels to set it to.
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Set the height of the second row to 30 pixels
- * sheet.setRowHeight(1, 30);
- * // Set the height of the first row to 20 pixels
- * sheet.setRowHeight(0, 20);
- * ```
- */
- setRowHeight(e, t) {
- return this.setRowHeights(e, 1, t);
- }
- /**
- * Make certain row wrap and auto height.
- * @param rowPosition
- * @param auto
- * @returns {FWorksheet} this
- * @example
- * ```ts
- const fWorkbook = univerAPI.getActiveWorkbook();
- const fWorkSheet = fWorkbook.getActiveSheet();
- fWorkSheet.autoFitRow(24);
- * ```
- */
- autoFitRow(e, t = we.TRUE) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = [{
- startRow: e,
- endRow: e,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- }];
- return this._commandService.syncExecuteCommand(sl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- range: i[0],
- value: xn.WRAP
- }), this._commandService.syncExecuteCommand(
- Oe.id,
- {
- unitId: n,
- subUnitId: s,
- ranges: i,
- autoHeightInfo: t
- }
- ), this;
- }
- /**
- * Sets the height of the given rows in pixels.
- * By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
- * @param {number} startRow - The starting row position to change
- * @param {number} numRows - The number of rows to change
- * @param {number} height - The height in pixels to set it to
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * sheet.setRowHeights(1, 10, 30);
- * ```
- */
- setRowHeights(e, t, n) {
- var d;
- const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = this._worksheet.getRowManager(), h = [], a = [];
- for (let c = e; c < e + t; c++) {
- const v = ((d = o.getRow(c)) == null ? void 0 : d.ah) || this._worksheet.getConfig().defaultRowHeight, k = {
- startRow: c,
- endRow: c,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- };
- n <= v ? h.push(k) : a.push(k);
- }
- return a.length > 0 && this._commandService.syncExecuteCommand(Wo.id, {
- unitId: s,
- subUnitId: i,
- ranges: a,
- value: n
- }), h.length > 0 && this._commandService.syncExecuteCommand(Lo.id, {
- unitId: s,
- subUnitId: i,
- ranges: h
- }), this;
- }
- /**
- * Sets the height of the given rows to auto.
- * @param {number} startRow - The starting row position to change
- * @param {number} numRows - The number of rows to change
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * sheet.setRowAutoHeight(1, 10);
- * ```
- */
- setRowAutoHeight(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = [
- {
- startRow: e,
- endRow: e + t - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- }
- ];
- return this._commandService.syncExecuteCommand(Lo.id, {
- unitId: n,
- subUnitId: s,
- ranges: i
- }), this;
- }
- /**
- * Sets the height of the given rows in pixels. By default, rows grow to fit cell contents. When you use setRowHeightsForced, rows are forced to the specified height even if the cell contents are taller than the row height.
- * @param {number} startRow - The starting row position to change
- * @param {number} numRows - The number of rows to change
- * @param {number} height - The height in pixels to set it to
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * sheet.setRowHeightsForced(1, 10, 30);
- * ```
- */
- setRowHeightsForced(e, t, n) {
- const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = [
- {
- startRow: e,
- endRow: e + t - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- }
- ];
- return this._commandService.syncExecuteCommand(Wo.id, {
- unitId: s,
- subUnitId: i,
- ranges: o,
- value: n
- }), this;
- }
- // #endregion
- /**
- * Set custom properties for given rows.
- * @param {IObjectArrayPrimitiveType<CustomData>} custom - The custom properties to set
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setRowCustom({ key: 'value' });
- * ```
- */
- setRowCustom(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
- for (const [o, h] of Object.entries(e))
- s[Number(o)] = {
- custom: h
- };
- const i = {
- unitId: t,
- subUnitId: n,
- rowData: s
- };
- return this._commandService.syncExecuteCommand(Ku.id, i), this;
- }
- // #region Column
- /**
- * Inserts a column after the given column position.
- * @param {number} afterPosition - The column after which the new column should be added, starting at 0 for the first column
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 columns at column index 2 (before column C)
- * sheet.insertColumnAfter(2);
- * // Insert 1 column at column index 0 (before column A)
- * sheet.insertColumnAfter(0);
- * ```
- */
- insertColumnAfter(e) {
- return this.insertColumnsAfter(e, 1);
- }
- /**
- * Inserts a column before the given column position.
- * @param {number} beforePosition - The column before which the new column should be added, starting at 0 for the first column
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 columns at column index 2 (before column C)
- * sheet.insertColumnBefore(2);
- * // Insert 1 column at column index 0 (before column A)
- * sheet.insertColumnBefore(0);
- * ```
- */
- insertColumnBefore(e) {
- return this.insertColumnsBefore(e, 1);
- }
- /**
- * Inserts one or more consecutive blank columns in a sheet starting at the specified location.
- * @param {number} columnIndex - The index indicating where to insert a column, starting at 0 for the first column
- * @param {number} numColumns - The number of columns to insert
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 columns at column index 2 (before column C)
- * sheet.insertColumns(2, 3);
- * // Insert 1 column at column index 0 (before column A)
- * sheet.insertColumns(0);
- * ```
- */
- insertColumns(e, t = 1) {
- return this.insertColumnsBefore(e, t);
- }
- /**
- * Inserts a given number of columns after the given column position.
- * @param {number} afterPosition - The column after which the new columns should be added, starting at 0 for the first column
- * @param {number} howMany - The number of columns to insert
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 columns at column index 2 (before column C)
- * sheet.insertColumnsAfter(2, 3);
- * // Insert 1 column at column index 0 (before column A)
- * sheet.insertColumnsAfter(0, 1);
- * ```
- */
- insertColumnsAfter(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = wu.RIGHT, o = 0, h = this._worksheet.getRowCount() - 1, a = e + 1, d = e + t, c = Vn(this._worksheet, o, h, a, d, false, e);
- return this._commandService.syncExecuteCommand(pr2.id, {
- unitId: n,
- subUnitId: s,
- direction: i,
- range: {
- startRow: o,
- endRow: h,
- startColumn: a,
- endColumn: d
- },
- cellValue: c
- }), this;
- }
- /**
- * Inserts a number of columns before the given column position.
- * @param {number} beforePosition - The column before which the new columns should be added, starting at 0 for the first column
- * @param {number} howMany - The number of columns to insert
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Insert 3 columns at column index 2 (before column C)
- * sheet.insertColumnsBefore(2, 3);
- * // Insert 1 column at column index 0 (before column A)
- * sheet.insertColumnsBefore(0, 1);
- * ```
- */
- insertColumnsBefore(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = wu.LEFT, o = 0, h = this._worksheet.getRowCount() - 1, a = e, d = e + t - 1, c = Vn(this._worksheet, o, h, a, d, false, e - 1);
- return this._commandService.syncExecuteCommand(pr2.id, {
- unitId: n,
- subUnitId: s,
- direction: i,
- range: {
- startRow: o,
- endRow: h,
- startColumn: a,
- endColumn: d
- },
- cellValue: c
- }), this;
- }
- /**
- * Deletes the column at the given column position.
- * @param {number} columnPosition - The position of the column, starting at 0 for the first column
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Delete column C
- * sheet.deleteColumn(2);
- * // Delete column A
- * sheet.deleteColumn(0);
- * ```
- */
- deleteColumn(e) {
- return this.deleteColumns(e, 1);
- }
- /**
- * Deletes a number of columns starting at the given column position.
- * @param {number} columnPosition - The position of the first column to delete, starting at 0 for the first column
- * @param {number} howMany - The number of columns to delete
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Delete 3 columns at column index 2 (columns C, D, E)
- * sheet.deleteColumns(2, 3);
- * // Delete 1 column at column index 0 (column A)
- * sheet.deleteColumns(0, 1);
- * ```
- */
- deleteColumns(e, t) {
- const n = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: e,
- endColumn: e + t - 1
- };
- return this._commandService.syncExecuteCommand(Mr.id, {
- range: n,
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId()
- }), this;
- }
- /**
- * Moves the columns selected by the given range to the position indicated by the destinationIndex. The columnSpec itself does not have to exactly represent an entire column or group of columns to move—it selects all columns that the range spans.
- * @param {FRange} columnSpec - A range spanning the columns that should be moved
- * @param {number} destinationIndex - The index that the columns should be moved to. Note that this index is based on the coordinates before the columns are moved. Existing data is shifted right to make room for the moved columns while the source columns are removed from the grid. Therefore, the data may end up at a different index than originally specified. Use 0-index for this method
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Move columns C, D, E to column index 2 (columns B, C, D)
- * sheet.moveColumns({ startColumn: 2, endColumn: 4 }, 1);
- * // Move column A to column index 0 (column A)
- * sheet.moveColumns({ startColumn: 0, endColumn: 0 }, 0);
- * ```
- */
- moveColumns(e, t) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = q(e.getRange(), this._worksheet), o = i, h = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: t,
- endColumn: t
- };
- return this._commandService.syncExecuteCommand(jn.id, {
- unitId: n,
- subUnitId: s,
- range: i,
- fromRange: o,
- toRange: h
- }), this;
- }
- /**
- * Hides the column or columns in the given range.
- * @param {FRange} column - The column range to hide
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Hide columns C, D, E
- * sheet.hideColumn({ startColumn: 2, endColumn: 4 });
- * // Hide column A
- * sheet.hideColumn({ startColumn: 0, endColumn: 0 });
- * ```
- */
- hideColumn(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = q(e.getRange(), this._worksheet);
- return this._commandService.syncExecuteCommand(yr.id, {
- unitId: t,
- subUnitId: n,
- ranges: [s]
- }), this;
- }
- /**
- * Hides one or more consecutive columns starting at the given index. Use 0-index for this method
- * @param {number} columnIndex - The starting index of the columns to hide
- * @param {number} numColumn - The number of columns to hide
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Hide columns C, D, E
- * sheet.hideColumns(2, 3);
- * // Hide column A
- * sheet.hideColumns(0, 1);
- * ```
- */
- hideColumns(e, t = 1) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: e,
- endColumn: e + t - 1,
- rangeType: De.COLUMN
- };
- return this._commandService.syncExecuteCommand(yr.id, {
- unitId: n,
- subUnitId: s,
- ranges: [i]
- }), this;
- }
- /**
- * Show the column in the given range.
- * @param {FRange} column - The range to unhide, if hidden
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Unhide columns C, D, E
- * sheet.unhideColumn({ startColumn: 2, endColumn: 4 });
- * // Unhide column A
- * sheet.unhideColumn({ startColumn: 0, endColumn: 0 });
- * ```
- */
- unhideColumn(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = q(e.getRange(), this._worksheet);
- return this._commandService.syncExecuteCommand(Kn.id, {
- unitId: t,
- subUnitId: n,
- ranges: [s]
- }), this;
- }
- /**
- * Show one or more consecutive columns starting at the given index. Use 0-index for this method
- * @param {number} columnIndex - The starting index of the columns to unhide
- * @param {number} numColumn - The number of columns to unhide
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Unhide columns C, D, E
- * sheet.unhideColumns(2, 3);
- * // Unhide column A
- * sheet.unhideColumns(0, 1);
- * ```
- */
- showColumns(e, t = 1) {
- const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: e,
- endColumn: e + t - 1,
- rangeType: De.COLUMN
- };
- return this._commandService.syncExecuteCommand(Kn.id, {
- unitId: n,
- subUnitId: s,
- ranges: [i]
- }), this;
- }
- /**
- * Sets the width of the given column in pixels.
- * @param {number} columnPosition - The position of the given column to set
- * @param {number} width - The width in pixels to set it to
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Set width of column B to 100 pixels
- * sheet.setColumnWidth(1, 100);
- * ```
- */
- setColumnWidth(e, t) {
- return this.setColumnWidths(e, 1, t);
- }
- /**
- * Sets the width of the given columns in pixels.
- * @param {number} startColumn - The starting column position to change
- * @param {number} numColumn - The number of columns to change
- * @param {number} width - The width in pixels to set it to
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Set width of columns B-D (index 1-3) to 100 pixels
- * sheet.setColumnWidths(1, 3, 100);
- * ```
- */
- setColumnWidths(e, t, n) {
- const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = [
- {
- startColumn: e,
- endColumn: e + t - 1,
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1
- }
- ];
- return this._commandService.syncExecuteCommand(Mn.id, {
- unitId: s,
- subUnitId: i,
- ranges: o,
- value: n
- }), this;
- }
- // #endregion
- /**
- * Set custom properties for given columns.
- * @param {IObjectArrayPrimitiveType<CustomData>} custom - The custom properties to set
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setColumnCustom({ 0: { key: 'value' } });
- * ```
- */
- setColumnCustom(e) {
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
- for (const [o, h] of Object.entries(e))
- s[Number(o)] = {
- custom: h
- };
- const i = {
- unitId: t,
- subUnitId: n,
- columnData: s
- };
- return this._commandService.syncExecuteCommand($u.id, i), this;
- }
- // #region merge cells
- /**
- * Get all merged cells in the current sheet
- * @returns {FRange[]} all merged cells
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Get all merged ranges in the sheet
- * const mergedRanges = sheet.getMergedRanges();
- * // Process each merged range
- * mergedRanges.forEach(range => {
- * console.log(range.getA1Notation());
- * });
- * ```
- */
- getMergedRanges() {
- return this._worksheet.getSnapshot().mergeData.map((t) => this._injector.createInstance(S, this._workbook, this._worksheet, t));
- }
- /**
- * Get the merged cell data of the specified row and column.
- * @param {number} row - The row index
- * @param {number} column - The column index
- * @returns {FRange|undefined} The merged cell data, or undefined if the cell is not merged
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const merge = fWorkSheet.getCellMergeData(0, 0);
- * if (merge) {
- * console.log('Merged range:', merge.getA1Notation());
- * }
- * ```
- */
- getCellMergeData(e, t) {
- const s = this._worksheet.getMergedCell(e, t);
- if (s)
- return this._injector.createInstance(S, this._workbook, this._worksheet, s);
- }
- // #endregion
- /**
- * Returns the selected range in the active sheet, or null if there is no active range.
- * @returns {FRange | null} the active range
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Get the currently active range
- * const activeRange = sheet.getActiveRange();
- * if (activeRange) {
- * console.log('Active range:', activeRange.getA1Notation());
- * }
- * ```
- */
- getActiveRange() {
- return this._fWorkbook.getActiveRange();
- }
- /**
- * Sets the active selection region for this sheet.
- * @param {FRange} range - The range to set as the active selection
- * @returns {FWorksheet} This sheet, for chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setActiveRange(fWorkSheet.getRange('A1'));
- * ```
- */
- setActiveRange(e) {
- const { unitId: t, sheetId: n } = e.getRange();
- if (t !== this._workbook.getUnitId() || n !== this._worksheet.getSheetId())
- throw new Error("Specified range must be part of the sheet.");
- return this._fWorkbook.setActiveRange(e), this;
- }
- /**
- * Sets the frozen state of the current sheet.
- * @param {IFreeze} freeze - the scrolling viewport start range and count of freezed rows and columns.
- * that means if you want to freeze the first 3 rows and 2 columns, you should set freeze as { startRow: 3, startColumn: 2, xSplit: 2, ySplit: 3 }
- * @deprecated use `setFrozenRows` and `setFrozenColumns` instead.
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Freeze first 3 rows and 2 columns
- * sheet.setFreeze({
- * startRow: 3,
- * startColumn: 2,
- * xSplit: 2,
- * ySplit: 3
- * });
- * ```
- */
- setFreeze(e) {
- return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"), this._commandService.syncExecuteCommand(Bu.id, {
- ...e,
- unitId: this._workbook.getUnitId(),
- subUnitId: this.getSheetId()
- }), this;
- }
- /**
- * Cancels the frozen state of the current sheet.
- * @returns {FWorksheet} This worksheet instance for chaining
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Cancel freeze
- * sheet.cancelFreeze();
- * ```
- */
- cancelFreeze() {
- return this._commandService.syncExecuteCommand(Fu.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this.getSheetId()
- }), this;
- }
- /**
- * Get the freeze state of the current sheet.
- * @returns {IFreeze} The freeze state of the current sheet
- * @example
- * ```typescript
- * const sheet = workbook.getActiveSheet();
- * // Get the freeze state of the current sheet
- * const freeze = sheet.getFreeze();
- * console.log(freeze);
- * ```
- */
- getFreeze() {
- return this._worksheet.getFreeze();
- }
- setFrozenColumns(...e) {
- const t = this.getFreeze();
- if (arguments.length === 1) {
- const n = e[0];
- this.setFreeze({
- ...t,
- startColumn: n > 0 ? n : -1,
- xSplit: n
- });
- } else if (arguments.length === 2) {
- let [n = 0, s = 0] = e;
- n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(Bu.id, {
- startColumn: s + 1,
- xSplit: s - n + 1,
- startRow: t.startRow,
- ySplit: t.ySplit,
- unitId: this._workbook.getUnitId(),
- subUnitId: this.getSheetId()
- });
- }
- return this;
- }
- setFrozenRows(...e) {
- const t = this.getFreeze();
- if (arguments.length === 1) {
- const n = e[0];
- this.setFreeze({
- ...t,
- startRow: n > 0 ? n : -1,
- ySplit: n
- });
- } else if (arguments.length === 2) {
- let [n = 0, s = 0] = e;
- n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(Bu.id, {
- startRow: s + 1,
- ySplit: s - n + 1,
- startColumn: t.startColumn,
- xSplit: t.xSplit,
- unitId: this._workbook.getUnitId(),
- subUnitId: this.getSheetId()
- });
- }
- return this;
- }
- /**
- * Get the number of frozen columns.
- * @returns {number} The number of frozen columns, returns 0 if no columns are frozen.
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // Get the number of frozen columns
- * const frozenColumns = fWorkSheet.getFrozenColumns();
- * console.log(frozenColumns);
- * ```
- */
- getFrozenColumns() {
- const e = this.getFreeze();
- return e.startColumn === -1 ? 0 : e.startColumn;
- }
- /**
- * Get the number of frozen rows.
- * @returns {number} The number of frozen rows. returns 0 if no rows are frozen.
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // Get the number of frozen rows
- * const frozenRows = fWorkSheet.getFrozenRows();
- * console.log(frozenRows);
- * ```
- */
- getFrozenRows() {
- const e = this.getFreeze();
- return e.startRow === -1 ? 0 : e.startRow;
- }
- /**
- * Get freezed rows.
- * @returns {IRowRange} The range of the frozen rows.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // Get the range of the frozen rows
- * const frozenRows = fWorkSheet.getFrozenRowRange();
- * console.log(frozenRows);
- * ```
- */
- getFrozenRowRange() {
- const e = this._worksheet.getFreeze();
- return {
- startRow: e.startRow - e.ySplit,
- endRow: e.startRow - 1
- };
- }
- /**
- * Get freezed columns
- * @returns {IColumnRange} The range of the frozen columns.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // Get the range of the frozen columns
- * const frozenColumns = fWorkSheet.getFrozenColumnRange();
- * console.log(frozenColumns);
- * ```
- */
- getFrozenColumnRange() {
- const e = this._worksheet.getFreeze();
- return {
- startColumn: e.startColumn - e.xSplit,
- endColumn: e.startColumn - 1
- };
- }
- /**
- * Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
- * @returns {boolean} True if the sheet's gridlines are hidden; otherwise false.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // check if the gridlines are hidden
- * if (fWorkSheet.hasHiddenGridLines()) {
- * console.log('Gridlines are hidden');
- * }
- * ```
- */
- hasHiddenGridLines() {
- return this._worksheet.getConfig().showGridlines === we.FALSE;
- }
- /**
- * Hides or reveals the sheet gridlines.
- * @param {boolean} hidden - If `true`, hide gridlines in this sheet; otherwise show the gridlines.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ``` ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // hide the gridlines
- * fWorkSheet.setHiddenGridlines(true);
- * ```
- */
- setHiddenGridlines(e) {
- return this._commandService.syncExecuteCommand(Nl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- showGridlines: e ? we.FALSE : we.TRUE
- }), this;
- }
- /**
- * Set the color of the gridlines in the sheet.
- * @param {string|undefined} color - The color to set for the gridlines.Undefined or null to reset to the default color.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // set the gridlines color to red
- * fWorkSheet.setGridLinesColor('#ff0000');
- * ```
- */
- setGridLinesColor(e) {
- return this._commandService.syncExecuteCommand(ju.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- color: e
- }), this;
- }
- /**
- * Get the color of the gridlines in the sheet.
- * @returns {string | undefined} The color of the gridlines in the sheet or undefined. The default color is 'rgb(214, 216, 219)'.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // get the gridlines color of the sheet
- * console.log(fWorkSheet.getGridLinesColor());
- * ```
- */
- getGridLinesColor() {
- return this._worksheet.getGridlinesColor();
- }
- /**
- * Sets the sheet tab color.
- * @param {string|null|undefined} color - A color code in CSS notation (like '#ffffff' or 'white'), or null to reset the tab color.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // set the tab color to red
- * fWorkSheet.setTabColor('#ff0000');
- * ```
- */
- setTabColor(e) {
- return this._commandService.syncExecuteCommand(al2.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- color: e
- }), this;
- }
- /**
- * Get the tab color of the sheet.
- * @returns {string} The tab color of the sheet or undefined.
- * The default color is css style property 'unset'.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // get the tab color of the sheet
- * console.log(fWorkSheet.getTabColor());
- * ```
- */
- getTabColor() {
- return this._worksheet.getTabColor();
- }
- // eslint-disable-next-line
- /**
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback)` instead
- */
- onCellDataChange(e) {
- return this._injector.get(Pt).onCommandExecuted((n) => {
- if (n.id === Q.id) {
- const s = n.params;
- s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new kt(s.cellValue));
- }
- });
- }
- // eslint-disable-next-line
- /**
- * @deprecated use `univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback)` instead
- */
- onBeforeCellDataChange(e) {
- return this._injector.get(Pt).beforeCommandExecuted((n) => {
- if (n.id === Q.id) {
- const s = n.params;
- s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new kt(s.cellValue));
- }
- });
- }
- /**
- * Hides this sheet. Has no effect if the sheet is already hidden. If this method is called on the only visible sheet, it throws an exception.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // hide the active sheet
- * fWorkSheet.hideSheet();
- * ```
- */
- hideSheet() {
- const e = this._injector.get(Pt);
- if (this._workbook.getSheets().filter((i) => i.isSheetHidden() !== we.TRUE).length <= 1)
- throw new Error("Cannot hide the only visible sheet");
- return e.syncExecuteCommand(hl.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId()
- }), this;
- }
- /**
- * Shows this sheet. Has no effect if the sheet is already visible.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheets = fWorkbook.getSheets();
- * // show the last sheet
- * fWorkSheets[fWorkSheets.length - 1].showSheet();
- * ```
- */
- showSheet() {
- return this._injector.get(Pt).syncExecuteCommand(Fr.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId()
- }), this;
- }
- /**
- * Returns true if the sheet is currently hidden.
- * @returns {boolean} True if the sheet is hidden; otherwise, false.
- */
- isSheetHidden() {
- return this._worksheet.isSheetHidden() === we.TRUE;
- }
- /**
- * Sets the sheet name.
- * @param {string} name - The new name for the sheet.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // set the sheet name to 'Sheet1'
- * fWorkSheet.setName('Sheet1');
- * ```
- */
- setName(e) {
- return this._commandService.syncExecuteCommand(Do.id, {
- unitId: this._workbook.getUnitId(),
- subUnitId: this._worksheet.getSheetId(),
- name: e
- }), this;
- }
- /**
- * Activates this sheet. Does not alter the sheet itself, only the parent's notion of the active sheet.
- * @returns {FWorksheet} Current sheet, for chaining.
- */
- activate() {
- return this._fWorkbook.setActiveSheet(this), this;
- }
- /**
- * Gets the position of the sheet in its parent spreadsheet. Starts at 0.
- * @returns {number} The position of the sheet in its parent spreadsheet.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // get the position of the active sheet
- * const position = fWorkSheet.getIndex();
- * console.log(position); // 0
- * ```
- */
- getIndex() {
- return this._workbook.getSheetIndex(this._worksheet);
- }
- /**
- * Clears the sheet of content and formatting information.Or Optionally clears only the contents or only the formatting.
- * @param {IFacadeClearOptions} [options] - Options for clearing the sheet. If not provided, the contents and formatting are cleared both.
- * @param {boolean} [options.contentsOnly] - If true, the contents of the sheet are cleared. If false, the contents and formatting are cleared. Default is false.
- * @param {boolean} [options.formatOnly] - If true, the formatting of the sheet is cleared. If false, the contents and formatting are cleared. Default is false.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // clear the sheet of content and formatting information
- * fWorkSheet.clear();
- * // clear the sheet of content only
- * fWorkSheet.clear({ contentsOnly: true });
- * ```
- */
- clear(e) {
- e && e.contentsOnly && !e.formatOnly && this.clearContents(), e && e.formatOnly && !e.contentsOnly && this.clearFormats();
- const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = this._injector.get(Pt), i = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- };
- return s.syncExecuteCommand(po.id, {
- unitId: t,
- subUnitId: n,
- ranges: [i],
- options: e
- }), this;
- }
- /**
- * Clears the sheet of contents, while preserving formatting information.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // clear the sheet of content only
- * fWorkSheet.clearContents();
- * ```
- */
- clearContents() {
- const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(Pt), s = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- };
- return n.syncExecuteCommand(Co.id, {
- unitId: e,
- subUnitId: t,
- ranges: [s]
- }), this;
- }
- /**
- * Clears the sheet of formatting, while preserving contents.
- * @returns {FWorksheet} Returns the current worksheet instance for method chaining
- * @example
- * ```typescript
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // clear the sheet of formatting only
- * fWorkSheet.clearFormats();
- * ```
- */
- clearFormats() {
- const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(Pt), s = {
- startRow: 0,
- endRow: this._worksheet.getRowCount() - 1,
- startColumn: 0,
- endColumn: this._worksheet.getColumnCount() - 1
- };
- return n.syncExecuteCommand(So.id, {
- unitId: e,
- subUnitId: t,
- ranges: [s]
- }), this;
- }
- /**
- * Returns a Range corresponding to the dimensions in which data is present.
- * This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).
- * @returns {FRange} The range of the data in the sheet.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * // the sheet is a empty sheet
- * const cellRange = fWorkSheet.getRange(200, 10, 1, 1);
- * cellRange.setValue('Hello World');
- * console.log(fWorkSheet.getDataRange().getA1Notation()); // A1:J200
- * ```
- */
- getDataRange() {
- const e = this.getLastRows(), t = this.getLastColumns();
- return this.getRange(0, 0, e + 1, t + 1);
- }
- /**
- * Returns the position of the last column that has content.
- * @returns {number} the last column of the sheet that contains content.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
- * console.log(fWorkSheet.getLastColumns()); // 20
- * ```
- */
- getLastColumns() {
- return this._worksheet.getLastColumnWithContent();
- }
- /**
- * @deprecated use getLastColumn instead.
- * Returns the position of the last column that has content. Same as getLastColumns.
- * @returns {number} the last column of the sheet that contains content.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
- * console.log(fWorkSheet.getLastColumn());
- * ```
- */
- getLastColumn() {
- return this._worksheet.getLastColumnWithContent();
- }
- /**
- * @deprecated use getLastRow instead.
- * Returns the position of the last row that has content.
- * @returns {number} the last row of the sheet that contains content.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const fRange = fWorkSheet.getRange(100,1,1,1);
- * fRange.setValue('Hello World');
- * console.log(fWorkSheet.getLastRows()); // 100
- */
- getLastRows() {
- return this._worksheet.getLastRowWithContent();
- }
- /**
- * Returns the position of the last row that has content, same as getLastRows().
- * @returns {number} the last row of the sheet that contains content.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const fRange = fWorkSheet.getRange(100,1,1,1);
- * fRange.setValue('Hello World');
- * console.log(fWorkSheet.getLastRow());
- */
- getLastRow() {
- return this._worksheet.getLastRowWithContent();
- }
- /**
- * Judge whether provided FWorksheet is equal to current.
- * @param {FWorksheet} other - the FWorksheet to compare with.
- * @returns {boolean} true if the FWorksheet is equal to the current FWorksheet, false otherwise.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const fWorkSheet2 = fWorkbook.getSheetByName('Sheet1');
- * console.log(fWorkSheet.equals(fWorkSheet2)); // true, if the active sheet is 'Sheet1'
- * ```
- */
- equalTo(e) {
- return e instanceof m ? this._worksheet.getSheetId() === e.getSheetId() && this._workbook.getUnitId() === e.getWorkbook().getUnitId() : false;
- }
- /*
- * Insert a defined name for worksheet.
- * @param {string} name - The name of the defined name to insert
- * @param {string} formulaOrRefString - The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
- * @example
- * ```ts
- * // The code below inserts a defined name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
- * sheet1.insertDefinedName('MyDefinedName', 'Sheet1!A1');
- * ```
- */
- insertDefinedName(e, t) {
- const s = this._injector.createInstance(V).setName(e).setRef(t).build();
- s.localSheetId = this.getSheetId(), this._fWorkbook.insertDefinedNameBuilder(s);
- }
- /**
- * Get all the defined names in the worksheet.
- * @returns {FDefinedName[]} All the defined names in the worksheet
- * @example
- * ```ts
- * // The code below gets all the defined names in the worksheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
- * const definedNames = sheet1.getDefinedNames();
- * ```
- */
- getDefinedNames() {
- return this._fWorkbook.getDefinedNames().filter((t) => t.getLocalSheetId() === this.getSheetId());
- }
- /**
- * Set custom metadata of worksheet
- * @param {CustomData | undefined} custom - custom metadata
- * @returns {FWorksheet}
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setCustomMetadata({ key: 'value' });
- * ```
- */
- setCustomMetadata(e) {
- return this._worksheet.setCustomMetadata(e), this;
- }
- /**
- * Set custom metadata of row
- * @param {number} index - row index
- * @param {CustomData | undefined} custom - custom metadata
- * @returns {FWorksheet} Current worksheet, for chaining.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setRowCustomMetadata(0, { key: 'value' });
- * ```
- */
- setRowCustomMetadata(e, t) {
- return this._worksheet.getRowManager().setCustomMetadata(e, t), this;
- }
- /**
- * Set custom metadata of column
- * @param {number} index - column index
- * @param {CustomData | undefined} custom - custom metadata
- * @returns {FWorksheet} Current worksheet, for chaining.
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * fWorkSheet.setColumnCustomMetadata(0, { key: 'value' });
- * ```
- */
- setColumnCustomMetadata(e, t) {
- return this._worksheet.getColumnManager().setCustomMetadata(e, t), this;
- }
- /**
- * Get custom metadata of row
- * @param {number} index - row index
- * @returns {CustomData | undefined} custom metadata
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const custom = fWorkSheet.getRowCustomMetadata(0);
- * ```
- */
- getRowCustomMetadata(e) {
- return this._worksheet.getRowManager().getCustomMetadata(e);
- }
- /**
- * Get custom metadata of column
- * @param {number} index - column index
- * @returns {CustomData | undefined} custom metadata
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const fWorkSheet = fWorkbook.getActiveSheet();
- * const custom = fWorkSheet.getColumnCustomMetadata(0);
- * ```
- */
- getColumnCustomMetadata(e) {
- return this._worksheet.getColumnManager().getCustomMetadata(e);
- }
- /**
- * Get all merged cells in the current worksheet
- * @returns {FRange[]} All the merged cells in the worksheet
- * @example
- * ```ts
- * const workbook = univerAPI.getActiveWorkbook();
- * const worksheet = workbook.getActiveSheet();
- * const rangeFirst = worksheet.getRange(0, 0, 2, 2);
- * const mergeFirst = rangeFirst.merge();
- * const rangeSecond = worksheet.getRange(5, 0, 2, 2);
- * const mergeSecond = rangeSecond.merge();
- * const mergeData = worksheet.getMergeData();
- * console.log('debugger', mergeData);
- * ```
- */
- getMergeData() {
- return this._worksheet.getMergeData().map((e) => this._injector.createInstance(S, this._workbook, this._worksheet, e));
- }
- };
- m = gn([
- B(3, ot(Ot)),
- B(4, ot(F)),
- B(5, ot(Mt)),
- B(6, Pt)
- ], m);
- var ln = Object.defineProperty;
- var mn = Object.getOwnPropertyDescriptor;
- var _n2 = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? mn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && ln(e, t, s), s;
- };
- var C = (r, e) => (t, n) => e(t, n, r);
- var f = class extends al {
- constructor(e, t, n, s, i, o, h, a, d, c) {
- super(t);
- b(this, "id");
- this._workbook = e, this._injector = t, this._resourceLoaderService = n, this._selectionManagerService = s, this._univerInstanceService = i, this._commandService = o, this._permissionService = h, this._logService = a, this._localeService = d, this._definedNamesService = c, this.id = this._workbook.getUnitId();
- }
- /**
- * Get the Workbook instance.
- * @returns {Workbook} The Workbook instance.
- * @example
- * ```ts
- * // The code below gets the Workbook instance
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const workbook = activeSpreadsheet.getWorkbook();
- * ```
- */
- getWorkbook() {
- return this._workbook;
- }
- /**
- * Get the id of the workbook.
- * @returns {string} The id of the workbook.
- * @example
- * ```ts
- * // The code below gets the id of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const id = activeSpreadsheet.getId();
- * ```
- */
- getId() {
- return this.id;
- }
- /**
- * Get the name of the workbook.
- * @returns {string} The name of the workbook.
- * @example
- * ```ts
- * // The code below gets the name of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const name = activeSpreadsheet.getName();
- * ```
- */
- getName() {
- return this._workbook.name;
- }
- /**
- * Set the name of the workbook.
- * @param {string} name The new name of the workbook.
- * @returns {void}
- * @example
- * ```ts
- * // The code below sets the name of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.setName('MyWorkbook');
- * ```
- */
- setName(e) {
- this._workbook.setName(e);
- }
- /**
- * Save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
- * @returns {IWorkbookData} Workbook snapshot data
- * @example
- * ```ts
- * // The code below saves the workbook snapshot data
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const snapshot = activeSpreadsheet.save();
- * ```
- */
- save() {
- return this._resourceLoaderService.saveUnit(this._workbook.getUnitId());
- }
- /**
- * @deprecated use 'save' instead.
- * @returns {IWorkbookData} Workbook snapshot data
- * @memberof FWorkbook
- * @example
- * ```ts
- * // The code below saves the workbook snapshot data
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const snapshot = activeSpreadsheet.getSnapshot();
- * ```
- */
- getSnapshot() {
- return this._logService.warn("use 'save' instead of 'getSnapshot'"), this.save();
- }
- /**
- * Get the active sheet of the workbook.
- * @returns {FWorksheet} The active sheet of the workbook
- * @example
- * ```ts
- * // The code below gets the active sheet of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * ```
- */
- getActiveSheet() {
- const e = this._workbook.getActiveSheet();
- return this._injector.createInstance(m, this, this._workbook, e);
- }
- /**
- * Gets all the worksheets in this workbook
- * @returns {FWorksheet[]} An array of all the worksheets in the workbook
- * @example
- * ```ts
- * // The code below gets all the worksheets in the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheets = activeSpreadsheet.getSheets();
- * ```
- */
- getSheets() {
- return this._workbook.getSheets().map((e) => this._injector.createInstance(m, this, this._workbook, e));
- }
- /**
- * Create a new worksheet and returns a handle to it.
- * @param {string} name Name of the new sheet
- * @param {number} rows How many rows would the new sheet have
- * @param {number} column How many columns would the new sheet have
- * @returns {FWorksheet} The new created sheet
- * @example
- * ```ts
- * // The code below creates a new sheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const newSheet = activeSpreadsheet.create('MyNewSheet', 10, 10);
- * ```
- */
- create(e, t, n) {
- const s = Q_({});
- s.rowCount = t, s.columnCount = n, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(fu.id, {
- unitId: this.id,
- index: this._workbook.getSheets().length,
- sheet: s
- }), this._commandService.syncExecuteCommand(an.id, {
- unitId: this.id,
- subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
- });
- const i = this._workbook.getActiveSheet();
- if (!i)
- throw new Error("No active sheet found");
- return this._injector.createInstance(m, this, this._workbook, i);
- }
- /**
- * Get a worksheet by sheet id.
- * @param {string} sheetId The id of the sheet to get.
- * @returns {FWorksheet | null} The worksheet with given sheet id
- * @example
- * ```ts
- * // The code below gets a worksheet by sheet id
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet = activeSpreadsheet.getSheetBySheetId('sheetId');
- * ```
- */
- getSheetBySheetId(e) {
- const t = this._workbook.getSheetBySheetId(e);
- return t ? this._injector.createInstance(m, this, this._workbook, t) : null;
- }
- /**
- * Get a worksheet by sheet name.
- * @param {string} name The name of the sheet to get.
- * @returns {FWorksheet | null} The worksheet with given sheet name
- * @example
- * ```ts
- * // The code below gets a worksheet by sheet name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
- * ```
- */
- getSheetByName(e) {
- const t = this._workbook.getSheetBySheetName(e);
- return t ? this._injector.createInstance(m, this, this._workbook, t) : null;
- }
- /**
- * Sets the given worksheet to be the active worksheet in the workbook.
- * @param {FWorksheet | string} sheet The worksheet to set as the active worksheet.
- * @returns {FWorksheet} The active worksheet
- * @example
- * ```ts
- * // The code below sets the given worksheet to be the active worksheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
- * activeSpreadsheet.setActiveSheet(sheet);
- * ```
- */
- setActiveSheet(e) {
- return this._commandService.syncExecuteCommand(an.id, {
- unitId: this.id,
- subUnitId: typeof e == "string" ? e : e.getSheetId()
- }), typeof e == "string" ? this.getSheetBySheetId(e) : e;
- }
- /**
- * Inserts a new worksheet into the workbook.
- * Using a default sheet name. The new sheet becomes the active sheet
- * @param {string} [sheetName] The name of the new sheet
- * @returns {FWorksheet} The new sheet
- * @example
- * ```ts
- * // The code below inserts a new sheet into the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.insertSheet();
- *
- * // The code below inserts a new sheet into the workbook, using a custom name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.insertSheet('MyNewSheet');
- * ```
- */
- insertSheet(e) {
- e != null ? this._commandService.syncExecuteCommand(fu.id, { sheet: { name: e } }) : this._commandService.syncExecuteCommand(fu.id);
- const t = this.id, n = this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId();
- this._commandService.syncExecuteCommand(an.id, {
- unitId: t,
- subUnitId: n
- });
- const s = this._workbook.getActiveSheet();
- if (!s)
- throw new Error("No active sheet found");
- return this._injector.createInstance(m, this, this._workbook, s);
- }
- /**
- * Deletes the specified worksheet.
- * @param {FWorksheet | string} sheet The worksheet to delete.
- * @returns {boolean} True if the worksheet was deleted, false otherwise.
- * @example
- * ```ts
- * // The code below deletes the specified worksheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
- * activeSpreadsheet.deleteSheet(sheet);
- * ```
- */
- deleteSheet(e) {
- const t = this.id, n = typeof e == "string" ? e : e.getSheetId();
- return this._commandService.syncExecuteCommand(ko.id, {
- unitId: t,
- subUnitId: n
- });
- }
- // #region editing
- /**
- * Undo the last action.
- * @returns {FWorkbook} A promise that resolves to true if the undo was successful, false otherwise.
- * @example
- * ```ts
- * // The code below undoes the last action
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.undo();
- * ```
- */
- undo() {
- return this._univerInstanceService.focusUnit(this.id), this._commandService.syncExecuteCommand(Nn.id), this;
- }
- /**
- * Redo the last undone action.
- * @returns {FWorkbook} A promise that resolves to true if the redo was successful, false otherwise.
- * @example
- * ```ts
- * // The code below redoes the last undone action
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.redo();
- * ```
- */
- redo() {
- return this._univerInstanceService.focusUnit(this.id), this._commandService.syncExecuteCommand(Tn.id), this;
- }
- /**
- * Callback for command execution.
- * @callback onBeforeCommandExecuteCallback
- * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed.
- */
- /**
- * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
- * @param {onBeforeCommandExecuteCallback} callback the callback.
- * @returns {IDisposable} A function to dispose the listening.
- * @example
- * ```ts
- * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.onBeforeCommandExecute((command) => {
- * console.log('Command executed:', command);
- * });
- * ```
- */
- onBeforeCommandExecute(e) {
- return this._commandService.beforeCommandExecuted((t) => {
- var n;
- ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
- });
- }
- /**
- * Callback for command execution.
- * @callback onCommandExecutedCallback
- * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed
- */
- /**
- * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
- * @param {onCommandExecutedCallback} callback the callback.
- * @returns {IDisposable} A function to dispose the listening.
- * @example
- * ```ts
- * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.onCommandExecuted((command) => {
- * console.log('Command executed:', command);
- * });
- * ```
- */
- onCommandExecuted(e) {
- return this._commandService.onCommandExecuted((t) => {
- var n;
- ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
- });
- }
- /**
- * Callback for selection changes.
- * @callback onSelectionChangeCallback
- * @param {IRange[]} selections The new selection.
- */
- /**
- * Register a callback that will be triggered when the selection changes.
- * @param {onSelectionChangeCallback} callback The callback.
- * @returns {IDisposable} A function to dispose the listening
- */
- onSelectionChange(e) {
- return Ze(
- this._selectionManagerService.selectionMoveEnd$.subscribe((t) => {
- this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET).getUnitId() === this.id && (t != null && t.length ? e(t.map((n) => n.range)) : e([]));
- })
- );
- }
- /**
- * Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.
- * @param {boolean} value editable value want to set
- * @returns {FWorkbook} FWorkbook instance
- */
- setEditable(e) {
- const t = new Me(this._workbook.getUnitId());
- return this._permissionService.getPermissionPoint(t.id) || this._permissionService.addPermissionPoint(t), this._permissionService.updatePermissionPoint(t.id, e), this;
- }
- /**
- * Sets the selection region for active sheet.
- * @param {FRange} range The range to set as the active selection.
- * @returns {FWorkbook} FWorkbook instance
- */
- setActiveRange(e) {
- const t = this.getActiveSheet(), n = e.getRange().sheetId || t.getSheetId(), s = n ? this._workbook.getSheetBySheetId(n) : this._workbook.getActiveSheet(true);
- if (!s)
- throw new Error("No active sheet found");
- s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(m, this, this._workbook, s));
- const i = {
- unitId: this.getId(),
- subUnitId: n,
- selections: [e].map((o) => ({ range: o.getRange(), primary: ve(o.getRange(), s), style: null }))
- };
- return this._commandService.syncExecuteCommand(re2.id, i), this;
- }
- /**
- * Returns the selected range in the active sheet, or null if there is no active range.
- * @returns {FRange | null} The active range
- */
- // could sheet have no active range ?
- getActiveRange() {
- const e = this._workbook.getActiveSheet(), n = this._selectionManagerService.getCurrentSelections().find((s) => !!s.primary);
- return n ? this._injector.createInstance(S, this._workbook, e, n.range) : null;
- }
- /**
- * Deletes the currently active sheet.
- * @returns {boolean} true if the sheet was deleted, false otherwise
- * @example
- * ```ts
- * // The code below deletes the currently active sheet and stores the new active
- * // sheet in a variable
- * const sheet = univerAPI.getActiveWorkbook().deleteActiveSheet();
- * ```
- */
- deleteActiveSheet() {
- const e = this.getActiveSheet();
- return this.deleteSheet(e);
- }
- /**
- * Duplicates the given worksheet.
- * @param {FWorksheet} sheet The worksheet to duplicate.
- * @returns {FWorksheet} The duplicated worksheet
- * @example
- * ```ts
- * // The code below duplicates the given worksheet
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const activeSheet = activeSpreadsheet.getActiveSheet();
- * activeSpreadsheet.duplicateSheet(activeSheet);
- * ```
- */
- duplicateSheet(e) {
- return this._commandService.syncExecuteCommand(xs.id, {
- unitId: e.getWorkbook().getUnitId(),
- subUnitId: e.getSheetId()
- }), this._injector.createInstance(m, this, this._workbook, this._workbook.getActiveSheet());
- }
- /**
- * Duplicates the active sheet.
- * @returns {FWorksheet} The duplicated worksheet
- * @example
- * ```ts
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.duplicateActiveSheet();
- * ```
- */
- duplicateActiveSheet() {
- const e = this.getActiveSheet();
- return this.duplicateSheet(e);
- }
- /**
- * Get the number of sheets in the workbook.
- * @returns {number} The number of sheets in the workbook
- * @example
- * ```ts
- * // The code below gets the number of sheets in the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const numSheets = activeSpreadsheet.getNumSheets();
- * ```
- */
- getNumSheets() {
- return this._workbook.getSheets().length;
- }
- /**
- * Get the locale of the workbook.
- * @returns {LocaleType} The locale of the workbook
- * @example
- * ```ts
- * // The code below gets the locale of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const locale = activeSpreadsheet.getLocale();
- * ```
- */
- getLocale() {
- return this._localeService.getCurrentLocale();
- }
- /**
- * @deprecated use setSpreadsheetLocale instead.
- * @param {LocaleType} locale - The locale to set
- */
- setLocale(e) {
- this._localeService.setLocale(e);
- }
- /**
- * Set the locale of the workbook.
- * @param {LocaleType} locale The locale to set
- * @returns {FWorkbook} This workbook, for chaining
- * @example
- * ```ts
- * // The code below sets the locale of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.setLocale(LocaleType.EN_US);
- * ```
- */
- setSpreadsheetLocale(e) {
- return this._localeService.setLocale(e), this;
- }
- /**
- * Get the URL of the workbook.
- * @returns {string} The URL of the workbook
- * @example
- * ```ts
- * // The code below gets the URL of the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const url = activeSpreadsheet.getUrl();
- * ```
- */
- getUrl() {
- return location.href;
- }
- /**
- * Move the sheet to the specified index.
- * @param {FWorksheet} sheet The sheet to move
- * @param {number} index The index to move the sheet to
- * @returns {FWorkbook} This workbook, for chaining
- * @example
- * ```ts
- * // The code below moves the sheet to the specified index
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const sheet = activeSpreadsheet.getActiveSheet();
- * activeSpreadsheet.moveSheet(sheet, 1);
- * ```
- */
- moveSheet(e, t) {
- let n = t;
- return n < 0 ? n = 0 : n > this._workbook.getSheets().length - 1 && (n = this._workbook.getSheets().length - 1), this._commandService.syncExecuteCommand(Wr.id, {
- unitId: e.getWorkbook().getUnitId(),
- order: n,
- subUnitId: e.getSheetId()
- }), this;
- }
- /**
- * Move the active sheet to the specified index.
- * @param {number} index The index to move the active sheet to
- * @returns {FWorkbook} This workbook, for chaining
- * @example
- * ```ts
- * // The code below moves the active sheet to the specified index
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.moveActiveSheet(1);
- * ```
- */
- moveActiveSheet(e) {
- const t = this.getActiveSheet();
- return this.moveSheet(t, e);
- }
- /**
- * Get the PermissionInstance.
- * @returns {FPermission} - The PermissionInstance.
- */
- getPermission() {
- return this._injector.createInstance(j);
- }
- /**
- * Get the defined name by name.
- * @param {string} name The name of the defined name to get
- * @returns {FDefinedName | null} The defined name with the given name
- * @example
- * ```ts
- * // The code below gets the defined name by name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const definedName = activeSpreadsheet.getDefinedName('MyDefinedName');
- * ```
- */
- getDefinedName(e) {
- const t = this._definedNamesService.getValueByName(this.id, e);
- return t ? this._injector.createInstance(F2, { ...t, unitId: this.id }) : null;
- }
- /**
- * Get all the defined names in the workbook.
- * @returns {FDefinedName[]} All the defined names in the workbook
- * @example
- * ```ts
- * // The code below gets all the defined names in the workbook
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const definedNames = activeSpreadsheet.getDefinedNames();
- * ```
- */
- getDefinedNames() {
- const e = this._definedNamesService.getDefinedNameMap(this.id);
- return e ? Object.values(e).map((t) => this._injector.createInstance(F2, { ...t, unitId: this.id })) : [];
- }
- /**
- * Insert a defined name.
- * @param {string} name The name of the defined name to insert
- * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
- * @returns {FWorkbook} The current FWorkbook instance
- * @example
- * ```ts
- * // The code below inserts a defined name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
- * ```
- */
- insertDefinedName(e, t) {
- const s = this._injector.createInstance(V).setName(e).setRef(t).build();
- return s.localSheetId = ch, this.insertDefinedNameBuilder(s), this;
- }
- /**
- * Delete the defined name with the given name.
- * @param {string} name The name of the defined name to delete
- * @returns {boolean} true if the defined name was deleted, false otherwise
- * @example
- * ```ts
- * // The code below deletes the defined name with the given name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const deleted = activeSpreadsheet.deleteDefinedName('MyDefinedName');
- * ```
- */
- deleteDefinedName(e) {
- const t = this.getDefinedName(e);
- return t ? (t.delete(), true) : false;
- }
- /**
- * Insert a defined name by builder param.
- * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
- * @returns {void}
- * @example
- * ```ts
- * // The code below inserts a defined name by builder param
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const builder = univerAPI.newDefinedName();
- * const param = builder.setName('MyDefinedName').setRef('Sheet1!A1').build();
- * activeSpreadsheet.insertDefinedNameBuilder(param);
- * ```
- */
- insertDefinedNameBuilder(e) {
- e.unitId = this.getId(), this._commandService.syncExecuteCommand(Ur.id, e);
- }
- /**
- * Update the defined name with the given name.
- * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
- * @returns {void}
- * @example
- * ```ts
- * // The code below updates the defined name with the given name
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();
- * builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();
- * activeSpreadsheet.updateDefinedNameBuilder(param);
- * ```
- */
- updateDefinedNameBuilder(e) {
- this._commandService.syncExecuteCommand(Ur.id, e);
- }
- /**
- * Gets the registered range themes.
- * @returns {string[]} The name list of registered range themes.
- * @example
- * ```ts
- * // The code below gets the registered range themes
- * const activeSpreadsheet = univerAPI.getActiveWorkbook();
- * const themes = activeSpreadsheet.getRegisteredRangeThemes();
- * console.log(themes);
- * ```
- */
- getRegisteredRangeThemes() {
- return this._injector.get(ho).getRegisteredRangeThemes();
- }
- /**
- * Register a custom range theme style.
- * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register
- * @returns {void}
- * @example
- * ```ts
- * // import {RangeThemeStyle} from '@univerjs/sheets';
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const rangeThemeStyle = new RangeThemeStyle('MyTheme');
- * rangeThemeStyle.setSecondRowStyle({
- * bg: {
- * rgb: 'rgb(214,231,241)',
- * },
- * });
- * fWorkbook.registerRangeTheme(rangeThemeStyle);
- * ```
- */
- registerRangeTheme(e) {
- this._commandService.syncExecuteCommand(wu2.id, {
- unitId: this.getId(),
- rangeThemeStyle: e
- });
- }
- /**
- * Unregister a custom range theme style.
- * @param {string} themeName The name of the theme to unregister
- * @returns {void}
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * fWorkbook.unregisterRangeTheme('MyTheme');
- * ```
- */
- unregisterRangeTheme(e) {
- this._commandService.syncExecuteCommand(Ol.id, {
- unitId: this.getId(),
- themeName: e
- });
- }
- /**
- * Set custom metadata of workbook
- * @param {CustomData | undefined} custom custom metadata
- * @returns {FWorkbook} FWorkbook
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * fWorkbook.setCustomMetadata({ key: 'value' });
- * ```
- */
- setCustomMetadata(e) {
- return this._workbook.setCustomMetadata(e), this;
- }
- /**
- * Get custom metadata of workbook
- * @returns {CustomData | undefined} custom metadata
- * @example
- * ```ts
- * const fWorkbook = univerAPI.getActiveWorkbook();
- * const custom = fWorkbook.getCustomMetadata();
- * ```
- */
- getCustomMetadata() {
- return this._workbook.getCustomMetadata();
- }
- };
- f = _n2([
- C(1, ot(Ot)),
- C(2, ot(va)),
- C(3, ot(F)),
- C(4, _n),
- C(5, Pt),
- C(6, UE),
- C(7, Mt),
- C(8, ot(Vr)),
- C(9, pr)
- ], f);
- var kn = class extends pi {
- getCommandSheetTarget(e) {
- var i;
- const t = e.params;
- if (!t)
- return;
- const n = t.unitId ? this.getUniverSheet(t.unitId) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
- if (!n)
- return;
- const s = n.getSheetBySheetId(t.subUnitId || t.sheetId) || n.getActiveSheet();
- if (s)
- return { workbook: n, worksheet: s };
- }
- getSheetTarget(e, t) {
- const n = this.getUniverSheet(e);
- if (!n)
- return;
- const s = n.getSheetBySheetId(t);
- if (s)
- return { workbook: n, worksheet: s };
- }
- _initWorkbookEvent(e) {
- const t = e.get(_n);
- this.disposeWithMe(
- t.unitDisposed$.subscribe((n) => {
- this._eventRegistry.get(this.Event.WorkbookDisposed) && n.type === Fe.UNIVER_SHEET && this.fireEvent(
- this.Event.WorkbookDisposed,
- {
- unitId: n.getUnitId(),
- unitType: n.type,
- snapshot: n.getSnapshot()
- }
- );
- })
- ), this.disposeWithMe(
- t.unitAdded$.subscribe((n) => {
- if (this._eventRegistry.get(this.Event.WorkbookCreated) && n.type === Fe.UNIVER_SHEET) {
- const s = n, i = e.createInstance(f, s);
- this.fireEvent(
- this.Event.WorkbookCreated,
- {
- unitId: n.getUnitId(),
- type: n.type,
- workbook: i,
- unit: i
- }
- );
- }
- })
- );
- }
- // eslint-disable-next-line max-lines-per-function
- _initialize(e) {
- const t = e.get(Pt);
- this.disposeWithMe(
- // eslint-disable-next-line max-lines-per-function, complexity
- t.beforeCommandExecuted((n) => {
- var s, i, o, h;
- switch (n.id) {
- case fu.id: {
- const a = n.params, { unitId: d, index: c, sheet: v } = a || {}, k = d ? this.getUniverSheet(d) : (s = this.getActiveWorkbook) == null ? void 0 : s.call(this);
- if (!k)
- return;
- const ge = {
- workbook: k,
- index: c,
- sheet: v
- };
- if (this.fireEvent(
- this.Event.BeforeSheetCreate,
- ge
- ), ge.cancel)
- throw new xf();
- break;
- }
- case Ar.id: {
- if (!this._eventListend(this.Event.BeforeActiveSheetChange))
- return;
- const { subUnitId: a, unitId: d } = n.params, c = d ? this.getUniverSheet(d) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
- if (!c || !a)
- return;
- const v = c.getSheetBySheetId(a), k = c.getActiveSheet();
- if (!v || !k)
- return;
- this._fireBeforeActiveSheetChange(c, v, k);
- break;
- }
- case ko.id: {
- if (!this._eventListend(this.Event.BeforeSheetDelete))
- return;
- const a = this.getCommandSheetTarget(n);
- if (!a)
- return;
- const { workbook: d, worksheet: c } = a;
- this._fireBeforeSheetDelete(d, c);
- break;
- }
- case Wr.id: {
- if (!this._eventListend(this.Event.BeforeSheetMove))
- return;
- const { fromOrder: a, toOrder: d } = n.params, c = this.getCommandSheetTarget(n);
- if (!c)
- return;
- this._fireBeforeSheetMove(c.workbook, c.worksheet, d, a);
- break;
- }
- case Do.id: {
- if (!this._eventListend(this.Event.BeforeSheetNameChange))
- return;
- const { name: a } = n.params, d = this.getCommandSheetTarget(n);
- if (!d)
- return;
- this._fireBeforeSheetNameChange(d.workbook, d.worksheet, a, d.worksheet.getSheetName());
- break;
- }
- case al2.id: {
- if (!this._eventListend(this.Event.BeforeSheetTabColorChange))
- return;
- const { color: a } = n.params, d = this.getCommandSheetTarget(n);
- if (!d)
- return;
- this._fireBeforeSheetTabColorChange(d.workbook, d.worksheet, a, d.worksheet.getTabColor());
- break;
- }
- case hl.id: {
- if (!this._eventListend(this.Event.BeforeSheetHideChange))
- return;
- const { hidden: a } = n.params, d = this.getCommandSheetTarget(n);
- if (!d)
- return;
- this._fireBeforeSheetHideChange(d.workbook, d.worksheet, !!a);
- break;
- }
- case ju.id: {
- if (!this._eventListend(this.Event.BeforeGridlineColorChange))
- return;
- const a = this.getCommandSheetTarget(n);
- if (!a)
- return;
- this.fireEvent(this.Event.BeforeGridlineColorChange, {
- ...a,
- color: (o = n.params) == null ? void 0 : o.color
- });
- break;
- }
- case Nl.id: {
- if (!this._eventListend(this.Event.BeforeGridlineEnableChange))
- return;
- const a = this.getCommandSheetTarget(n);
- if (!a)
- return;
- this.fireEvent(this.Event.BeforeGridlineEnableChange, {
- ...a,
- enabled: !!((h = n.params) != null && h.showGridlines)
- });
- break;
- }
- }
- })
- ), this.disposeWithMe(
- // eslint-disable-next-line max-lines-per-function, complexity
- t.onCommandExecuted((n) => {
- var s, i;
- if (fh.indexOf(n.id) > -1) {
- if (!this._eventListend(this.Event.SheetValueChanged) || !this.getActiveSheet())
- return;
- const h = Rh(n).map(
- (a) => {
- var d, c;
- return (c = (d = this.getWorkbook(a.unitId)) == null ? void 0 : d.getSheetBySheetId(a.subUnitId)) == null ? void 0 : c.getRange(a.range);
- }
- ).filter(Boolean);
- if (!h.length)
- return;
- this.fireEvent(this.Event.SheetValueChanged, {
- payload: n,
- effectedRanges: h
- });
- return;
- }
- switch (n.id) {
- case fu.id: {
- const o = n.params, { unitId: h } = o || {}, a = h ? this.getUniverSheet(h) : (s = this.getActiveWorkbook) == null ? void 0 : s.call(this);
- if (!a)
- return;
- const d = a.getActiveSheet();
- if (!d)
- return;
- const c = {
- workbook: a,
- worksheet: d
- };
- this.fireEvent(
- this.Event.SheetCreated,
- c
- );
- break;
- }
- case Ar.id: {
- if (!this._eventListend(this.Event.ActiveSheetChanged))
- return;
- const o = this.getActiveSheet();
- if (!o)
- return;
- const { workbook: h, worksheet: a } = o;
- this._fireActiveSheetChanged(h, a);
- break;
- }
- case ko.id: {
- if (!this._eventListend(this.Event.SheetDeleted))
- return;
- const { subUnitId: o, unitId: h } = n.params, a = h ? this.getUniverSheet(h) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
- if (!a || !o)
- return;
- this._fireSheetDeleted(a, o);
- break;
- }
- case Wr.id: {
- if (!this._eventListend(this.Event.SheetMoved))
- return;
- const { toOrder: o } = n.params, h = this.getCommandSheetTarget(n);
- if (!h)
- return;
- this._fireSheetMoved(h.workbook, h.worksheet, o);
- break;
- }
- case Do.id: {
- if (!this._eventListend(this.Event.SheetNameChanged))
- return;
- const { name: o } = n.params, h = this.getCommandSheetTarget(n);
- if (!h)
- return;
- this._fireSheetNameChanged(h.workbook, h.worksheet, o);
- break;
- }
- case al2.id: {
- if (!this._eventListend(this.Event.SheetTabColorChanged))
- return;
- const { color: o } = n.params, h = this.getCommandSheetTarget(n);
- if (!h)
- return;
- this._fireSheetTabColorChanged(h.workbook, h.worksheet, o);
- break;
- }
- case hl.id: {
- if (!this._eventListend(this.Event.SheetHideChanged))
- return;
- const { hidden: o } = n.params, h = this.getCommandSheetTarget(n);
- if (!h)
- return;
- this._fireSheetHideChanged(h.workbook, h.worksheet, !!o);
- break;
- }
- case ju.id:
- case Nl.id: {
- if (!this._eventListend(this.Event.GridlineChanged))
- return;
- const o = this.getCommandSheetTarget(n);
- if (!o)
- return;
- this.fireEvent(this.Event.GridlineChanged, {
- ...o,
- enabled: !o.worksheet.hasHiddenGridLines(),
- color: o.worksheet.getGridLinesColor()
- });
- break;
- }
- }
- })
- ), this._initWorkbookEvent(e);
- }
- createUniverSheet(e) {
- const n = this._injector.get(_n).createUnit(Fe.UNIVER_SHEET, e);
- return this._injector.createInstance(f, n);
- }
- createWorkbook(e) {
- return this.createUniverSheet(e);
- }
- getActiveWorkbook() {
- const e = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
- return e ? this._injector.createInstance(f, e) : null;
- }
- getActiveUniverSheet() {
- return this.getActiveWorkbook();
- }
- getUniverSheet(e) {
- const t = this._univerInstanceService.getUnit(e, Fe.UNIVER_SHEET);
- return t ? this._injector.createInstance(f, t) : null;
- }
- getWorkbook(e) {
- return this.getUniverSheet(e);
- }
- getPermission() {
- return this._injector.createInstance(j);
- }
- onUniverSheetCreated(e) {
- const t = this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((n) => {
- const s = this._injector.createInstance(f, n);
- e(s);
- });
- return Ze(t);
- }
- newDefinedName() {
- return this._injector.createInstance(V);
- }
- getActiveSheet() {
- const e = this.getActiveWorkbook();
- if (!e)
- return null;
- const t = e.getActiveSheet();
- return t ? { workbook: e, worksheet: t } : null;
- }
- _fireBeforeActiveSheetChange(e, t, n) {
- this.fireEvent(this.Event.BeforeActiveSheetChange, {
- workbook: e,
- activeSheet: t,
- oldActiveSheet: n
- });
- }
- _fireActiveSheetChanged(e, t) {
- this.fireEvent(this.Event.ActiveSheetChanged, {
- workbook: e,
- activeSheet: t
- });
- }
- _fireBeforeSheetDelete(e, t) {
- this.fireEvent(this.Event.BeforeSheetDelete, {
- workbook: e,
- worksheet: t
- });
- }
- _fireSheetDeleted(e, t) {
- this.fireEvent(this.Event.SheetDeleted, {
- workbook: e,
- sheetId: t
- });
- }
- _fireBeforeSheetMove(e, t, n, s) {
- this.fireEvent(this.Event.BeforeSheetMove, {
- workbook: e,
- worksheet: t,
- newIndex: n,
- oldIndex: s
- });
- }
- _fireSheetMoved(e, t, n) {
- this.fireEvent(this.Event.SheetMoved, {
- workbook: e,
- worksheet: t,
- newIndex: n
- });
- }
- _fireBeforeSheetNameChange(e, t, n, s) {
- this.fireEvent(this.Event.BeforeSheetNameChange, {
- workbook: e,
- worksheet: t,
- newName: n,
- oldName: s
- });
- }
- _fireSheetNameChanged(e, t, n) {
- this.fireEvent(this.Event.SheetNameChanged, {
- workbook: e,
- worksheet: t,
- newName: n
- });
- }
- _fireBeforeSheetTabColorChange(e, t, n, s) {
- this.fireEvent(this.Event.BeforeSheetTabColorChange, {
- workbook: e,
- worksheet: t,
- newColor: n,
- oldColor: s
- });
- }
- _fireSheetTabColorChanged(e, t, n) {
- this.fireEvent(this.Event.SheetTabColorChanged, {
- workbook: e,
- worksheet: t,
- newColor: n
- });
- }
- _fireBeforeSheetHideChange(e, t, n) {
- this.fireEvent(this.Event.BeforeSheetHideChange, {
- workbook: e,
- worksheet: t,
- hidden: n
- });
- }
- _fireSheetHideChanged(e, t, n) {
- this.fireEvent(this.Event.SheetHideChanged, {
- workbook: e,
- worksheet: t,
- hidden: n
- });
- }
- };
- pi.extend(kn);
- var Sn = class {
- get SheetValueChangeType() {
- return vd;
- }
- get SheetSkeletonChangeType() {
- return Id;
- }
- };
- ci.extend(Sn);
- var wn = class extends hi {
- get SheetCreated() {
- return "SheetCreated";
- }
- get BeforeSheetCreate() {
- return "BeforeSheetCreate";
- }
- get WorkbookCreated() {
- return "WorkbookCreated";
- }
- get WorkbookDisposed() {
- return "WorkbookDisposed";
- }
- get GridlineChanged() {
- return "GridlineChanged";
- }
- get BeforeGridlineEnableChange() {
- return "BeforeGridlineEnableChange";
- }
- get BeforeGridlineColorChange() {
- return "BeforeGridlineColorChange";
- }
- get BeforeActiveSheetChange() {
- return "BeforeActiveSheetChange";
- }
- get ActiveSheetChanged() {
- return "ActiveSheetChanged";
- }
- get SheetDeleted() {
- return "SheetDeleted";
- }
- get BeforeSheetDelete() {
- return "BeforeSheetDelete";
- }
- get SheetMoved() {
- return "SheetMoved";
- }
- get BeforeSheetMove() {
- return "BeforeSheetMove";
- }
- get SheetNameChanged() {
- return "SheetNameChanged";
- }
- get BeforeSheetNameChange() {
- return "BeforeSheetNameChange";
- }
- get SheetTabColorChanged() {
- return "SheetTabColorChanged";
- }
- get BeforeSheetTabColorChange() {
- return "BeforeSheetTabColorChange";
- }
- get SheetHideChanged() {
- return "SheetHideChanged";
- }
- get BeforeSheetHideChange() {
- return "BeforeSheetHideChange";
- }
- get SheetValueChanged() {
- return "SheetValueChanged";
- }
- };
- hi.extend(wn);
- var Cn = Object.defineProperty;
- var fn2 = Object.getOwnPropertyDescriptor;
- var vn = (r, e, t, n) => {
- for (var s = n > 1 ? void 0 : n ? fn2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
- (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
- return n && s && Cn(e, t, s), s;
- };
- var In = (r, e) => (t, n) => e(t, n, r);
- var xe = class extends Fi {
- constructor(r) {
- super(), this._injector = r;
- }
- };
- xe = vn([
- In(0, ot(Ot))
- ], xe);
- export {
- j,
- S,
- L,
- m,
- f,
- Sn,
- wn,
- xe
- };
- //# sourceMappingURL=chunk-CLOCSTN3.js.map
|