chunk-CLOCSTN3.js 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173
  1. import {
  2. $u,
  3. Ao,
  4. Ar,
  5. Bt,
  6. Bu,
  7. Co,
  8. D,
  9. Do,
  10. F,
  11. Fn,
  12. Fr,
  13. Fu,
  14. Hn,
  15. Id,
  16. Ir,
  17. Iu,
  18. Jn,
  19. Kn,
  20. Ku,
  21. Lo,
  22. Me,
  23. Mn,
  24. Mr,
  25. Ne,
  26. Nl,
  27. Oe,
  28. Ol,
  29. Ou,
  30. Q,
  31. Rh,
  32. So,
  33. St,
  34. Te,
  35. Th,
  36. Tl,
  37. Ur,
  38. Vn,
  39. Wo,
  40. Wr,
  41. Ye,
  42. Zr,
  43. _h,
  44. al as al2,
  45. an,
  46. ba,
  47. bh,
  48. ch,
  49. ct,
  50. de,
  51. fe,
  52. fh,
  53. fr as fr2,
  54. fu,
  55. he,
  56. hl,
  57. ho,
  58. iu,
  59. jn,
  60. ju,
  61. ke,
  62. ko,
  63. kr,
  64. nl,
  65. ol,
  66. on,
  67. po,
  68. pr as pr2,
  69. re as re2,
  70. sl,
  71. un,
  72. vd,
  73. ve,
  74. vr,
  75. we as we2,
  76. wu as wu2,
  77. xs,
  78. yr,
  79. ze
  80. } from "./chunk-BW43Z7N3.js";
  81. import {
  82. Pr,
  83. fn,
  84. fr,
  85. pc,
  86. pr
  87. } from "./chunk-QRYBFJ3R.js";
  88. import {
  89. De,
  90. Fe,
  91. Fi,
  92. Mt,
  93. Nn,
  94. Ot,
  95. Pt,
  96. Q_,
  97. Tn,
  98. UE,
  99. Vr,
  100. Xt,
  101. Ze,
  102. Zt,
  103. _n,
  104. al,
  105. bE,
  106. ci,
  107. cr,
  108. en,
  109. fC,
  110. hi,
  111. hn,
  112. kt,
  113. mC,
  114. ot,
  115. pi,
  116. qt,
  117. re,
  118. vC,
  119. va,
  120. we,
  121. wu,
  122. xf,
  123. xn,
  124. yu
  125. } from "./chunk-23V3HWTR.js";
  126. // 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
  127. var Ge = Object.defineProperty;
  128. var qe = (r, e, t) => e in r ? Ge(r, e, { enumerable: true, configurable: true, writable: true, value: t }) : r[e] = t;
  129. var b = (r, e, t) => qe(r, typeof e != "symbol" ? e + "" : e, t);
  130. var $t = Object.defineProperty;
  131. var Gt = Object.getOwnPropertyDescriptor;
  132. var qt2 = (r, e, t, n) => {
  133. for (var s = n > 1 ? void 0 : n ? Gt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  134. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  135. return n && s && $t(e, t, s), s;
  136. };
  137. var w = (r, e) => (t, n) => e(t, n, r);
  138. function Kt(r, e, t) {
  139. const n = t.getDefinedNameMap(r);
  140. if (n == null)
  141. return e.t("definedName.defaultName") + 1;
  142. const i = Array.from(Object.values(n)).length + 1, o = e.t("definedName.defaultName") + i;
  143. if (t.getValueByName(r, o) == null)
  144. return o;
  145. let h = i + 1;
  146. for (; ; ) {
  147. const a = e.t("definedName.defaultName") + h;
  148. if (t.getValueByName(r, a) == null)
  149. return a;
  150. h++;
  151. }
  152. }
  153. var V = class {
  154. constructor() {
  155. b(this, "_definedNameParam");
  156. this._definedNameParam = {
  157. id: qt(10),
  158. unitId: "",
  159. name: "",
  160. formulaOrRefString: ""
  161. };
  162. }
  163. /**
  164. * Sets the name of the defined name builder.
  165. * @param {string} name The name of the defined name.
  166. * @returns {FDefinedNameBuilder} The defined name builder.
  167. * @example
  168. * ```ts
  169. * const workbook = univerAPI.getActiveWorkbook();
  170. * const definedNameBuilder = univerAPI.newDefinedName()
  171. * .setName('MyDefinedName')
  172. * .build();
  173. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  174. * ```
  175. */
  176. setName(e) {
  177. return this._definedNameParam.name = e, this;
  178. }
  179. /**
  180. * Sets the formula of the defined name builder.
  181. * @param {string }formula The formula of the defined name.
  182. * @returns {FDefinedNameBuilder} The defined name builder.
  183. * @example
  184. * ```ts
  185. * const workbook = univerAPI.getActiveWorkbook();
  186. * const definedNameBuilder = univerAPI.newDefinedName()
  187. * .setFormula('SUM(Sheet1!$A$1)')
  188. * .setName('MyDefinedName')
  189. * .build();
  190. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  191. * ```
  192. */
  193. setFormula(e) {
  194. return this._definedNameParam.formulaOrRefString = `=${e}`, this;
  195. }
  196. /**
  197. * Sets the reference of the defined name builder.
  198. * @param {string} a1Notation The reference of the defined name.
  199. * @returns {FDefinedNameBuilder} The defined name builder.
  200. * @example
  201. * ```ts
  202. * const workbook = univerAPI.getActiveWorkbook();
  203. * const definedNameBuilder = univerAPI.newDefinedName()
  204. * .setRef('Sheet1!$A$1')
  205. * .build();
  206. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  207. * ```
  208. */
  209. setRef(e) {
  210. return this._definedNameParam.formulaOrRefString = e, this;
  211. }
  212. /**
  213. * Sets the reference of the defined name builder by range .
  214. * @param {number} row The start row of the range.
  215. * @param {number} column The start column of the range.
  216. * @param {number} numRows The number of rows in the range.
  217. * @param {number} numColumns The number of columns in the range.
  218. * @returns {FDefinedNameBuilder} The defined name builder.
  219. * @example
  220. * ```ts
  221. * const workbook = univerAPI.getActiveWorkbook();
  222. * const definedNameBuilder = univerAPI.newDefinedName()
  223. * .setRefByRange(1, 3, 2, 5)
  224. * .build();
  225. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  226. * ```
  227. */
  228. setRefByRange(e, t, n, s) {
  229. return this._definedNameParam.formulaOrRefString = fr({
  230. startRow: e,
  231. endRow: e + (n != null ? n : 1) - 1,
  232. startColumn: t,
  233. endColumn: t + (s != null ? s : 1) - 1
  234. }), this;
  235. }
  236. /**
  237. * Sets the comment of the defined name builder.
  238. * @param {string} comment The comment of the defined name.
  239. * @returns {FDefinedNameBuilder} The defined name builder.
  240. * @example
  241. * ```ts
  242. * const workbook = univerAPI.getActiveWorkbook();
  243. * const definedNameBuilder = univerAPI.newDefinedName()
  244. * .setComment('This is a comment')
  245. * .build();
  246. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  247. * ```
  248. */
  249. setComment(e) {
  250. return this._definedNameParam.comment = e, this;
  251. }
  252. /**
  253. * Sets the hidden status of the defined name builder.
  254. * @param {boolean} hidden The hidden status of the defined name.
  255. * @returns {FDefinedNameBuilder} The defined name builder.
  256. * @example
  257. * ```ts
  258. * const workbook = univerAPI.getActiveWorkbook();
  259. * const definedNameBuilder = univerAPI.newDefinedName()
  260. * .setHidden(true)
  261. * .build();
  262. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  263. * ```
  264. */
  265. setHidden(e) {
  266. return this._definedNameParam.hidden = e, this;
  267. }
  268. /**
  269. * Builds the defined name.
  270. * @returns {FDefinedNameBuilder} The defined name mutation parameter.
  271. * @example
  272. * ```ts
  273. * const workbook = univerAPI.getActiveWorkbook();
  274. * const definedNameBuilder = univerAPI.newDefinedName()
  275. * .setRef('Sheet1!$A$1')
  276. * .setName('MyDefinedName')
  277. * .build();
  278. * workbook.insertDefinedNameBuilder(definedNameBuilder);
  279. * ```
  280. */
  281. build() {
  282. return this._definedNameParam;
  283. }
  284. load(e) {
  285. return this._definedNameParam = e, this;
  286. }
  287. };
  288. var F2 = class extends Fi {
  289. constructor(r, e, t, n, s, i, o, h, a, d) {
  290. 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;
  291. }
  292. _apply() {
  293. this._definedNameParam.name === "" && (this._definedNameParam.name = Kt(this._definedNameParam.unitId, this._localeService, this._definedNamesService)), this._commandService.syncExecuteCommand(Ur.id, this._definedNameParam);
  294. }
  295. /**
  296. * Gets the name of the defined name.
  297. * @returns {string} The name of the defined name.
  298. * @example
  299. * ```ts
  300. * const workbook = univerAPI.getActiveWorkbook();
  301. * const definedName = workbook.getDefinedNames[0];
  302. * console.log(definedName.getName());
  303. * ```
  304. */
  305. getName() {
  306. return this._definedNameParam.name;
  307. }
  308. /**
  309. * Sets the name of the defined name.
  310. * @param {string} name The name of the defined name.
  311. * @example
  312. * ```ts
  313. * const workbook = univerAPI.getActiveWorkbook();
  314. * const definedName = workbook.getDefinedName('MyDefinedName');
  315. * definedName.setName('NewDefinedName');
  316. * ```
  317. */
  318. setName(r) {
  319. this._definedNameParam.name = r, this._apply();
  320. }
  321. /**
  322. * Sets the formula of the defined name.
  323. * @param {string} formula The formula of the defined name.
  324. * @example
  325. * ```ts
  326. * const workbook = univerAPI.getActiveWorkbook();
  327. * const definedName = workbook.getDefinedName('MyDefinedName');
  328. * definedName.setFormula('SUM(Sheet1!$A$1)');
  329. * ```
  330. */
  331. setFormula(r) {
  332. this._definedNameParam.formulaOrRefString = `=${r}`, this._apply();
  333. }
  334. /**
  335. * Sets the reference of the defined name.
  336. * @param {string} refString The reference of the defined name.
  337. * @example
  338. * ```ts
  339. * const workbook = univerAPI.getActiveWorkbook();
  340. * const definedName = workbook.getDefinedNames[0];
  341. * definedName.setRef('Sheet1!$A$1');
  342. * ```
  343. */
  344. setRef(r) {
  345. this._definedNameParam.formulaOrRefString = r, this._apply();
  346. }
  347. /**
  348. * Gets the reference of the defined name.
  349. * @returns {string} The reference of the defined name.
  350. * @example
  351. * ```ts
  352. * const workbook = univerAPI.getActiveWorkbook();
  353. * const definedName = workbook.getDefinedNames[0];
  354. * console.log(definedName.getFormulaOrRefString());
  355. * ```
  356. */
  357. getFormulaOrRefString() {
  358. return this._definedNameParam.formulaOrRefString;
  359. }
  360. /**
  361. * Sets the reference of the defined name by range.
  362. * @param {number} row The start row of the range.
  363. * @param {number} column The start column of the range.
  364. * @param {number} numRows The number of rows in the range.
  365. * @param {number} numColumns The number of columns in the range.
  366. * @example
  367. * ```ts
  368. * const workbook = univerAPI.getActiveWorkbook();
  369. * const definedName = workbook.getDefinedNames[0];
  370. * definedName.setRefByRange(1, 3, 2, 5);
  371. * ```
  372. */
  373. setRefByRange(r, e, t, n) {
  374. this._definedNameParam.formulaOrRefString = fr({
  375. startRow: r,
  376. endRow: r + (t != null ? t : 1) - 1,
  377. startColumn: e,
  378. endColumn: e + (n != null ? n : 1) - 1
  379. }), this._apply();
  380. }
  381. /**
  382. * Gets the comment of the defined name.
  383. * @returns {string | undefined} The comment of the defined name.
  384. * @example
  385. * ```ts
  386. * const workbook = univerAPI.getActiveWorkbook();
  387. * const definedName = workbook.getDefinedNames[0];
  388. * console.log(definedName.getComment());
  389. * ```
  390. */
  391. getComment() {
  392. return this._definedNameParam.comment;
  393. }
  394. /**
  395. * Sets the comment of the defined name.
  396. * @param {string} comment The comment of the defined name.
  397. * @example
  398. * ```ts
  399. * const workbook = univerAPI.getActiveWorkbook();
  400. * const definedName = workbook.getDefinedNames[0];
  401. * definedName.setComment('This is a comment');
  402. * ```
  403. */
  404. setComment(r) {
  405. this._definedNameParam.comment = r, this._apply();
  406. }
  407. /**
  408. * Sets the scope of the defined name to the worksheet.
  409. * @param {FWorksheet} worksheet The worksheet to set the scope to.
  410. * @example
  411. * ```ts
  412. * const workbook = univerAPI.getActiveWorkbook();
  413. * const worksheet = workbook.getWorksheets[0];
  414. * const definedName = workbook.getDefinedNames[0];
  415. * definedName.setScopeToWorksheet(worksheet);
  416. * ```
  417. */
  418. setScopeToWorksheet(r) {
  419. this._definedNameParam.localSheetId = r.getSheetId(), this._apply();
  420. }
  421. /**
  422. * Sets the scope of the defined name to the workbook.
  423. * @example
  424. * ```ts
  425. * const workbook = univerAPI.getActiveWorkbook();
  426. * const definedName = workbook.getDefinedNames[0];
  427. * definedName.setScopeToWorkbook();
  428. * ```
  429. */
  430. setScopeToWorkbook() {
  431. this._definedNameParam.localSheetId = ch, this._apply();
  432. }
  433. /**
  434. * Sets the hidden status of the defined name.
  435. * @param {boolean} hidden The hidden status of the defined name.
  436. * @example
  437. * ```ts
  438. * const workbook = univerAPI.getActiveWorkbook();
  439. * const definedName = workbook.getDefinedNames[0];
  440. * definedName.setHidden(true);
  441. * ```
  442. */
  443. setHidden(r) {
  444. this._definedNameParam.hidden = r, this._apply();
  445. }
  446. /**
  447. * Deletes the defined name.
  448. * @example
  449. * ```ts
  450. * const workbook = univerAPI.getActiveWorkbook();
  451. * const definedName = workbook.getDefinedNames[0];
  452. * definedName.delete();
  453. * ```
  454. */
  455. delete() {
  456. this._commandService.syncExecuteCommand(Ir.id, this._definedNameParam);
  457. }
  458. /**
  459. * Gets the local sheet id of the defined name.
  460. * @returns {string | undefined} The local sheet id of the defined name.
  461. * @example
  462. * ```ts
  463. * const workbook = univerAPI.getActiveWorkbook();
  464. * const definedName = workbook.getDefinedNames[0];
  465. * console.log(definedName.getLocalSheetId());
  466. * ```
  467. */
  468. getLocalSheetId() {
  469. return this._definedNameParam.localSheetId;
  470. }
  471. /**
  472. * Checks if the defined name is in the workbook scope.
  473. * @returns {boolean} True if the defined name is in the workbook scope, false otherwise.
  474. * @example
  475. * ```ts
  476. * const workbook = univerAPI.getActiveWorkbook();
  477. * const definedName = workbook.getDefinedNames[0];
  478. * console.log(definedName.isWorkbookScope());
  479. * ```
  480. */
  481. isWorkbookScope() {
  482. return this._definedNameParam.localSheetId === ch;
  483. }
  484. /**
  485. * Converts the defined name to a defined name builder.
  486. * @returns {FDefinedNameBuilder} The defined name builder.
  487. * @example
  488. * ```ts
  489. * const workbook = univerAPI.getActiveWorkbook();
  490. * const definedName = workbook.getDefinedNames[0];
  491. * const definedNameBuilder = definedName.toBuilder();
  492. * const param definedNameBuilder.setName('NewDefinedName').setFormula('SUM(Sheet1!$A$1)').build();
  493. * workbook.updateDefinedNameBuilder(param);
  494. * ```
  495. */
  496. toBuilder() {
  497. const r = this._injector.createInstance(V);
  498. return r.load(this._definedNameParam), r;
  499. }
  500. };
  501. F2 = qt2([
  502. w(1, ot(Ot)),
  503. w(2, Pt),
  504. w(3, UE),
  505. w(4, ot(Ye)),
  506. w(5, ot(de)),
  507. w(6, ot(un)),
  508. w(7, ot(bE)),
  509. w(8, ot(Vr)),
  510. w(9, pr)
  511. ], F2);
  512. var Yt = Object.defineProperty;
  513. var Jt = Object.getOwnPropertyDescriptor;
  514. var Qt = (r, e, t, n) => {
  515. for (var s = n > 1 ? void 0 : n ? Jt(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  516. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  517. return n && s && Yt(e, t, s), s;
  518. };
  519. var R = (r, e) => (t, n) => e(t, n, r);
  520. var j = class extends Fi {
  521. constructor(e, t, n, s, i, o, h) {
  522. super();
  523. b(this, "permissionPointsDefinition", bh);
  524. b(this, "rangeRuleChangedAfterAuth$");
  525. b(this, "sheetRuleChangedAfterAuth$");
  526. 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$;
  527. }
  528. /**
  529. * Configures a specific permission point for a workbook.
  530. *
  531. * This function sets or updates a permission point for a workbook identified by `unitId`.
  532. * It creates a new permission point if it does not already exist, and updates the point with the provided value.
  533. * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
  534. * @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.
  535. * @param {boolean} value - The boolean value to determine whether the permission point is enabled or disabled.
  536. */
  537. setWorkbookPermissionPoint(e, t, n) {
  538. const s = new t(e);
  539. this._permissionService.getPermissionPoint(s.id) || this._permissionService.addPermissionPoint(s), this._permissionService.updatePermissionPoint(s.id, n);
  540. }
  541. /**
  542. * This function is used to set whether the workbook can be edited
  543. * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
  544. * @param {boolean} value - A value that controls whether the workbook can be edited
  545. */
  546. setWorkbookEditPermission(e, t) {
  547. this.setWorkbookPermissionPoint(e, Me, t);
  548. }
  549. /**
  550. * This function is used to add a base permission for a worksheet.
  551. * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
  552. * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
  553. * @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`.
  554. */
  555. async addWorksheetBasePermission(e, t) {
  556. if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
  557. throw new Error("sheet protection cannot intersect with range protection");
  558. const s = await this._authzIoService.create({
  559. objectType: D.Worksheet,
  560. worksheetObject: {
  561. collaborators: [],
  562. unitID: e,
  563. strategies: [],
  564. name: "",
  565. scope: void 0
  566. }
  567. });
  568. if (this._commandService.syncExecuteCommand(ct.id, {
  569. unitId: e,
  570. subUnitId: t,
  571. rule: {
  572. permissionId: s,
  573. unitType: D.Worksheet,
  574. unitId: e,
  575. subUnitId: t
  576. }
  577. }))
  578. return s;
  579. }
  580. /**
  581. * Delete the entire table protection set for the worksheet and reset the point permissions of the worksheet to true
  582. * @param {string} unitId - The unique identifier of the workbook for which the permission is being set.
  583. * @param {string} subUnitId - The unique identifier of the worksheet for which the permission is being set.
  584. */
  585. removeWorksheetPermission(e, t) {
  586. this._commandService.syncExecuteCommand(St.id, {
  587. unitId: e,
  588. subUnitId: t
  589. }), [...we2(), ...ke()].forEach((n) => {
  590. const s = new n(e, t);
  591. this._permissionService.updatePermissionPoint(s.id, true);
  592. }), this._worksheetProtectionPointRuleModel.deleteRule(e, t);
  593. }
  594. /**
  595. * Sets the worksheet permission point by updating or adding the permission point for the worksheet.
  596. * If the worksheet doesn't have a base permission, it creates one to used render
  597. * @param {string} unitId - The unique identifier of the workbook.
  598. * @param {string} subUnitId - The unique identifier of the worksheet.
  599. * @param {WorkSheetPermissionPointConstructor} FPointClass - The constructor for the permission point class.
  600. * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
  601. * @param {boolean} value - The new permission value to be set for the worksheet.
  602. * @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`.
  603. */
  604. async setWorksheetPermissionPoint(e, t, n, s) {
  605. const i = this._worksheetProtectionRuleModel.getRule(e, t);
  606. let o;
  607. if (n === Te || n === Hn)
  608. if (i)
  609. o = i.permissionId;
  610. else {
  611. if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length > 0)
  612. throw new Error("sheet protection cannot intersect with range protection");
  613. o = await this.addWorksheetBasePermission(e, t);
  614. }
  615. else {
  616. const c = this._worksheetProtectionPointRuleModel.getRule(e, t);
  617. c ? o = c.permissionId : (o = await this._authzIoService.create({
  618. objectType: D.Worksheet,
  619. worksheetObject: {
  620. collaborators: [],
  621. unitID: e,
  622. strategies: [],
  623. name: "",
  624. scope: void 0
  625. }
  626. }), this._commandService.syncExecuteCommand(Ao.id, { unitId: e, subUnitId: t, permissionId: o }));
  627. }
  628. const a = new n(e, t);
  629. return this._permissionService.getPermissionPoint(a.id) || this._permissionService.addPermissionPoint(a), this._permissionService.updatePermissionPoint(a.id, s), o;
  630. }
  631. /**
  632. * Adds a range protection to the worksheet.
  633. * @param {string} unitId - The unique identifier of the workbook.
  634. * @param {string} subUnitId - The unique identifier of the worksheet.
  635. * @param {IRange[]} ranges - The ranges to be protected.
  636. * @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
  637. */
  638. async addRangeBaseProtection(e, t, n) {
  639. const s = await this._authzIoService.create({
  640. objectType: D.SelectRange,
  641. selectRangeObject: {
  642. collaborators: [],
  643. unitID: e,
  644. name: "",
  645. scope: void 0
  646. }
  647. }), i = `ruleId_${qt(6)}`;
  648. if (this._worksheetProtectionRuleModel.getRule(e, t))
  649. throw new Error("sheet protection cannot intersect with range protection");
  650. if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).some((c) => c.ranges.some((v) => n.some((k) => en.intersects(k, v)))))
  651. throw new Error("range protection cannot intersect");
  652. if (this._commandService.syncExecuteCommand(Ne.id, {
  653. unitId: e,
  654. subUnitId: t,
  655. rules: [{
  656. permissionId: s,
  657. unitType: D.SelectRange,
  658. unitId: e,
  659. subUnitId: t,
  660. ranges: n,
  661. id: i
  662. }]
  663. }))
  664. return {
  665. permissionId: s,
  666. ruleId: i
  667. };
  668. }
  669. /**
  670. * Removes the range protection from the worksheet.
  671. * @param {string} unitId - The unique identifier of the workbook.
  672. * @param {string} subUnitId - The unique identifier of the worksheet.
  673. * @param {string[]} ruleIds - The rule IDs of the range protection to be removed.
  674. */
  675. removeRangeProtection(e, t, n) {
  676. this._commandService.syncExecuteCommand(ze.id, {
  677. unitId: e,
  678. subUnitId: t,
  679. ruleIds: n
  680. }) && this._rangeProtectionRuleModel.getSubunitRuleList(e, t).length === 0 && (this._worksheetProtectionPointRuleModel.deleteRule(e, t), [...ke()].forEach((o) => {
  681. const h = new o(e, t);
  682. this._permissionService.updatePermissionPoint(h.id, h.value);
  683. }));
  684. }
  685. /**
  686. * Modify the permission points of a custom area
  687. * @param {string} unitId - The unique identifier of the workbook.
  688. * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
  689. * @param {string} permissionId - The unique identifier of the permission that controls access to the range.
  690. * @param {RangePermissionPointConstructor} FPointClass - The constructor for the range permission point class.
  691. * See the [permission-point documentation](https://github.com/dream-num/univer/tree/dev/packages/sheets/src/services/permission/permission-point) for more details.
  692. * @param {boolean} value - The new permission value to be set for the range (e.g., true for allowing access, false for restricting access).
  693. */
  694. setRangeProtectionPermissionPoint(e, t, n, s, i) {
  695. const o = new s(e, t, n);
  696. this._permissionService.getPermissionPoint(o.id) || this._permissionService.addPermissionPoint(o), this._permissionService.updatePermissionPoint(o.id, i);
  697. }
  698. /**
  699. * Sets the ranges for range protection in a worksheet.
  700. *
  701. * This method finds the rule by unitId, subUnitId, and ruleId, and updates the rule with the provided ranges.
  702. * It checks for overlaps with existing ranges in the same subunit and shows an error message if any overlap is detected.
  703. * If no overlap is found, it executes the command to update the range protection with the new ranges.
  704. * @param {string} unitId - The unique identifier of the workbook.
  705. * @param {string} subUnitId - The unique identifier of the worksheet within the workbook.
  706. * @param {string} ruleId - The ruleId of the range protection rule that is being updated.
  707. * @param {IRange[]} ranges - The array of new ranges to be set for the range protection rule.
  708. */
  709. setRangeProtectionRanges(e, t, n, s) {
  710. const i = this._rangeProtectionRuleModel.getRule(e, t, n);
  711. if (i) {
  712. if (this._rangeProtectionRuleModel.getSubunitRuleList(e, t).filter((a) => a.id !== n).some((a) => a.ranges.some((d) => s.some((c) => en.intersects(c, d)))))
  713. throw new Error("range protection cannot intersect");
  714. this._commandService.syncExecuteCommand(he.id, {
  715. unitId: e,
  716. subUnitId: t,
  717. ruleId: n,
  718. rule: {
  719. ...i,
  720. ranges: s
  721. }
  722. });
  723. }
  724. }
  725. };
  726. j = Qt([
  727. R(0, ot(Ot)),
  728. R(1, Pt),
  729. R(2, UE),
  730. R(3, ot(Ye)),
  731. R(4, ot(de)),
  732. R(5, ot(un)),
  733. R(6, ot(bE))
  734. ], j);
  735. function Xt2(r) {
  736. switch (r) {
  737. case "left":
  738. return Xt.LEFT;
  739. case "center":
  740. return Xt.CENTER;
  741. case "normal":
  742. return Xt.RIGHT;
  743. default:
  744. throw new Error(`Invalid horizontal alignment: ${r}`);
  745. }
  746. }
  747. function Zt2(r) {
  748. switch (r) {
  749. case Xt.LEFT:
  750. return "left";
  751. case Xt.CENTER:
  752. return "center";
  753. case Xt.RIGHT:
  754. return "normal";
  755. default:
  756. throw new Error(`Invalid horizontal alignment: ${r}`);
  757. }
  758. }
  759. function en2(r) {
  760. switch (r) {
  761. case "top":
  762. return hn.TOP;
  763. case "middle":
  764. return hn.MIDDLE;
  765. case "bottom":
  766. return hn.BOTTOM;
  767. default:
  768. throw new Error(`Invalid vertical alignment: ${r}`);
  769. }
  770. }
  771. function tn(r) {
  772. switch (r) {
  773. case hn.TOP:
  774. return "top";
  775. case hn.MIDDLE:
  776. return "middle";
  777. case hn.BOTTOM:
  778. return "bottom";
  779. default:
  780. throw new Error(`Invalid vertical alignment: ${r}`);
  781. }
  782. }
  783. function O(r) {
  784. return vC(r) ? {
  785. f: r,
  786. v: null,
  787. p: null
  788. } : mC(r) ? {
  789. v: r,
  790. p: null,
  791. f: null
  792. } : (fC(r), r);
  793. }
  794. function Pe(r, e) {
  795. const t = new kt(), { startRow: n, startColumn: s, endRow: i, endColumn: o } = e;
  796. if (re.isArray(r))
  797. for (let h = 0; h <= i - n; h++)
  798. for (let a = 0; a <= o - s; a++)
  799. t.setValue(h + n, a + s, O(r[h][a]));
  800. else
  801. new kt(r).forValue((a, d, c) => {
  802. t.setValue(a, d, O(c));
  803. });
  804. return t.getMatrix();
  805. }
  806. function G(r, e) {
  807. return {
  808. startRow: r.startRow,
  809. endRow: r.endRow,
  810. startColumn: 0,
  811. endColumn: e.getColumnCount() - 1,
  812. rangeType: De.ROW
  813. };
  814. }
  815. function q(r, e) {
  816. return {
  817. startRow: 0,
  818. endRow: e.getRowCount() - 1,
  819. startColumn: r.startColumn,
  820. endColumn: r.endColumn,
  821. rangeType: De.COLUMN
  822. };
  823. }
  824. var nn = Object.defineProperty;
  825. var rn = Object.getOwnPropertyDescriptor;
  826. var sn = (r, e, t, n) => {
  827. for (var s = n > 1 ? void 0 : n ? rn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  828. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  829. return n && s && nn(e, t, s), s;
  830. };
  831. var K = (r, e) => (t, n) => e(t, n, r);
  832. var S = class extends al {
  833. constructor(r, e, t, n, s, i) {
  834. super(n), this._workbook = r, this._worksheet = e, this._range = t, this._injector = n, this._commandService = s, this._formulaDataModel = i;
  835. }
  836. /**
  837. * Get the unit ID of the current workbook
  838. * @returns {string} The unit ID of the workbook
  839. * @example
  840. * ```ts
  841. * univerAPI.getActiveWorkbook()
  842. * .getActiveSheet()
  843. * .getActiveRange()
  844. * .getUnitId()
  845. * ```
  846. */
  847. getUnitId() {
  848. return this._workbook.getUnitId();
  849. }
  850. /**
  851. * Gets the name of the worksheet
  852. * @returns {string} The name of the worksheet
  853. * @example
  854. * ```ts
  855. * univerAPI.getActiveWorkbook()
  856. * .getActiveSheet()
  857. * .getActiveRange()
  858. * .getSheetName()
  859. * ```
  860. */
  861. getSheetName() {
  862. return this._worksheet.getName();
  863. }
  864. /**
  865. * Gets the ID of the worksheet
  866. * @returns {string} The ID of the worksheet
  867. * @example
  868. * ```ts
  869. * univerAPI.getActiveWorkbook()
  870. * .getActiveSheet()
  871. * .getActiveRange()
  872. * .getSheetId()
  873. * ```
  874. */
  875. getSheetId() {
  876. return this._worksheet.getSheetId();
  877. }
  878. /**
  879. * Gets the area where the statement is applied
  880. * @returns {IRange} The area where the statement is applied
  881. * @example
  882. * ```ts
  883. * univerAPI.getActiveWorkbook()
  884. * .getActiveSheet()
  885. * .getActiveRange()
  886. * .getRange()
  887. * ```
  888. */
  889. getRange() {
  890. return this._range;
  891. }
  892. /**
  893. * Gets the starting row number of the applied area
  894. * @returns {number} The starting row number of the area
  895. * @example
  896. * ```ts
  897. * univerAPI.getActiveWorkbook()
  898. * .getActiveSheet()
  899. * .getActiveRange()
  900. * .getRow()
  901. * ```
  902. */
  903. getRow() {
  904. return this._range.startRow;
  905. }
  906. /**
  907. * Gets the starting column number of the applied area
  908. * @returns {number} The starting column number of the area
  909. * @example
  910. * ```ts
  911. * univerAPI.getActiveWorkbook()
  912. * .getActiveSheet()
  913. * .getActiveRange()
  914. * .getColumn()
  915. * ```
  916. */
  917. getColumn() {
  918. return this._range.startColumn;
  919. }
  920. /**
  921. * Gets the width of the applied area
  922. * @returns {number} The width of the area
  923. * @example
  924. * ```ts
  925. * univerAPI.getActiveWorkbook()
  926. * .getActiveSheet()
  927. * .getActiveRange()
  928. * .getWidth()
  929. * ```
  930. */
  931. getWidth() {
  932. return this._range.endColumn - this._range.startColumn + 1;
  933. }
  934. /**
  935. * Gets the height of the applied area
  936. * @returns {number} The height of the area
  937. * @example
  938. * ```ts
  939. * univerAPI.getActiveWorkbook()
  940. * .getActiveSheet()
  941. * .getActiveRange()
  942. * .getHeight()
  943. * ```
  944. */
  945. getHeight() {
  946. return this._range.endRow - this._range.startRow + 1;
  947. }
  948. /**
  949. * Return range whether this range is merged
  950. * @returns {boolean} if true is merged
  951. * @example
  952. * ```ts
  953. * univerAPI.getActiveWorkbook()
  954. * .getActiveSheet()
  955. * .getActiveRange()
  956. * .isMerged()
  957. * ```
  958. */
  959. isMerged() {
  960. const { startColumn: r, startRow: e, endColumn: t, endRow: n } = this._range;
  961. return this._worksheet.getMergedCellRange(e, r, n, t).some((i) => en.equals(i, this._range));
  962. }
  963. /**
  964. * Return first cell style data in this range
  965. * @returns {IStyleData | null} The cell style data
  966. * @example
  967. * ```ts
  968. * univerAPI.getActiveWorkbook()
  969. * .getActiveSheet()
  970. * .getActiveRange()
  971. * .getCellStyleData()
  972. * ```
  973. */
  974. getCellStyleData() {
  975. var t;
  976. const r = this.getCellData(), e = this._workbook.getStyles();
  977. return r && e && (t = e.getStyleByCell(r)) != null ? t : null;
  978. }
  979. /**
  980. * Return first cell style in this range
  981. * @returns {TextStyleValue | null} The cell style
  982. * @example
  983. * ```ts
  984. * univerAPI.getActiveWorkbook()
  985. * .getActiveSheet()
  986. * .getActiveRange()
  987. * .getCellStyle()
  988. * ```
  989. */
  990. getCellStyle() {
  991. const r = this.getCellStyleData();
  992. return r ? cr.create(r) : null;
  993. }
  994. /**
  995. * Returns the cell styles for the cells in the range.
  996. * @returns {Array<Array<TextStyleValue | null>>} A two-dimensional array of cell styles.
  997. * @example
  998. * ```ts
  999. * univerAPI.getActiveWorkbook()
  1000. * .getActiveSheet()
  1001. * .getActiveRange()
  1002. * .getCellStyles()
  1003. * ```
  1004. */
  1005. getCellStyles() {
  1006. const r = this.getCellDatas(), e = this._workbook.getStyles();
  1007. return r.map((t) => t.map((n) => {
  1008. if (!n)
  1009. return null;
  1010. const s = e.getStyleByCell(n);
  1011. return s ? cr.create(s) : null;
  1012. }));
  1013. }
  1014. getValue(r) {
  1015. var e, t;
  1016. return r ? this.getValueAndRichTextValue() : (t = (e = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) == null ? void 0 : e.v) != null ? t : null;
  1017. }
  1018. getValues(r) {
  1019. var o, h;
  1020. r && this.getValueAndRichTextValues();
  1021. const { startRow: e, endRow: t, startColumn: n, endColumn: s } = this._range, i = [];
  1022. for (let a = e; a <= t; a++) {
  1023. const d = [];
  1024. for (let c = n; c <= s; c++)
  1025. d.push((h = (o = this._worksheet.getCell(a, c)) == null ? void 0 : o.v) != null ? h : null);
  1026. i.push(d);
  1027. }
  1028. return i;
  1029. }
  1030. /**
  1031. * Return first cell model data in this range
  1032. * @returns {ICellData | null} The cell model data
  1033. * @example
  1034. * ```ts
  1035. * univerAPI.getActiveWorkbook()
  1036. * .getActiveSheet()
  1037. * .getActiveRange()
  1038. * .getCellData()
  1039. * ```
  1040. */
  1041. getCellData() {
  1042. var r;
  1043. return (r = this._worksheet.getCell(this._range.startRow, this._range.startColumn)) != null ? r : null;
  1044. }
  1045. /**
  1046. * Alias for getCellDataGrid.
  1047. * @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.
  1048. * @example
  1049. * ```ts
  1050. * univerAPI.getActiveWorkbook()
  1051. * .getActiveSheet()
  1052. * .getActiveRange()
  1053. * .getCellDatas()
  1054. * ```
  1055. */
  1056. getCellDatas() {
  1057. return this.getCellDataGrid();
  1058. }
  1059. /**
  1060. * Returns the cell data for the cells in the range.
  1061. * @returns {Nullable<ICellData>[][]} A two-dimensional array of cell data.
  1062. * @example
  1063. * ```ts
  1064. * univerAPI.getActiveWorkbook()
  1065. * .getActiveSheet()
  1066. * .getActiveRange()
  1067. * .getCellDataGrid()
  1068. * ```
  1069. */
  1070. getCellDataGrid() {
  1071. const { startRow: r, endRow: e, startColumn: t, endColumn: n } = this._range, s = [];
  1072. for (let i = r; i <= e; i++) {
  1073. const o = [];
  1074. for (let h = t; h <= n; h++)
  1075. o.push(this._worksheet.getCellRaw(i, h));
  1076. s.push(o);
  1077. }
  1078. return s;
  1079. }
  1080. /**
  1081. * Returns the rich text value for the cell at the start of this range.
  1082. * @returns {Nullable<RichTextValue>} The rich text value
  1083. * @internal
  1084. * @beta
  1085. * @example
  1086. * ```ts
  1087. * univerAPI.getActiveWorkbook()
  1088. * .getActiveSheet()
  1089. * .getActiveRange()
  1090. * .getRichTextValue()
  1091. * ```
  1092. */
  1093. getRichTextValue() {
  1094. const r = this.getCellData();
  1095. return r != null && r.p ? new Zt(r.p) : null;
  1096. }
  1097. /**
  1098. * Returns the rich text value for the cells in the range.
  1099. * @returns {Nullable<RichTextValue>[][]} A two-dimensional array of RichTextValue objects.
  1100. * @internal
  1101. * @beta
  1102. * @example
  1103. * ```ts
  1104. * univerAPI.getActiveWorkbook()
  1105. * .getActiveSheet()
  1106. * .getActiveRange()
  1107. * .getRichTextValues()
  1108. * ```
  1109. */
  1110. getRichTextValues() {
  1111. return this.getCellDataGrid().map((e) => e.map((t) => t != null && t.p ? new Zt(t.p) : null));
  1112. }
  1113. /**
  1114. * Returns the value and rich text value for the cell at the start of this range.
  1115. * @returns {Nullable<CellValue | RichTextValue>} The value and rich text value
  1116. * @internal
  1117. * @beta
  1118. * @example
  1119. * ```ts
  1120. * univerAPI.getActiveWorkbook()
  1121. * .getActiveSheet()
  1122. * .getActiveRange()
  1123. * .getValueAndRichTextValue()
  1124. * ```
  1125. */
  1126. getValueAndRichTextValue() {
  1127. const r = this.getCellData();
  1128. return r != null && r.p ? new Zt(r.p) : r == null ? void 0 : r.v;
  1129. }
  1130. /**
  1131. * Returns the value and rich text value for the cells in the range.
  1132. * @returns {Nullable<CellValue | RichTextValue>[][]} A two-dimensional array of value and rich text value
  1133. * @example
  1134. * ```ts
  1135. * univerAPI.getActiveWorkbook()
  1136. * .getActiveSheet()
  1137. * .getActiveRange()
  1138. * .getValueAndRichTextValues()
  1139. * ```
  1140. */
  1141. getValueAndRichTextValues() {
  1142. return this.getCellDatas().map((e) => e.map((t) => t != null && t.p ? new Zt(t.p) : t == null ? void 0 : t.v));
  1143. }
  1144. /**
  1145. * Returns the formulas (A1 notation) for the cells in the range. Entries in the 2D array are empty strings for cells with no formula.
  1146. * @returns {string[][]} A two-dimensional array of formulas in string format.
  1147. * @example
  1148. * ```ts
  1149. * univerAPI.getActiveWorkbook()
  1150. * .getActiveSheet()
  1151. * .getActiveRange()
  1152. * .getFormulas()
  1153. * ```
  1154. */
  1155. getFormulas() {
  1156. const r = [], { startRow: e, endRow: t, startColumn: n, endColumn: s } = this._range, i = this._worksheet.getSheetId(), o = this._workbook.getUnitId();
  1157. for (let h = e; h <= t; h++) {
  1158. const a = [];
  1159. for (let d = n; d <= s; d++) {
  1160. const c = this._formulaDataModel.getFormulaStringByCell(h, d, i, o);
  1161. a.push(c || "");
  1162. }
  1163. r.push(a);
  1164. }
  1165. return r;
  1166. }
  1167. /**
  1168. * Returns true if the cell wrap is enabled
  1169. * @returns {boolean} True if the cell wrap is enabled
  1170. * @example
  1171. * ```ts
  1172. * univerAPI.getActiveWorkbook()
  1173. * .getActiveSheet()
  1174. * .getActiveRange()
  1175. * .getWrap()
  1176. * ```
  1177. */
  1178. getWrap() {
  1179. return this._worksheet.getRange(this._range).getWrap() === we.TRUE;
  1180. }
  1181. /**
  1182. * Returns the text wrapping strategy for the top left cell of the range.
  1183. * @returns {WrapStrategy} The text wrapping strategy
  1184. * @example
  1185. * ```ts
  1186. * univerAPI.getActiveWorkbook()
  1187. * .getActiveSheet()
  1188. * .getActiveRange()
  1189. * .getWrapStrategy()
  1190. * ```
  1191. */
  1192. getWrapStrategy() {
  1193. return this._worksheet.getRange(this._range).getWrapStrategy();
  1194. }
  1195. /**
  1196. * Returns the horizontal alignment for the top left cell of the range.
  1197. * @returns {string} The horizontal alignment
  1198. * @example
  1199. * ```ts
  1200. * univerAPI.getActiveWorkbook()
  1201. * .getActiveSheet()
  1202. * .getActiveRange()
  1203. * .getHorizontalAlignment()
  1204. * ```
  1205. */
  1206. getHorizontalAlignment() {
  1207. return Zt2(this._worksheet.getRange(this._range).getHorizontalAlignment());
  1208. }
  1209. /**
  1210. * Returns the vertical alignment for the top left cell of the range.
  1211. * @returns {string} The vertical alignment
  1212. * @example
  1213. * ```ts
  1214. * univerAPI.getActiveWorkbook()
  1215. * .getActiveSheet()
  1216. * .getActiveRange()
  1217. * .getVerticalAlignment()
  1218. * ```
  1219. */
  1220. getVerticalAlignment() {
  1221. return tn(this._worksheet.getRange(this._range).getVerticalAlignment());
  1222. }
  1223. /**
  1224. * Set custom meta data for first cell in current range.
  1225. * @param {CustomData} data The custom meta data
  1226. * @returns {FRange} This range, for chaining
  1227. * ```ts
  1228. * univerAPI.getActiveWorkbook()
  1229. * .getActiveSheet()
  1230. * .getActiveRange()
  1231. * .setCustomMetaData({ key: 'value' });
  1232. * ```
  1233. */
  1234. setCustomMetaData(r) {
  1235. return this.setValue({
  1236. custom: r
  1237. });
  1238. }
  1239. /**
  1240. * Set custom meta data for current range.
  1241. * @param {CustomData[][]} datas The custom meta data
  1242. * @returns {FRange} This range, for chaining
  1243. * ```ts
  1244. * univerAPI.getActiveWorkbook()
  1245. * .getActiveSheet()
  1246. * .getActiveRange()
  1247. * .setCustomMetaDatas([[{ key: 'value' }]]);
  1248. * ```
  1249. */
  1250. setCustomMetaDatas(r) {
  1251. return this.setValues(r.map((e) => e.map((t) => ({ custom: t }))));
  1252. }
  1253. /**
  1254. * Returns the custom meta data for the cell at the start of this range.
  1255. * @returns {CustomData | null} The custom meta data
  1256. * @example
  1257. * ```
  1258. * univerAPI.getActiveWorkbook()
  1259. * .getActiveSheet()
  1260. * .getActiveRange()
  1261. * .getCustomMetaData()
  1262. * ```
  1263. */
  1264. getCustomMetaData() {
  1265. var e;
  1266. const r = this.getCellData();
  1267. return (e = r == null ? void 0 : r.custom) != null ? e : null;
  1268. }
  1269. /**
  1270. * Returns the custom meta data for the cells in the range.
  1271. * @returns {CustomData[][]} A two-dimensional array of custom meta data
  1272. * @example
  1273. * ```
  1274. * univerAPI.getActiveWorkbook()
  1275. * .getActiveSheet()
  1276. * .getActiveRange()
  1277. * .getCustomMetaDatas()
  1278. * ```
  1279. */
  1280. getCustomMetaDatas() {
  1281. return this.getCellDataGrid().map((e) => e.map((t) => {
  1282. var n;
  1283. return (n = t == null ? void 0 : t.custom) != null ? n : null;
  1284. }));
  1285. }
  1286. /**
  1287. * Sets basic border properties for the current range.
  1288. * @param {BorderType} type The type of border to apply
  1289. * @param {BorderStyleTypes} style The border style
  1290. * @param {string} [color] Optional border color in CSS notation
  1291. * @returns {FRange} This range, for chaining
  1292. * @example
  1293. * ```ts
  1294. * univerAPI.getActiveWorkbook()
  1295. * .getActiveSheet()
  1296. * .getActiveRange()
  1297. * .setBorder(BorderType.ALL, BorderStyleType.THIN, '#ff0000');
  1298. * ```
  1299. */
  1300. setBorder(r, e, t) {
  1301. return this._commandService.syncExecuteCommand(Ou.id, {
  1302. unitId: this._workbook.getUnitId(),
  1303. subUnitId: this._worksheet.getSheetId(),
  1304. value: {
  1305. type: r,
  1306. style: e,
  1307. color: t
  1308. }
  1309. }), this;
  1310. }
  1311. // #region editing
  1312. /**
  1313. * Set background color for current range.
  1314. * @param {string} color The background color
  1315. * @returns {FRange} This range, for chaining
  1316. * @example
  1317. * ```ts
  1318. * univerAPI.getActiveWorkbook()
  1319. * .getActiveSheet()
  1320. * .getActiveRange()
  1321. * .setBackgroundColor('red')
  1322. * ```
  1323. */
  1324. setBackgroundColor(r) {
  1325. return this._commandService.syncExecuteCommand(fe.id, {
  1326. unitId: this._workbook.getUnitId(),
  1327. subUnitId: this._worksheet.getSheetId(),
  1328. range: this._range,
  1329. style: {
  1330. type: "bg",
  1331. value: {
  1332. rgb: r
  1333. }
  1334. }
  1335. }), this;
  1336. }
  1337. /**
  1338. * Set background color for current range.
  1339. * @param {string} color The background color
  1340. * @returns {FRange} This range, for chaining
  1341. * @example
  1342. * ```typescript
  1343. * univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange().setBackground('red')
  1344. * ```
  1345. */
  1346. setBackground(r) {
  1347. return this.setBackgroundColor(r), this;
  1348. }
  1349. /**
  1350. * Set new value for current cell, first cell in this range.
  1351. * @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.
  1352. * @returns {FRange} This range, for chaining
  1353. * ```ts
  1354. * univerAPI.getActiveWorkbook()
  1355. * .getActiveSheet()
  1356. * .getActiveRange()
  1357. * .setValue(1);
  1358. * ```
  1359. */
  1360. setValue(r) {
  1361. const e = O(r);
  1362. if (!e)
  1363. throw new Error("Invalid value");
  1364. return this._commandService.syncExecuteCommand(on.id, {
  1365. unitId: this._workbook.getUnitId(),
  1366. subUnitId: this._worksheet.getSheetId(),
  1367. range: this._range,
  1368. value: e
  1369. }), this;
  1370. }
  1371. /**
  1372. * Set new value for current cell, first cell in this range.
  1373. * @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.
  1374. * @returns {FRange} This range, for chaining
  1375. * ```ts
  1376. * univerAPI.getActiveWorkbook()
  1377. * .getActiveSheet()
  1378. * .getActiveRange()
  1379. * .setValueForCell(1);
  1380. * ```
  1381. */
  1382. setValueForCell(r) {
  1383. const e = O(r);
  1384. if (!e)
  1385. throw new Error("Invalid value");
  1386. return this._commandService.syncExecuteCommand(on.id, {
  1387. unitId: this._workbook.getUnitId(),
  1388. subUnitId: this._worksheet.getSheetId(),
  1389. range: {
  1390. startColumn: this._range.startColumn,
  1391. startRow: this._range.startRow,
  1392. endColumn: this._range.endColumn,
  1393. endRow: this._range.endRow
  1394. },
  1395. value: e
  1396. }), this;
  1397. }
  1398. /**
  1399. * Set the rich text value for the cell at the start of this range.
  1400. * @param {RichTextValue | IDocumentData} value The rich text value
  1401. * @returns {FRange} The range
  1402. * @example
  1403. * ```
  1404. * univerAPI.getActiveWorkbook()
  1405. * .getActiveSheet()
  1406. * .getActiveRange()
  1407. * .setRichTextValueForCell(new RichTextValue().insertText('Hello'));
  1408. * ```
  1409. */
  1410. setRichTextValueForCell(r) {
  1411. const e = r instanceof Zt ? r.getData() : r, t = {
  1412. unitId: this._workbook.getUnitId(),
  1413. subUnitId: this._worksheet.getSheetId(),
  1414. range: {
  1415. startColumn: this._range.startColumn,
  1416. startRow: this._range.startRow,
  1417. endColumn: this._range.endColumn,
  1418. endRow: this._range.endRow
  1419. },
  1420. value: { p: e }
  1421. };
  1422. return this._commandService.syncExecuteCommand(on.id, t), this;
  1423. }
  1424. /**
  1425. * Set the rich text value for the cells in the range.
  1426. * @param {RichTextValue[][]} values The rich text value
  1427. * @returns {FRange} The range
  1428. * @example
  1429. * ```ts
  1430. * univerAPI
  1431. * .getActiveWorkbook()
  1432. * .getActiveSheet()
  1433. * .getActiveRange()
  1434. * .setRichTextValues([[new RichTextValue().insertText('Hello')]]);
  1435. * ```
  1436. */
  1437. setRichTextValues(r) {
  1438. const e = r.map((s) => s.map((i) => i && { p: i instanceof Zt ? i.getData() : i })), t = Pe(e, this._range), n = {
  1439. unitId: this._workbook.getUnitId(),
  1440. subUnitId: this._worksheet.getSheetId(),
  1441. range: this._range,
  1442. value: t
  1443. };
  1444. return this._commandService.syncExecuteCommand(on.id, n), this;
  1445. }
  1446. /**
  1447. * Set the cell wrap of the given range.
  1448. * 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.
  1449. * @param {boolean} isWrapEnabled Whether to enable wrap
  1450. * @returns {FRange} this range, for chaining
  1451. * @example
  1452. * ```ts
  1453. * univerAPI.getActiveWorkbook()
  1454. * .getActiveSheet()
  1455. * .getActiveRange()
  1456. * .setWrap(true);
  1457. * ```
  1458. */
  1459. setWrap(r) {
  1460. return this._commandService.syncExecuteCommand(sl.id, {
  1461. unitId: this._workbook.getUnitId(),
  1462. subUnitId: this._worksheet.getSheetId(),
  1463. range: this._range,
  1464. value: r ? xn.WRAP : xn.UNSPECIFIED
  1465. }), this;
  1466. }
  1467. /**
  1468. * Sets the text wrapping strategy for the cells in the range.
  1469. * @param {WrapStrategy} strategy The text wrapping strategy
  1470. * @returns {FRange} this range, for chaining
  1471. * @example
  1472. * ```ts
  1473. * univerAPI.getActiveWorkbook()
  1474. * .getActiveSheet()
  1475. * .getActiveRange()
  1476. * .setWrapStrategy(WrapStrategy.WRAP);
  1477. * ```
  1478. */
  1479. setWrapStrategy(r) {
  1480. return this._commandService.syncExecuteCommand(sl.id, {
  1481. unitId: this._workbook.getUnitId(),
  1482. subUnitId: this._worksheet.getSheetId(),
  1483. range: this._range,
  1484. value: r
  1485. }), this;
  1486. }
  1487. /**
  1488. * Set the vertical (top to bottom) alignment for the given range (top/middle/bottom).
  1489. * @param {"top" | "middle" | "bottom"} alignment The vertical alignment
  1490. * @returns {FRange} this range, for chaining
  1491. * @example
  1492. * ```ts
  1493. * univerAPI.getActiveWorkbook()
  1494. * .getActiveSheet()
  1495. * .getActiveRange()
  1496. * .setVerticalAlignment('top');
  1497. * ```
  1498. */
  1499. setVerticalAlignment(r) {
  1500. return this._commandService.syncExecuteCommand(nl.id, {
  1501. unitId: this._workbook.getUnitId(),
  1502. subUnitId: this._worksheet.getSheetId(),
  1503. range: this._range,
  1504. value: en2(r)
  1505. }), this;
  1506. }
  1507. /**
  1508. * Set the horizontal (left to right) alignment for the given range (left/center/right).
  1509. * @param {"left" | "center" | "normal"} alignment The horizontal alignment
  1510. * @returns {FRange} this range, for chaining
  1511. * @example
  1512. * ```ts
  1513. * univerAPI.getActiveWorkbook()
  1514. * .getActiveSheet()
  1515. * .getActiveRange()
  1516. * .setHorizontalAlignment('left');
  1517. * ```
  1518. */
  1519. setHorizontalAlignment(r) {
  1520. return this._commandService.syncExecuteCommand(ol.id, {
  1521. unitId: this._workbook.getUnitId(),
  1522. subUnitId: this._worksheet.getSheetId(),
  1523. range: this._range,
  1524. value: Xt2(r)
  1525. }), this;
  1526. }
  1527. /**
  1528. * 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.
  1529. * @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.
  1530. * @returns {FRange} This range, for chaining
  1531. * @example
  1532. * ```ts
  1533. * univerAPI.getActiveWorkbook()
  1534. * .getActiveSheet()
  1535. * .getActiveRange()
  1536. * .setValues([[1, 2], [3, 4]]);
  1537. * ```
  1538. */
  1539. setValues(r) {
  1540. const e = Pe(r, this._range);
  1541. return this._commandService.syncExecuteCommand(on.id, {
  1542. unitId: this._workbook.getUnitId(),
  1543. subUnitId: this._worksheet.getSheetId(),
  1544. range: this._range,
  1545. value: e
  1546. }), this;
  1547. }
  1548. /**
  1549. * Sets the font weight for the given range (normal/bold),
  1550. * @param {FontWeight|null} fontWeight The font weight, either 'normal' or 'bold'; a null value resets the font weight.
  1551. * @returns {FRange} This range, for chaining
  1552. * @example
  1553. * ```ts
  1554. * univerAPI.getActiveWorkbook()
  1555. * .getActiveSheet()
  1556. * .getActiveRange()
  1557. * .setFontWeight('bold');
  1558. * ```
  1559. */
  1560. setFontWeight(r) {
  1561. let e;
  1562. if (r === "bold")
  1563. e = we.TRUE;
  1564. else if (r === "normal")
  1565. e = we.FALSE;
  1566. else if (r === null)
  1567. e = null;
  1568. else
  1569. throw new Error("Invalid fontWeight");
  1570. const t = {
  1571. type: "bl",
  1572. value: e
  1573. }, n = {
  1574. unitId: this._workbook.getUnitId(),
  1575. subUnitId: this._worksheet.getSheetId(),
  1576. range: this._range,
  1577. style: t
  1578. };
  1579. return this._commandService.syncExecuteCommand(fe.id, n), this;
  1580. }
  1581. /**
  1582. * Sets the font style for the given range ('italic' or 'normal').
  1583. * @param {FontStyle|null} fontStyle The font style, either 'italic' or 'normal'; a null value resets the font style.
  1584. * @returns {FRange} This range, for chaining
  1585. * @example
  1586. * ```ts
  1587. * univerAPI.getActiveWorkbook()
  1588. * .getActiveSheet()
  1589. * .getActiveRange()
  1590. * .setFontStyle('italic');
  1591. * ```
  1592. */
  1593. setFontStyle(r) {
  1594. let e;
  1595. if (r === "italic")
  1596. e = we.TRUE;
  1597. else if (r === "normal")
  1598. e = we.FALSE;
  1599. else if (r === null)
  1600. e = null;
  1601. else
  1602. throw new Error("Invalid fontStyle");
  1603. const t = {
  1604. type: "it",
  1605. value: e
  1606. }, n = {
  1607. unitId: this._workbook.getUnitId(),
  1608. subUnitId: this._worksheet.getSheetId(),
  1609. range: this._range,
  1610. style: t
  1611. };
  1612. return this._commandService.syncExecuteCommand(fe.id, n), this;
  1613. }
  1614. /**
  1615. * Sets the font line style of the given range ('underline', 'line-through', or 'none').
  1616. * @param {FontLine|null} fontLine The font line style, either 'underline', 'line-through', or 'none'; a null value resets the font line style.
  1617. * @returns {FRange} This range, for chaining
  1618. * @example
  1619. * ```ts
  1620. * univerAPI.getActiveWorkbook()
  1621. * .getActiveSheet()
  1622. * .getActiveRange()
  1623. * .setFontLine('underline');
  1624. * ```
  1625. */
  1626. setFontLine(r) {
  1627. if (r === "underline")
  1628. this._setFontUnderline({
  1629. s: we.TRUE
  1630. });
  1631. else if (r === "line-through")
  1632. this._setFontStrikethrough({
  1633. s: we.TRUE
  1634. });
  1635. else if (r === "none")
  1636. this._setFontUnderline({
  1637. s: we.FALSE
  1638. }), this._setFontStrikethrough({
  1639. s: we.FALSE
  1640. });
  1641. else if (r === null)
  1642. this._setFontUnderline(null), this._setFontStrikethrough(null);
  1643. else
  1644. throw new Error("Invalid fontLine");
  1645. return this;
  1646. }
  1647. /**
  1648. * Sets the font underline style of the given ITextDecoration
  1649. * @param {ITextDecoration|null} value The font underline style of the given ITextDecoration; a null value resets the font underline style
  1650. * @returns {void}
  1651. * @example
  1652. * ```ts
  1653. * univerAPI.getActiveWorkbook()
  1654. * .getActiveSheet()
  1655. * .getActiveRange()
  1656. * .setFontLine('underline');
  1657. * ```
  1658. */
  1659. _setFontUnderline(r) {
  1660. const e = {
  1661. type: "ul",
  1662. value: r
  1663. }, t = {
  1664. unitId: this._workbook.getUnitId(),
  1665. subUnitId: this._worksheet.getSheetId(),
  1666. range: this._range,
  1667. style: e
  1668. };
  1669. this._commandService.syncExecuteCommand(fe.id, t);
  1670. }
  1671. /**
  1672. * Sets the font strikethrough style of the given ITextDecoration
  1673. * @param {ITextDecoration|null} value The font strikethrough style of the given ITextDecoration; a null value resets the font strikethrough style
  1674. * @returns {void}
  1675. */
  1676. _setFontStrikethrough(r) {
  1677. const e = {
  1678. type: "st",
  1679. value: r
  1680. }, t = {
  1681. unitId: this._workbook.getUnitId(),
  1682. subUnitId: this._worksheet.getSheetId(),
  1683. range: this._range,
  1684. style: e
  1685. };
  1686. this._commandService.syncExecuteCommand(fe.id, t);
  1687. }
  1688. /**
  1689. * Sets the font family, such as "Arial" or "Helvetica".
  1690. * @param {string|null} fontFamily The font family to set; a null value resets the font family.
  1691. * @returns {FRange} This range, for chaining
  1692. * @example
  1693. * ```ts
  1694. * univerAPI.getActiveWorkbook()
  1695. * .getActiveSheet()
  1696. * .getActiveRange()
  1697. * .setFontFamily('Arial');
  1698. * ```
  1699. */
  1700. setFontFamily(r) {
  1701. const e = {
  1702. type: "ff",
  1703. value: r
  1704. }, t = {
  1705. unitId: this._workbook.getUnitId(),
  1706. subUnitId: this._worksheet.getSheetId(),
  1707. range: this._range,
  1708. style: e
  1709. };
  1710. return this._commandService.syncExecuteCommand(fe.id, t), this;
  1711. }
  1712. /**
  1713. * Sets the font size, with the size being the point size to use.
  1714. * @param {number|null} size A font size in point size. A null value resets the font size.
  1715. * @returns {FRange} This range, for chaining
  1716. * @example
  1717. * ```ts
  1718. * univerAPI.getActiveWorkbook()
  1719. * .getActiveSheet()
  1720. * .getActiveRange()
  1721. * .setFontSize(12);
  1722. * ```
  1723. */
  1724. setFontSize(r) {
  1725. const e = {
  1726. type: "fs",
  1727. value: r
  1728. }, t = {
  1729. unitId: this._workbook.getUnitId(),
  1730. subUnitId: this._worksheet.getSheetId(),
  1731. range: this._range,
  1732. style: e
  1733. };
  1734. return this._commandService.syncExecuteCommand(fe.id, t), this;
  1735. }
  1736. /**
  1737. * Sets the font color in CSS notation (such as '#ffffff' or 'white').
  1738. * @param {string|null} color The font color in CSS notation (such as '#ffffff' or 'white'); a null value resets the color.
  1739. * @returns {FRange} This range, for chaining
  1740. * @example
  1741. * ```ts
  1742. * univerAPI.getActiveWorkbook()
  1743. * .getActiveSheet()
  1744. * .getActiveRange()
  1745. * .setFontColor('#ff0000');
  1746. * ```
  1747. */
  1748. setFontColor(r) {
  1749. const t = {
  1750. type: "cl",
  1751. value: r === null ? null : { rgb: r }
  1752. }, n = {
  1753. unitId: this._workbook.getUnitId(),
  1754. subUnitId: this._worksheet.getSheetId(),
  1755. range: this._range,
  1756. style: t
  1757. };
  1758. return this._commandService.syncExecuteCommand(fe.id, n), this;
  1759. }
  1760. // #endregion editing
  1761. //#region Merge cell
  1762. /**
  1763. * Merge cells in a range into one merged cell
  1764. * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
  1765. * @returns {FRange} This range, for chaining
  1766. * @example
  1767. * ```ts
  1768. * const workbook = univerAPI.getActiveWorkbook();
  1769. * const worksheet = workbook.getActiveSheet();
  1770. * const range = worksheet.getRange(0, 0, 2, 2);
  1771. * const merge = range.merge();
  1772. * const isMerged = merge.isMerged();
  1773. * console.log('debugger', isMerged);
  1774. * ```
  1775. */
  1776. merge(r = true) {
  1777. const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId();
  1778. return Th(this._injector, e, t, [this._range], r), this;
  1779. }
  1780. /**
  1781. * Merges cells in a range horizontally.
  1782. * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
  1783. * @returns {FRange} This range, for chaining
  1784. * @example
  1785. * ```ts
  1786. * const workbook = univerAPI.getActiveWorkbook();
  1787. * const worksheet = workbook.getActiveSheet();
  1788. * const range = worksheet.getRange(2, 2, 2, 2);
  1789. * const merge = range.mergeAcross();
  1790. * const allMerge = worksheet.getMergeData();
  1791. * console.log(allMerge.length); // There will be two merged cells.
  1792. * ```
  1793. */
  1794. mergeAcross(r = true) {
  1795. const e = Zr([this._range], yu.ROWS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
  1796. return Th(this._injector, t, n, e, r), this;
  1797. }
  1798. /**
  1799. * Merges cells in a range vertically.
  1800. * @param {boolean} [defaultMerge] - If true, only the value in the upper left cell is retained.
  1801. * @returns {FRange} This range, for chaining
  1802. * @example
  1803. * ```ts
  1804. * const workbook = univerAPI.getActiveWorkbook();
  1805. * const worksheet = workbook.getActiveSheet();
  1806. * const range = worksheet.getRange(4, 4, 2, 2);
  1807. * const merge = range.mergeVertically();
  1808. * const allMerge = worksheet.getMergeData();
  1809. * console.log(allMerge.length); // There will be two merged cells.
  1810. * ```
  1811. */
  1812. mergeVertically(r = true) {
  1813. const e = Zr([this._range], yu.COLUMNS), t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
  1814. return Th(this._injector, t, n, e, r), this;
  1815. }
  1816. /**
  1817. * Returns true if cells in the current range overlap a merged cell.
  1818. * @returns {boolean} is overlap with a merged cell
  1819. * @example
  1820. * ```ts
  1821. * const workbook = univerAPI.getActiveWorkbook();
  1822. * const worksheet = workbook.getActiveSheet();
  1823. * const range = worksheet.getRange(0,0,2,2);
  1824. * const merge = range.merge();
  1825. * const anchor = worksheet.getRange(0,0);
  1826. * const isPartOfMerge = anchor.isPartOfMerge();
  1827. * console.log('debugger, isPartOfMerge) // true
  1828. * ```
  1829. */
  1830. isPartOfMerge() {
  1831. const { startRow: r, startColumn: e, endRow: t, endColumn: n } = this._range;
  1832. return this._worksheet.getMergedCellRange(r, e, t, n).length > 0;
  1833. }
  1834. /**
  1835. * Break all horizontally- or vertically-merged cells contained within the range list into individual cells again.
  1836. * @returns {FRange} This range, for chaining
  1837. * @example
  1838. * ```ts
  1839. * const workbook = univerAPI.getActiveWorkbook();
  1840. * const worksheet = workbook.getActiveSheet();
  1841. * const range = worksheet.getRange(0,0,2,2);
  1842. * const merge = range.merge();
  1843. * const anchor = worksheet.getRange(0,0);
  1844. * const isPartOfMergeFirst = anchor.isPartOfMerge();
  1845. * console.log('debugger' isPartOfMergeFirst) // true
  1846. * range.breakApart();
  1847. * const isPartOfMergeSecond = anchor.isPartOfMerge();
  1848. * console.log('debugger' isPartOfMergeSecond) // false
  1849. * ```
  1850. */
  1851. breakApart() {
  1852. return this._commandService.syncExecuteCommand(Iu.id, { ranges: [this._range] }), this;
  1853. }
  1854. //#endregion
  1855. /**
  1856. * Iterate cells in this range. Merged cells will be respected.
  1857. * @param {Function} callback the callback function to be called for each cell in the range
  1858. * @param {number} callback.row the row number of the cell
  1859. * @param {number} callback.col the column number of the cell
  1860. * @param {ICellData} callback.cell the cell data
  1861. * ```ts
  1862. * const fWorkbook = univerAPI.getActiveWorkbook();
  1863. * const fWorksheet = fWorkbook.getActiveSheet();
  1864. * const fRange = fWorksheet.getRange('A1:B2');
  1865. * fRange.forEach((row, col, cell) => {
  1866. * console.log(row, col, cell);
  1867. * });
  1868. * ```
  1869. */
  1870. forEach(r) {
  1871. const { startColumn: e, startRow: t, endColumn: n, endRow: s } = this._range;
  1872. this._worksheet.getMatrixWithMergedCells(t, e, s, n).forValue((i, o, h) => {
  1873. r(i, o, h);
  1874. });
  1875. }
  1876. /**
  1877. * Returns a string description of the range, in A1 notation.
  1878. * @param {boolean} [withSheet] - If true, the sheet name is included in the A1 notation.
  1879. * @returns {string} The A1 notation of the range.
  1880. * ```ts
  1881. * const fWorkbook = univerAPI.getActiveWorkbook();
  1882. * const fWorksheet = fWorkbook.getActiveSheet();
  1883. * const fRange = fWorksheet.getRange('A1:B2');
  1884. * console.log(fRange.getA1Notation()); // A1:B2
  1885. * ```
  1886. */
  1887. getA1Notation(r) {
  1888. return r ? pc(this._worksheet.getName(), this._range) : fr(this._range);
  1889. }
  1890. /**
  1891. * Sets the specified range as the active range, with the top left cell in the range as the current cell.
  1892. * @returns {FRange} This range, for chaining.
  1893. * @example
  1894. * ```ts
  1895. * const fWorkbook = univerAPI.getActiveWorkbook();
  1896. * const fWorksheet = fWorkbook.getActiveSheet();
  1897. * const fRange = fWorksheet.getRange('A1:B2');
  1898. * fRange.activate(); // the active cell will be A1
  1899. * ```
  1900. */
  1901. activate() {
  1902. return this._injector.createInstance(f, this._workbook).setActiveRange(this), this;
  1903. }
  1904. /**
  1905. * Sets the specified cell as the current cell.
  1906. * If the specified cell is present in an existing range, then that range becomes the active range with the cell as the current cell.
  1907. * 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.
  1908. * @returns {FRange} This range, for chaining.
  1909. * @description If the range is not a single cell, an error will be thrown.
  1910. */
  1911. activateAsCurrentCell() {
  1912. const r = this._worksheet.getMergedCell(this._range.startRow, this._range.startColumn);
  1913. if (r && en.equals(r, this._range) || !r && this._range.startRow === this._range.endRow && this._range.startColumn === this._range.endColumn)
  1914. return this.activate();
  1915. throw new Error("The range is not a single cell");
  1916. }
  1917. /**
  1918. * Splits a column of text into multiple columns based on a custom specified delimiter.
  1919. * @param {boolean} [treatMultipleDelimitersAsOne] Whether to treat multiple continuous delimiters as one. The default value is false.
  1920. * @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.
  1921. * @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.
  1922. * @example Show how to split text to columns with combined delimiter. The bit operations are used to combine the delimiters.
  1923. * // A1:A3 has following values:
  1924. * // A | B | C
  1925. * // 1;;2;3 | |
  1926. * // 1;,2;3 | |
  1927. * // After calling splitTextToColumns(false, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
  1928. * // A | B | C | D
  1929. * // 1 | | 2 | 3
  1930. * // 1 | | 2 | 3
  1931. * // After calling splitTextToColumns(true, SplitDelimiterEnum.Semicolon|SplitDelimiterEnum.Comma), the range will be:
  1932. * // A | B | C
  1933. * // 1 | 2 | 3
  1934. * // 1 | 2 | 3
  1935. * @example Show how to split text to columns with custom delimiter
  1936. * // A1:A3 has following values:
  1937. * // A | B | C
  1938. * // 1#2#3 | |
  1939. * // 4##5#6 | |
  1940. * // After calling splitTextToColumns(false, SplitDelimiterEnum.Custom, '#'), the range will be:
  1941. * // A | B | C | D
  1942. * // 1 | 2 | 3 |
  1943. * // 4 | | 5 | 6
  1944. * // After calling splitTextToColumns(true, SplitDelimiterEnum.Custom, '#'), the range will be:
  1945. * // A | B | C
  1946. * // 1 | 2 | 3
  1947. * // 4 | 5 | 6
  1948. */
  1949. splitTextToColumns(r, e, t) {
  1950. this._commandService.syncExecuteCommand(Tl.id, {
  1951. unitId: this._workbook.getUnitId(),
  1952. subUnitId: this._worksheet.getSheetId(),
  1953. range: this._range,
  1954. delimiter: e,
  1955. customDelimiter: t,
  1956. treatMultipleDelimitersAsOne: r
  1957. });
  1958. }
  1959. /**
  1960. * Set the theme style for the range.
  1961. * @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.
  1962. * @example
  1963. * ```ts
  1964. * const fWorkbook = univerAPI.getActiveWorkbook();
  1965. * const fWorksheet = fWorkbook.getActiveSheet();
  1966. * const fRange = fWorksheet.getRange('A1:E20');
  1967. * fRange.useThemeStyle('default');
  1968. * ```
  1969. */
  1970. useThemeStyle(r) {
  1971. if (r == null) {
  1972. const e = this.getUsedThemeStyle();
  1973. e && this.removeThemeStyle(e);
  1974. } else
  1975. this._commandService.syncExecuteCommand(ba.id, {
  1976. unitId: this._workbook.getUnitId(),
  1977. subUnitId: this._worksheet.getSheetId(),
  1978. range: this._range,
  1979. themeName: r
  1980. });
  1981. }
  1982. /**
  1983. * Remove the theme style for the range.
  1984. * @param {string} themeName The name of the theme style to remove.
  1985. * @example
  1986. * ```ts
  1987. * const fWorkbook = univerAPI.getActiveWorkbook();
  1988. * const fWorksheet = fWorkbook.getActiveSheet();
  1989. * const fRange = fWorksheet.getRange('A1:E20');
  1990. * fRange.removeThemeStyle('default');
  1991. * ```
  1992. */
  1993. removeThemeStyle(r) {
  1994. this._commandService.syncExecuteCommand(iu.id, {
  1995. unitId: this._workbook.getUnitId(),
  1996. subUnitId: this._worksheet.getSheetId(),
  1997. range: this._range,
  1998. themeName: r
  1999. });
  2000. }
  2001. /**
  2002. * Gets the theme style applied to the range.
  2003. * @returns {string | undefined} The name of the theme style applied to the range or not exist.
  2004. * @example
  2005. * ```ts
  2006. * const fWorkbook = univerAPI.getActiveWorkbook();
  2007. * const fWorksheet = fWorkbook.getActiveSheet();
  2008. * const fRange = fWorksheet.getRange('A1:E20');
  2009. * fRange.useThemeStyle('default');
  2010. * const themeStyle = fRange.getUsedThemeStyle();
  2011. * console.log(themeStyle); // 'default'
  2012. * ```
  2013. */
  2014. getUsedThemeStyle() {
  2015. return this._injector.get(ho).getAppliedRangeThemeStyle({
  2016. unitId: this._workbook.getUnitId(),
  2017. subUnitId: this._worksheet.getSheetId(),
  2018. range: this._range
  2019. });
  2020. }
  2021. };
  2022. S = sn([
  2023. K(3, ot(Ot)),
  2024. K(4, Pt),
  2025. K(5, ot(Pr))
  2026. ], S);
  2027. var on2 = Object.defineProperty;
  2028. var hn2 = Object.getOwnPropertyDescriptor;
  2029. var an2 = (r, e, t, n) => {
  2030. for (var s = n > 1 ? void 0 : n ? hn2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  2031. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  2032. return n && s && on2(e, t, s), s;
  2033. };
  2034. var dn = (r, e) => (t, n) => e(t, n, r);
  2035. var L = class {
  2036. constructor(r, e, t, n) {
  2037. this._workbook = r, this._worksheet = e, this._selections = t, this._injector = n;
  2038. }
  2039. /**
  2040. * Represents the active selection in the sheet. Which means the selection contains the active cell.
  2041. * @returns {FRange | null} The active selection.
  2042. * @example
  2043. * ```ts
  2044. * const fWorkbook = univerAPI.getActiveWorkbook();
  2045. * const fWorksheet = fWorkbook.getActiveSheet();
  2046. * const fSelection = fWorksheet.getSelection();
  2047. * const activeRange = fSelection.getActiveRange();
  2048. * console.log(activeRange);
  2049. * ```
  2050. */
  2051. getActiveRange() {
  2052. const r = this._selections.find((e) => !!e.primary);
  2053. return r ? this._injector.createInstance(S, this._workbook, this._worksheet, r.range) : null;
  2054. }
  2055. /**
  2056. * Represents the active selection list in the sheet.
  2057. * @returns {FRange[]} The active selection list.
  2058. * @example
  2059. * ```ts
  2060. * const fWorkbook = univerAPI.getActiveWorkbook();
  2061. * const fWorksheet = fWorkbook.getActiveSheet();
  2062. * const fSelection = fWorksheet.getSelection();
  2063. * const activeRangeList = fSelection.getActiveRangeList();
  2064. * console.log(activeRangeList);
  2065. * ```
  2066. */
  2067. getActiveRangeList() {
  2068. return this._selections.map((r) => this._injector.createInstance(S, this._workbook, this._worksheet, r.range));
  2069. }
  2070. /**
  2071. * Represents the current select cell in the sheet.
  2072. * @returns {ISelectionCell} The current select cell info.Pay attention to the type of the return value.
  2073. * @example
  2074. * ```ts
  2075. * const fWorkbook = univerAPI.getActiveWorkbook();
  2076. * const fWorksheet = fWorkbook.getActiveSheet();
  2077. * const fSelection = fWorksheet.getSelection();
  2078. * const currentCell = fSelection.getCurrentCell();
  2079. * console.log(currentCell);
  2080. * ```
  2081. */
  2082. getCurrentCell() {
  2083. const r = this._selections.find((e) => !!e.primary);
  2084. return r ? r.primary : null;
  2085. }
  2086. /**
  2087. * Returns the active sheet in the spreadsheet.
  2088. * @returns {FWorksheet} The active sheet in the spreadsheet.
  2089. * @example
  2090. * ```ts
  2091. * const fWorkbook = univerAPI.getActiveWorkbook();
  2092. * const fWorksheet = fWorkbook.getActiveSheet();
  2093. * const fSelection = fWorksheet.getSelection();
  2094. * const activeSheet = fSelection.getActiveSheet();
  2095. * console.log(activeSheet.equalTo(fWorksheet)); // true
  2096. * ```
  2097. */
  2098. getActiveSheet() {
  2099. const r = this._injector.createInstance(f, this._workbook);
  2100. return this._injector.createInstance(m, r, this._workbook, this._worksheet);
  2101. }
  2102. /**
  2103. * 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.
  2104. * @param {FRange} cell The new primary cell to update.
  2105. * @returns {FSelection} The new selection after updating the primary cell.Because the selection is immutable, the return value is a new selection.
  2106. * @example
  2107. * ```ts
  2108. * const fWorkbook = univerAPI.getActiveWorkbook();
  2109. * const fWorksheet = fWorkbook.getActiveSheet();
  2110. * const fSelection = fWorksheet.getSelection();
  2111. * const cell = fWorksheet.getCell('A1');
  2112. * const newSelection = fSelection.updatePrimaryCell(cell);
  2113. * console.log(newSelection.getActiveRange().getA1Notation()); // A1
  2114. * ```
  2115. */
  2116. updatePrimaryCell(r) {
  2117. const e = this._injector.get(Pt);
  2118. let t = [], n = false;
  2119. for (const { range: i, style: o } of this._selections)
  2120. en.contains(i, r.getRange()) ? (t.push({
  2121. range: i,
  2122. primary: ve(r.getRange(), this._worksheet),
  2123. style: o
  2124. }), n = true) : t.push({
  2125. range: i,
  2126. primary: null,
  2127. style: o
  2128. });
  2129. n || (t = [
  2130. {
  2131. range: r.getRange(),
  2132. primary: ve(r.getRange(), this._worksheet)
  2133. }
  2134. ]);
  2135. const s = {
  2136. unitId: this._workbook.getUnitId(),
  2137. subUnitId: this._worksheet.getSheetId(),
  2138. selections: t
  2139. };
  2140. return e.syncExecuteCommand(re2.id, s), new L(this._workbook, this._worksheet, t, this._injector);
  2141. }
  2142. /**
  2143. *Get the next primary cell in the specified direction. If the primary cell not exists in selections, return null.
  2144. * @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).
  2145. * @returns {FRange | null} The next primary cell in the specified direction.
  2146. * @example
  2147. * ```ts
  2148. * // import { Direction } from '@univerjs/core';
  2149. * const fWorkbook = univerAPI.getActiveWorkbook();
  2150. * const fWorksheet = fWorkbook.getActiveSheet();
  2151. * // make sure the active cell is A1 and selection is A1:C3
  2152. * const fSelection = fWorksheet.getSelection();
  2153. * const nextCell = fSelection.getNextDataRange(Direction.RIGHT);
  2154. * console.log(nextCell?.getA1Notation()); // B1
  2155. * ```
  2156. */
  2157. getNextDataRange(r) {
  2158. if (!this._selections.find((n) => !!n.primary))
  2159. return null;
  2160. const t = _h(this._selections.concat(), r, this._worksheet);
  2161. return t ? this._injector.createInstance(S, this._workbook, this._worksheet, t) : null;
  2162. }
  2163. };
  2164. L = an2([
  2165. dn(3, ot(Ot))
  2166. ], L);
  2167. var cn = Object.defineProperty;
  2168. var un2 = Object.getOwnPropertyDescriptor;
  2169. var gn = (r, e, t, n) => {
  2170. for (var s = n > 1 ? void 0 : n ? un2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  2171. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  2172. return n && s && cn(e, t, s), s;
  2173. };
  2174. var B = (r, e) => (t, n) => e(t, n, r);
  2175. var m = class extends al {
  2176. /**
  2177. * Creates a new worksheet facade instance
  2178. * @param {FWorkbook} _fWorkbook - The facade workbook instance
  2179. * @param {Workbook} _workbook - The workbook instance
  2180. * @param {Worksheet} _worksheet - The worksheet instance
  2181. * @param {Injector} _injector - The injector instance
  2182. * @param {SheetsSelectionsService} _selectionManagerService - The selection manager service
  2183. * @param {ILogService} _logService - The log service
  2184. * @param {ICommandService} _commandService - The command service
  2185. */
  2186. constructor(e, t, n, s, i, o, h) {
  2187. super(s);
  2188. b(this, "setActiveSelection", this.setActiveRange);
  2189. this._fWorkbook = e, this._workbook = t, this._worksheet = n, this._injector = s, this._selectionManagerService = i, this._logService = o, this._commandService = h;
  2190. }
  2191. /**
  2192. * Returns the worksheet
  2193. * @returns {Worksheet} The worksheet instance.
  2194. * @example
  2195. * ```typescript
  2196. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet().getSheet();
  2197. * ```
  2198. */
  2199. getSheet() {
  2200. return this._worksheet;
  2201. }
  2202. /**
  2203. * Returns the injector
  2204. * @returns {Injector} The injector
  2205. * @example
  2206. * ```typescript
  2207. * const injector = univerAPI.getActiveWorkbook().getActiveSheet().getInject();
  2208. * ```
  2209. */
  2210. getInject() {
  2211. return this._injector;
  2212. }
  2213. /**
  2214. * Returns the workbook
  2215. * @returns {Workbook} The workbook instance.
  2216. * @example
  2217. * ```typescript
  2218. * const workbook = univerAPI.getActiveWorkbook().getWorkbook();
  2219. * ```
  2220. */
  2221. getWorkbook() {
  2222. return this._workbook;
  2223. }
  2224. /**
  2225. * Returns the worksheet id.
  2226. * @returns {string} The id of the worksheet.
  2227. * @example
  2228. * ```typescript
  2229. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
  2230. * const id = sheet.getSheetId();
  2231. * ```
  2232. */
  2233. getSheetId() {
  2234. return this._worksheet.getSheetId();
  2235. }
  2236. /**
  2237. * Returns the worksheet name.
  2238. * @returns {string} The name of the worksheet.
  2239. * @example
  2240. * ```typescript
  2241. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
  2242. * const name = sheet.getSheetName();
  2243. * ```
  2244. */
  2245. getSheetName() {
  2246. return this._worksheet.getName();
  2247. }
  2248. /**
  2249. * Represents the selection ranges info of the worksheet.
  2250. * @returns {FSelection} return the current selections of the worksheet or null if there is no selection.
  2251. * @example
  2252. * ```typescript
  2253. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
  2254. * const selections = sheet.getSelection();
  2255. * ```
  2256. */
  2257. getSelection() {
  2258. const e = this._selectionManagerService.getCurrentSelections();
  2259. return e ? this._injector.createInstance(L, this._workbook, this._worksheet, e) : null;
  2260. }
  2261. // #region rows
  2262. // #region default style
  2263. /**
  2264. * Get the default style of the worksheet
  2265. * @returns {IStyleData} Default style of the worksheet.
  2266. * @example
  2267. * ```typescript
  2268. * const sheet = workbook.getActiveSheet();
  2269. * const defaultStyle = sheet.getDefaultStyle();
  2270. * ```
  2271. */
  2272. getDefaultStyle() {
  2273. return this._worksheet.getDefaultCellStyle();
  2274. }
  2275. /**
  2276. * Get the default style of the worksheet row
  2277. * @param {number} index - The row index
  2278. * @param {boolean} [keepRaw] - If true, return the raw style data maybe the style name or style data, otherwise return the data from row manager
  2279. * @returns {(Nullable<IStyleData> | string)} The default style of the worksheet row name or style data
  2280. * @example
  2281. * ```typescript
  2282. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
  2283. * // Get default style for row 0 (1)
  2284. * const rowStyle = sheet.getRowDefaultStyle(0);
  2285. * // Get raw style data for row 0
  2286. * const rawRowStyle = sheet.getRowDefaultStyle(0, true);
  2287. * ```
  2288. */
  2289. getRowDefaultStyle(e, t = false) {
  2290. return this._worksheet.getRowStyle(e, t);
  2291. }
  2292. /**
  2293. * Get the default style of the worksheet column
  2294. * @param {number} index - The column index
  2295. * @param {boolean} [keepRaw] - If true, return the raw style data maybe the style name or style data, otherwise return the data from col manager
  2296. * @returns {(Nullable<IStyleData> | string)} The default style of the worksheet column name or style data
  2297. * @example
  2298. * ```typescript
  2299. * const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
  2300. * // Get default style for column 0 (A)
  2301. * const colStyle = sheet.getColumnDefaultStyle(0);
  2302. * // Get raw style data for column 0
  2303. * const rawColStyle = sheet.getColumnDefaultStyle(0, true);
  2304. * ```
  2305. */
  2306. getColumnDefaultStyle(e, t = false) {
  2307. return this._worksheet.getColumnStyle(e, t);
  2308. }
  2309. /**
  2310. * Set the default style of the worksheet
  2311. * @param {string} style - The style to set
  2312. * @returns {FWorksheet} This worksheet instance for chaining
  2313. * @example
  2314. * ```typescript
  2315. * const fWorkbook = univerAPI.getActiveWorkbook();
  2316. * const fWorksheet = fWorkbook.getActiveSheet();
  2317. * fWorksheet.setDefaultStyle('default');
  2318. * ```
  2319. */
  2320. setDefaultStyle(e) {
  2321. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId();
  2322. return this._commandService.syncExecuteCommand(Bt.id, {
  2323. unitId: t,
  2324. subUnitId: n,
  2325. defaultStyle: e
  2326. }), this._worksheet.setDefaultCellStyle(e), this;
  2327. }
  2328. /**
  2329. * Set the default style of the worksheet row
  2330. * @param {number} index - The row index
  2331. * @param {string | Nullable<IStyleData>} style - The style name or style data
  2332. * @returns {FWorksheet} This sheet, for chaining.
  2333. * @example
  2334. * ```ts
  2335. * const fWorkbook = univerAPI.getActiveWorkbook();
  2336. * const fWorksheet = fWorkbook.getActiveSheet();
  2337. * fWorksheet.setRowDefaultStyle(0, 'default');
  2338. * ```
  2339. */
  2340. setColumnDefaultStyle(e, t) {
  2341. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  2342. unitId: n,
  2343. subUnitId: s,
  2344. columnData: {
  2345. [e]: {
  2346. s: t
  2347. }
  2348. }
  2349. };
  2350. return this._commandService.syncExecuteCommand($u.id, i), this;
  2351. }
  2352. /**
  2353. * Set the default style of the worksheet column
  2354. * @param {number} index - The column index
  2355. * @param {string | Nullable<IStyleData>} style - The style name or style data
  2356. * @returns {FWorksheet} This sheet, for chaining.
  2357. * @example
  2358. * ```ts
  2359. * const fWorkbook = univerAPI.getActiveWorkbook();
  2360. * const fWorksheet = fWorkbook.getActiveSheet();
  2361. * fWorksheet.setColumnDefaultStyle(0, 'default');
  2362. * ```
  2363. */
  2364. setRowDefaultStyle(e, t) {
  2365. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  2366. unitId: n,
  2367. subUnitId: s,
  2368. rowData: {
  2369. [e]: {
  2370. s: t
  2371. }
  2372. }
  2373. };
  2374. return this._commandService.syncExecuteCommand(Ku.id, i), this;
  2375. }
  2376. getRange(e, t, n, s) {
  2377. let i, o;
  2378. if (typeof e == "object")
  2379. i = e, o = this._worksheet;
  2380. else if (typeof e == "string") {
  2381. const { range: h, sheetName: a } = fn(e), d = a ? this._workbook.getSheetBySheetName(a) : this._worksheet;
  2382. if (!d)
  2383. throw new Error("Range not found");
  2384. o = d, i = {
  2385. ...h,
  2386. unitId: this._workbook.getUnitId(),
  2387. sheetId: o.getSheetId(),
  2388. // Use the current range instead of the future actual range to match Apps Script behavior.
  2389. // Users can create the latest range in real time when needed.
  2390. rangeType: De.NORMAL,
  2391. startRow: h.rangeType === De.COLUMN ? 0 : h.startRow,
  2392. endRow: h.rangeType === De.COLUMN ? o.getMaxRows() - 1 : h.endRow,
  2393. startColumn: h.rangeType === De.ROW ? 0 : h.startColumn,
  2394. endColumn: h.rangeType === De.ROW ? o.getMaxColumns() - 1 : h.endColumn
  2395. };
  2396. } else if (typeof e == "number" && t !== void 0)
  2397. o = this._worksheet, i = {
  2398. startRow: e,
  2399. endRow: e + (n != null ? n : 1) - 1,
  2400. startColumn: t,
  2401. endColumn: t + (s != null ? s : 1) - 1,
  2402. unitId: this._workbook.getUnitId(),
  2403. sheetId: this._worksheet.getSheetId()
  2404. };
  2405. else
  2406. throw new Error("Invalid range specification");
  2407. return this._injector.createInstance(S, this._workbook, o, i);
  2408. }
  2409. /**
  2410. * Returns the current number of columns in the sheet, regardless of content.
  2411. * @returns {number} The maximum columns count of the sheet
  2412. * @example
  2413. * ```typescript
  2414. * const sheet = workbook.getActiveSheet();
  2415. * const totalColumns = sheet.getMaxColumns();
  2416. * console.log(`Sheet has ${totalColumns} columns`);
  2417. * ```
  2418. */
  2419. getMaxColumns() {
  2420. return this._worksheet.getMaxColumns();
  2421. }
  2422. /**
  2423. * Returns the current number of rows in the sheet, regardless of content.
  2424. * @returns {number}The maximum rows count of the sheet
  2425. * @example
  2426. * ```typescript
  2427. * const sheet = workbook.getActiveSheet();
  2428. * const totalRows = sheet.getMaxRows();
  2429. * console.log(`Sheet has ${totalRows} rows`);
  2430. * ```
  2431. */
  2432. getMaxRows() {
  2433. return this._worksheet.getMaxRows();
  2434. }
  2435. /**
  2436. * Inserts a row after the given row position.
  2437. * @param {number} afterPosition - The row after which the new row should be added, starting at 0 for the first row.
  2438. * @returns {FWorksheet} This sheet, for chaining.
  2439. * @example
  2440. * ```typescript
  2441. * const sheet = workbook.getActiveSheet();
  2442. * // Insert 3 rows at row index 2 (before the third row)
  2443. * sheet.insertRowAfter(2);
  2444. * // Insert 1 row at row index 0 (before the first row)
  2445. * sheet.insertRowAfter(0);
  2446. * ```
  2447. */
  2448. insertRowAfter(e) {
  2449. return this.insertRowsAfter(e, 1);
  2450. }
  2451. /**
  2452. * Inserts a row before the given row position.
  2453. * @param {number} beforePosition - The row before which the new row should be added, starting at 0 for the first row.
  2454. * @returns {FWorksheet} This sheet, for chaining.
  2455. * @example
  2456. * ```typescript
  2457. * const sheet = workbook.getActiveSheet();
  2458. * // Insert 3 rows at row index 2 (before the third row)
  2459. * sheet.insertRowBefore(2);
  2460. * // Insert 1 row at row index 0 (before the first row)
  2461. * sheet.insertRowBefore(0);
  2462. * ```
  2463. */
  2464. insertRowBefore(e) {
  2465. return this.insertRowsBefore(e, 1);
  2466. }
  2467. /**
  2468. * Inserts one or more consecutive blank rows in a sheet starting at the specified location.
  2469. * @param {number} rowIndex - The index indicating where to insert a row, starting at 0 for the first row.
  2470. * @param {number} numRows - The number of rows to insert.
  2471. * @returns {FWorksheet} This sheet, for chaining.
  2472. * @example
  2473. * ```typescript
  2474. * const sheet = workbook.getActiveSheet();
  2475. * // Insert 3 rows at row index 2 (before the third row)
  2476. * sheet.insertRows(2, 3);
  2477. * // Insert 1 row at row index 0 (before the first row)
  2478. * sheet.insertRows(0);
  2479. * ```
  2480. */
  2481. insertRows(e, t = 1) {
  2482. return this.insertRowsBefore(e, t);
  2483. }
  2484. /**
  2485. * Inserts a number of rows after the given row position.
  2486. * @param {number} afterPosition - The row after which the new rows should be added, starting at 0 for the first row.
  2487. * @param {number} howMany - The number of rows to insert.
  2488. * @returns {FWorksheet} This sheet, for chaining.
  2489. * @example
  2490. * ```typescript
  2491. * const sheet = workbook.getActiveSheet();
  2492. * // Insert 3 rows at row index 2 (before the third row)
  2493. * sheet.insertRowsAfter(2, 3);
  2494. * // Insert 1 row at row index 0 (before the first row)
  2495. * sheet.insertRowsAfter(0);
  2496. * ```
  2497. */
  2498. insertRowsAfter(e, t) {
  2499. 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);
  2500. return this._commandService.syncExecuteCommand(fr2.id, {
  2501. unitId: n,
  2502. subUnitId: s,
  2503. direction: i,
  2504. range: {
  2505. startRow: o,
  2506. endRow: h,
  2507. startColumn: a,
  2508. endColumn: d
  2509. },
  2510. cellValue: c
  2511. }), this;
  2512. }
  2513. /**
  2514. * Inserts a number of rows before the given row position.
  2515. * @param {number} beforePosition - The row before which the new rows should be added, starting at 0 for the first row.
  2516. * @param {number} howMany - The number of rows to insert.
  2517. * @returns {FWorksheet} This sheet, for chaining.
  2518. * @example
  2519. * ```typescript
  2520. * const sheet = workbook.getActiveSheet();
  2521. * // Insert 3 rows at row index 2 (before the third row)
  2522. * sheet.insertRowsBefore(2, 3);
  2523. * // Insert 1 row at row index 0 (before the first row)
  2524. * sheet.insertRowsBefore(0);
  2525. * ```
  2526. */
  2527. insertRowsBefore(e, t) {
  2528. 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);
  2529. return this._commandService.syncExecuteCommand(fr2.id, {
  2530. unitId: n,
  2531. subUnitId: s,
  2532. direction: i,
  2533. range: {
  2534. startRow: o,
  2535. endRow: h,
  2536. startColumn: a,
  2537. endColumn: d
  2538. },
  2539. cellValue: c
  2540. }), this;
  2541. }
  2542. /**
  2543. * Deletes the row at the given row position.
  2544. * @param {number} rowPosition - The position of the row, starting at 0 for the first row.
  2545. * @returns {FWorksheet} This sheet, for chaining.
  2546. * @example
  2547. * ```typescript
  2548. * const sheet = workbook.getActiveSheet();
  2549. * // Delete 3 rows at row index 2 (rows 3-5)
  2550. * sheet.deleteRow(2);
  2551. * // Delete 1 row at row index 0 (first row)
  2552. * sheet.deleteRow(0);
  2553. * ```
  2554. */
  2555. deleteRow(e) {
  2556. return this.deleteRows(e, 1);
  2557. }
  2558. /**
  2559. * Deletes a number of rows starting at the given row position.
  2560. * @param {number} rowPosition - The position of the first row to delete, starting at 0 for the first row.
  2561. * @param {number} howMany - The number of rows to delete.
  2562. * @returns {FWorksheet} This sheet, for chaining.
  2563. * @example
  2564. * ```typescript
  2565. * const sheet = workbook.getActiveSheet();
  2566. * // Delete 3 rows at row index 2 (rows 3-5)
  2567. * sheet.deleteRows(2, 3);
  2568. * // Delete 1 row at row index 0 (first row)
  2569. * sheet.deleteRows(0);
  2570. * ```
  2571. */
  2572. deleteRows(e, t) {
  2573. const n = {
  2574. startRow: e,
  2575. endRow: e + t - 1,
  2576. startColumn: 0,
  2577. endColumn: this._worksheet.getColumnCount() - 1
  2578. };
  2579. return this._commandService.syncExecuteCommand(vr.id, {
  2580. range: n,
  2581. unitId: this._workbook.getUnitId(),
  2582. subUnitId: this._worksheet.getSheetId()
  2583. }), this;
  2584. }
  2585. /**
  2586. * 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.
  2587. * @param {FRange} rowSpec - A range spanning the rows that should be moved.
  2588. * @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.
  2589. * @returns {FWorksheet} This sheet, for chaining.
  2590. * @example
  2591. * ```typescript
  2592. * const sheet = workbook.getActiveSheet();
  2593. * // Move 3 rows at row index 2 (rows 3-5) to row index 0
  2594. * sheet.moveRows(rowSpec, 0);
  2595. * // Move 1 row at row index 0 (first row) to row index 2
  2596. * sheet.moveRows(rowSpec, 2);
  2597. * ```
  2598. */
  2599. moveRows(e, t) {
  2600. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = G(e.getRange(), this._worksheet), o = i, h = {
  2601. startRow: t,
  2602. endRow: t,
  2603. startColumn: i.startColumn,
  2604. endColumn: i.endColumn
  2605. };
  2606. return this._commandService.syncExecuteCommand(Fn.id, {
  2607. unitId: n,
  2608. subUnitId: s,
  2609. range: i,
  2610. fromRange: o,
  2611. toRange: h
  2612. }), this;
  2613. }
  2614. /**
  2615. * Hides the rows in the given range.
  2616. * @param {FRange} row - The row range to hide.
  2617. * @returns {FWorksheet} This sheet, for chaining.
  2618. * @example
  2619. * ```typescript
  2620. * const sheet = workbook.getActiveSheet();
  2621. * // Hide 3 rows starting from row index 1 (rows 2-4)
  2622. * sheet.hideRow(1);
  2623. * // Hide single row at index 0 (first row)
  2624. * sheet.hideRow(0);
  2625. * ```
  2626. */
  2627. hideRow(e) {
  2628. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = G(e.getRange(), this._worksheet);
  2629. return this._commandService.syncExecuteCommand(kr.id, {
  2630. unitId: t,
  2631. subUnitId: n,
  2632. ranges: [s]
  2633. }), this;
  2634. }
  2635. /**
  2636. * Hides one or more consecutive rows starting at the given index. Use 0-index for this method
  2637. * @param {number} rowIndex - The starting index of the rows to hide
  2638. * @param {number} numRow - The number of rows to hide
  2639. * @returns {FWorksheet} This sheet, for chaining.
  2640. * @example
  2641. * ```typescript
  2642. * const sheet = workbook.getActiveSheet();
  2643. * // Hide 3 rows starting from row index 1 (rows 2-4)
  2644. * sheet.hideRows(1, 3);
  2645. * // Hide single row at index 0 (first row)
  2646. * sheet.hideRows(0);
  2647. * ```
  2648. */
  2649. hideRows(e, t = 1) {
  2650. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  2651. startRow: e,
  2652. endRow: e + t - 1,
  2653. startColumn: 0,
  2654. endColumn: this._worksheet.getColumnCount() - 1,
  2655. rangeType: De.ROW
  2656. };
  2657. return this._commandService.syncExecuteCommand(kr.id, {
  2658. unitId: n,
  2659. subUnitId: s,
  2660. ranges: [i]
  2661. }), this;
  2662. }
  2663. /**
  2664. * Make the row in the given range visible.
  2665. * @param {FRange} row - The range to unhide, if hidden.
  2666. * @returns {FWorksheet} This sheet, for chaining.
  2667. * @example
  2668. * ```typescript
  2669. * const sheet = workbook.getActiveSheet();
  2670. * // Unhide 3 rows starting from row index 1 (rows 2-4)
  2671. * sheet.unhideRow(1);
  2672. * // Unhide single row at index 0 (first row)
  2673. * sheet.unhideRow(0);
  2674. * ```
  2675. */
  2676. unhideRow(e) {
  2677. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = G(e.getRange(), this._worksheet);
  2678. return this._commandService.syncExecuteCommand(Jn.id, {
  2679. unitId: t,
  2680. subUnitId: n,
  2681. ranges: [s]
  2682. }), this;
  2683. }
  2684. /**
  2685. * Scrolling sheet to make specific rows visible.
  2686. * @param {number} rowIndex - The starting index of the rows
  2687. * @param {number} numRow - The number of rows
  2688. * @returns {FWorksheet} This worksheet instance for chaining
  2689. * @example
  2690. * ```typescript
  2691. * const sheet = workbook.getActiveSheet();
  2692. * // Show 3 rows starting from row index 1 (rows 2-4)
  2693. * sheet.showRows(1);
  2694. * // Show single row at index 0 (first row)
  2695. * sheet.showRows(0);
  2696. * ```
  2697. */
  2698. showRows(e, t = 1) {
  2699. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  2700. startRow: e,
  2701. endRow: e + t - 1,
  2702. startColumn: 0,
  2703. endColumn: this._worksheet.getColumnCount() - 1,
  2704. rangeType: De.ROW
  2705. };
  2706. return this._commandService.syncExecuteCommand(Jn.id, {
  2707. unitId: n,
  2708. subUnitId: s,
  2709. ranges: [i]
  2710. }), this;
  2711. }
  2712. /**
  2713. * 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).
  2714. * @param {number} rowPosition - The row position to change.
  2715. * @param {number} height - The height in pixels to set it to.
  2716. * @returns {FWorksheet} This worksheet instance for chaining
  2717. * @example
  2718. * ```typescript
  2719. * const sheet = workbook.getActiveSheet();
  2720. * // Set the height of the second row to 30 pixels
  2721. * sheet.setRowHeight(1, 30);
  2722. * // Set the height of the first row to 20 pixels
  2723. * sheet.setRowHeight(0, 20);
  2724. * ```
  2725. */
  2726. setRowHeight(e, t) {
  2727. return this.setRowHeights(e, 1, t);
  2728. }
  2729. /**
  2730. * Make certain row wrap and auto height.
  2731. * @param rowPosition
  2732. * @param auto
  2733. * @returns {FWorksheet} this
  2734. * @example
  2735. * ```ts
  2736. const fWorkbook = univerAPI.getActiveWorkbook();
  2737. const fWorkSheet = fWorkbook.getActiveSheet();
  2738. fWorkSheet.autoFitRow(24);
  2739. * ```
  2740. */
  2741. autoFitRow(e, t = we.TRUE) {
  2742. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = [{
  2743. startRow: e,
  2744. endRow: e,
  2745. startColumn: 0,
  2746. endColumn: this._worksheet.getColumnCount() - 1
  2747. }];
  2748. return this._commandService.syncExecuteCommand(sl.id, {
  2749. unitId: this._workbook.getUnitId(),
  2750. subUnitId: this._worksheet.getSheetId(),
  2751. range: i[0],
  2752. value: xn.WRAP
  2753. }), this._commandService.syncExecuteCommand(
  2754. Oe.id,
  2755. {
  2756. unitId: n,
  2757. subUnitId: s,
  2758. ranges: i,
  2759. autoHeightInfo: t
  2760. }
  2761. ), this;
  2762. }
  2763. /**
  2764. * Sets the height of the given rows in pixels.
  2765. * By default, rows grow to fit cell contents. If you want to force rows to a specified height, use setRowHeightsForced(startRow, numRows, height).
  2766. * @param {number} startRow - The starting row position to change
  2767. * @param {number} numRows - The number of rows to change
  2768. * @param {number} height - The height in pixels to set it to
  2769. * @returns {FWorksheet} This worksheet instance for chaining
  2770. * @example
  2771. * ```typescript
  2772. * const sheet = workbook.getActiveSheet();
  2773. * sheet.setRowHeights(1, 10, 30);
  2774. * ```
  2775. */
  2776. setRowHeights(e, t, n) {
  2777. var d;
  2778. const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = this._worksheet.getRowManager(), h = [], a = [];
  2779. for (let c = e; c < e + t; c++) {
  2780. const v = ((d = o.getRow(c)) == null ? void 0 : d.ah) || this._worksheet.getConfig().defaultRowHeight, k = {
  2781. startRow: c,
  2782. endRow: c,
  2783. startColumn: 0,
  2784. endColumn: this._worksheet.getColumnCount() - 1
  2785. };
  2786. n <= v ? h.push(k) : a.push(k);
  2787. }
  2788. return a.length > 0 && this._commandService.syncExecuteCommand(Wo.id, {
  2789. unitId: s,
  2790. subUnitId: i,
  2791. ranges: a,
  2792. value: n
  2793. }), h.length > 0 && this._commandService.syncExecuteCommand(Lo.id, {
  2794. unitId: s,
  2795. subUnitId: i,
  2796. ranges: h
  2797. }), this;
  2798. }
  2799. /**
  2800. * Sets the height of the given rows to auto.
  2801. * @param {number} startRow - The starting row position to change
  2802. * @param {number} numRows - The number of rows to change
  2803. * @returns {FWorksheet} This worksheet instance for chaining
  2804. * @example
  2805. * ```typescript
  2806. * const sheet = workbook.getActiveSheet();
  2807. * sheet.setRowAutoHeight(1, 10);
  2808. * ```
  2809. */
  2810. setRowAutoHeight(e, t) {
  2811. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = [
  2812. {
  2813. startRow: e,
  2814. endRow: e + t - 1,
  2815. startColumn: 0,
  2816. endColumn: this._worksheet.getColumnCount() - 1
  2817. }
  2818. ];
  2819. return this._commandService.syncExecuteCommand(Lo.id, {
  2820. unitId: n,
  2821. subUnitId: s,
  2822. ranges: i
  2823. }), this;
  2824. }
  2825. /**
  2826. * 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.
  2827. * @param {number} startRow - The starting row position to change
  2828. * @param {number} numRows - The number of rows to change
  2829. * @param {number} height - The height in pixels to set it to
  2830. * @returns {FWorksheet} This worksheet instance for chaining
  2831. * @example
  2832. * ```typescript
  2833. * const sheet = workbook.getActiveSheet();
  2834. * sheet.setRowHeightsForced(1, 10, 30);
  2835. * ```
  2836. */
  2837. setRowHeightsForced(e, t, n) {
  2838. const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = [
  2839. {
  2840. startRow: e,
  2841. endRow: e + t - 1,
  2842. startColumn: 0,
  2843. endColumn: this._worksheet.getColumnCount() - 1
  2844. }
  2845. ];
  2846. return this._commandService.syncExecuteCommand(Wo.id, {
  2847. unitId: s,
  2848. subUnitId: i,
  2849. ranges: o,
  2850. value: n
  2851. }), this;
  2852. }
  2853. // #endregion
  2854. /**
  2855. * Set custom properties for given rows.
  2856. * @param {IObjectArrayPrimitiveType<CustomData>} custom - The custom properties to set
  2857. * @returns {FWorksheet} This worksheet instance for chaining
  2858. * @example
  2859. * ```typescript
  2860. * const fWorkbook = univerAPI.getActiveWorkbook();
  2861. * const fWorkSheet = fWorkbook.getActiveSheet();
  2862. * fWorkSheet.setRowCustom({ key: 'value' });
  2863. * ```
  2864. */
  2865. setRowCustom(e) {
  2866. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
  2867. for (const [o, h] of Object.entries(e))
  2868. s[Number(o)] = {
  2869. custom: h
  2870. };
  2871. const i = {
  2872. unitId: t,
  2873. subUnitId: n,
  2874. rowData: s
  2875. };
  2876. return this._commandService.syncExecuteCommand(Ku.id, i), this;
  2877. }
  2878. // #region Column
  2879. /**
  2880. * Inserts a column after the given column position.
  2881. * @param {number} afterPosition - The column after which the new column should be added, starting at 0 for the first column
  2882. * @returns {FWorksheet} This worksheet instance for chaining
  2883. * @example
  2884. * ```typescript
  2885. * const sheet = workbook.getActiveSheet();
  2886. * // Insert 3 columns at column index 2 (before column C)
  2887. * sheet.insertColumnAfter(2);
  2888. * // Insert 1 column at column index 0 (before column A)
  2889. * sheet.insertColumnAfter(0);
  2890. * ```
  2891. */
  2892. insertColumnAfter(e) {
  2893. return this.insertColumnsAfter(e, 1);
  2894. }
  2895. /**
  2896. * Inserts a column before the given column position.
  2897. * @param {number} beforePosition - The column before which the new column should be added, starting at 0 for the first column
  2898. * @returns {FWorksheet} This worksheet instance for chaining
  2899. * @example
  2900. * ```typescript
  2901. * const sheet = workbook.getActiveSheet();
  2902. * // Insert 3 columns at column index 2 (before column C)
  2903. * sheet.insertColumnBefore(2);
  2904. * // Insert 1 column at column index 0 (before column A)
  2905. * sheet.insertColumnBefore(0);
  2906. * ```
  2907. */
  2908. insertColumnBefore(e) {
  2909. return this.insertColumnsBefore(e, 1);
  2910. }
  2911. /**
  2912. * Inserts one or more consecutive blank columns in a sheet starting at the specified location.
  2913. * @param {number} columnIndex - The index indicating where to insert a column, starting at 0 for the first column
  2914. * @param {number} numColumns - The number of columns to insert
  2915. * @returns {FWorksheet} This sheet, for chaining
  2916. * @example
  2917. * ```typescript
  2918. * const sheet = workbook.getActiveSheet();
  2919. * // Insert 3 columns at column index 2 (before column C)
  2920. * sheet.insertColumns(2, 3);
  2921. * // Insert 1 column at column index 0 (before column A)
  2922. * sheet.insertColumns(0);
  2923. * ```
  2924. */
  2925. insertColumns(e, t = 1) {
  2926. return this.insertColumnsBefore(e, t);
  2927. }
  2928. /**
  2929. * Inserts a given number of columns after the given column position.
  2930. * @param {number} afterPosition - The column after which the new columns should be added, starting at 0 for the first column
  2931. * @param {number} howMany - The number of columns to insert
  2932. * @returns {FWorksheet} This sheet, for chaining
  2933. * @example
  2934. * ```typescript
  2935. * const sheet = workbook.getActiveSheet();
  2936. * // Insert 3 columns at column index 2 (before column C)
  2937. * sheet.insertColumnsAfter(2, 3);
  2938. * // Insert 1 column at column index 0 (before column A)
  2939. * sheet.insertColumnsAfter(0, 1);
  2940. * ```
  2941. */
  2942. insertColumnsAfter(e, t) {
  2943. 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);
  2944. return this._commandService.syncExecuteCommand(pr2.id, {
  2945. unitId: n,
  2946. subUnitId: s,
  2947. direction: i,
  2948. range: {
  2949. startRow: o,
  2950. endRow: h,
  2951. startColumn: a,
  2952. endColumn: d
  2953. },
  2954. cellValue: c
  2955. }), this;
  2956. }
  2957. /**
  2958. * Inserts a number of columns before the given column position.
  2959. * @param {number} beforePosition - The column before which the new columns should be added, starting at 0 for the first column
  2960. * @param {number} howMany - The number of columns to insert
  2961. * @returns {FWorksheet} This sheet, for chaining
  2962. * @example
  2963. * ```typescript
  2964. * const sheet = workbook.getActiveSheet();
  2965. * // Insert 3 columns at column index 2 (before column C)
  2966. * sheet.insertColumnsBefore(2, 3);
  2967. * // Insert 1 column at column index 0 (before column A)
  2968. * sheet.insertColumnsBefore(0, 1);
  2969. * ```
  2970. */
  2971. insertColumnsBefore(e, t) {
  2972. 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);
  2973. return this._commandService.syncExecuteCommand(pr2.id, {
  2974. unitId: n,
  2975. subUnitId: s,
  2976. direction: i,
  2977. range: {
  2978. startRow: o,
  2979. endRow: h,
  2980. startColumn: a,
  2981. endColumn: d
  2982. },
  2983. cellValue: c
  2984. }), this;
  2985. }
  2986. /**
  2987. * Deletes the column at the given column position.
  2988. * @param {number} columnPosition - The position of the column, starting at 0 for the first column
  2989. * @returns {FWorksheet} This sheet, for chaining
  2990. * @example
  2991. * ```typescript
  2992. * const sheet = workbook.getActiveSheet();
  2993. * // Delete column C
  2994. * sheet.deleteColumn(2);
  2995. * // Delete column A
  2996. * sheet.deleteColumn(0);
  2997. * ```
  2998. */
  2999. deleteColumn(e) {
  3000. return this.deleteColumns(e, 1);
  3001. }
  3002. /**
  3003. * Deletes a number of columns starting at the given column position.
  3004. * @param {number} columnPosition - The position of the first column to delete, starting at 0 for the first column
  3005. * @param {number} howMany - The number of columns to delete
  3006. * @returns {FWorksheet} This sheet, for chaining
  3007. * @example
  3008. * ```typescript
  3009. * const sheet = workbook.getActiveSheet();
  3010. * // Delete 3 columns at column index 2 (columns C, D, E)
  3011. * sheet.deleteColumns(2, 3);
  3012. * // Delete 1 column at column index 0 (column A)
  3013. * sheet.deleteColumns(0, 1);
  3014. * ```
  3015. */
  3016. deleteColumns(e, t) {
  3017. const n = {
  3018. startRow: 0,
  3019. endRow: this._worksheet.getRowCount() - 1,
  3020. startColumn: e,
  3021. endColumn: e + t - 1
  3022. };
  3023. return this._commandService.syncExecuteCommand(Mr.id, {
  3024. range: n,
  3025. unitId: this._workbook.getUnitId(),
  3026. subUnitId: this._worksheet.getSheetId()
  3027. }), this;
  3028. }
  3029. /**
  3030. * 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.
  3031. * @param {FRange} columnSpec - A range spanning the columns that should be moved
  3032. * @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
  3033. * @returns {FWorksheet} This sheet, for chaining
  3034. * @example
  3035. * ```typescript
  3036. * const sheet = workbook.getActiveSheet();
  3037. * // Move columns C, D, E to column index 2 (columns B, C, D)
  3038. * sheet.moveColumns({ startColumn: 2, endColumn: 4 }, 1);
  3039. * // Move column A to column index 0 (column A)
  3040. * sheet.moveColumns({ startColumn: 0, endColumn: 0 }, 0);
  3041. * ```
  3042. */
  3043. moveColumns(e, t) {
  3044. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = q(e.getRange(), this._worksheet), o = i, h = {
  3045. startRow: 0,
  3046. endRow: this._worksheet.getRowCount() - 1,
  3047. startColumn: t,
  3048. endColumn: t
  3049. };
  3050. return this._commandService.syncExecuteCommand(jn.id, {
  3051. unitId: n,
  3052. subUnitId: s,
  3053. range: i,
  3054. fromRange: o,
  3055. toRange: h
  3056. }), this;
  3057. }
  3058. /**
  3059. * Hides the column or columns in the given range.
  3060. * @param {FRange} column - The column range to hide
  3061. * @returns {FWorksheet} This sheet, for chaining
  3062. * @example
  3063. * ```typescript
  3064. * const sheet = workbook.getActiveSheet();
  3065. * // Hide columns C, D, E
  3066. * sheet.hideColumn({ startColumn: 2, endColumn: 4 });
  3067. * // Hide column A
  3068. * sheet.hideColumn({ startColumn: 0, endColumn: 0 });
  3069. * ```
  3070. */
  3071. hideColumn(e) {
  3072. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = q(e.getRange(), this._worksheet);
  3073. return this._commandService.syncExecuteCommand(yr.id, {
  3074. unitId: t,
  3075. subUnitId: n,
  3076. ranges: [s]
  3077. }), this;
  3078. }
  3079. /**
  3080. * Hides one or more consecutive columns starting at the given index. Use 0-index for this method
  3081. * @param {number} columnIndex - The starting index of the columns to hide
  3082. * @param {number} numColumn - The number of columns to hide
  3083. * @returns {FWorksheet} This sheet, for chaining
  3084. * @example
  3085. * ```typescript
  3086. * const sheet = workbook.getActiveSheet();
  3087. * // Hide columns C, D, E
  3088. * sheet.hideColumns(2, 3);
  3089. * // Hide column A
  3090. * sheet.hideColumns(0, 1);
  3091. * ```
  3092. */
  3093. hideColumns(e, t = 1) {
  3094. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  3095. startRow: 0,
  3096. endRow: this._worksheet.getRowCount() - 1,
  3097. startColumn: e,
  3098. endColumn: e + t - 1,
  3099. rangeType: De.COLUMN
  3100. };
  3101. return this._commandService.syncExecuteCommand(yr.id, {
  3102. unitId: n,
  3103. subUnitId: s,
  3104. ranges: [i]
  3105. }), this;
  3106. }
  3107. /**
  3108. * Show the column in the given range.
  3109. * @param {FRange} column - The range to unhide, if hidden
  3110. * @returns {FWorksheet} This sheet, for chaining
  3111. * @example
  3112. * ```typescript
  3113. * const sheet = workbook.getActiveSheet();
  3114. * // Unhide columns C, D, E
  3115. * sheet.unhideColumn({ startColumn: 2, endColumn: 4 });
  3116. * // Unhide column A
  3117. * sheet.unhideColumn({ startColumn: 0, endColumn: 0 });
  3118. * ```
  3119. */
  3120. unhideColumn(e) {
  3121. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = q(e.getRange(), this._worksheet);
  3122. return this._commandService.syncExecuteCommand(Kn.id, {
  3123. unitId: t,
  3124. subUnitId: n,
  3125. ranges: [s]
  3126. }), this;
  3127. }
  3128. /**
  3129. * Show one or more consecutive columns starting at the given index. Use 0-index for this method
  3130. * @param {number} columnIndex - The starting index of the columns to unhide
  3131. * @param {number} numColumn - The number of columns to unhide
  3132. * @returns {FWorksheet} This sheet, for chaining
  3133. * @example
  3134. * ```typescript
  3135. * const sheet = workbook.getActiveSheet();
  3136. * // Unhide columns C, D, E
  3137. * sheet.unhideColumns(2, 3);
  3138. * // Unhide column A
  3139. * sheet.unhideColumns(0, 1);
  3140. * ```
  3141. */
  3142. showColumns(e, t = 1) {
  3143. const n = this._workbook.getUnitId(), s = this._worksheet.getSheetId(), i = {
  3144. startRow: 0,
  3145. endRow: this._worksheet.getRowCount() - 1,
  3146. startColumn: e,
  3147. endColumn: e + t - 1,
  3148. rangeType: De.COLUMN
  3149. };
  3150. return this._commandService.syncExecuteCommand(Kn.id, {
  3151. unitId: n,
  3152. subUnitId: s,
  3153. ranges: [i]
  3154. }), this;
  3155. }
  3156. /**
  3157. * Sets the width of the given column in pixels.
  3158. * @param {number} columnPosition - The position of the given column to set
  3159. * @param {number} width - The width in pixels to set it to
  3160. * @returns {FWorksheet} This sheet, for chaining
  3161. * @example
  3162. * ```typescript
  3163. * const sheet = workbook.getActiveSheet();
  3164. * // Set width of column B to 100 pixels
  3165. * sheet.setColumnWidth(1, 100);
  3166. * ```
  3167. */
  3168. setColumnWidth(e, t) {
  3169. return this.setColumnWidths(e, 1, t);
  3170. }
  3171. /**
  3172. * Sets the width of the given columns in pixels.
  3173. * @param {number} startColumn - The starting column position to change
  3174. * @param {number} numColumn - The number of columns to change
  3175. * @param {number} width - The width in pixels to set it to
  3176. * @returns {FWorksheet} This sheet, for chaining
  3177. * @example
  3178. * ```typescript
  3179. * const sheet = workbook.getActiveSheet();
  3180. * // Set width of columns B-D (index 1-3) to 100 pixels
  3181. * sheet.setColumnWidths(1, 3, 100);
  3182. * ```
  3183. */
  3184. setColumnWidths(e, t, n) {
  3185. const s = this._workbook.getUnitId(), i = this._worksheet.getSheetId(), o = [
  3186. {
  3187. startColumn: e,
  3188. endColumn: e + t - 1,
  3189. startRow: 0,
  3190. endRow: this._worksheet.getRowCount() - 1
  3191. }
  3192. ];
  3193. return this._commandService.syncExecuteCommand(Mn.id, {
  3194. unitId: s,
  3195. subUnitId: i,
  3196. ranges: o,
  3197. value: n
  3198. }), this;
  3199. }
  3200. // #endregion
  3201. /**
  3202. * Set custom properties for given columns.
  3203. * @param {IObjectArrayPrimitiveType<CustomData>} custom - The custom properties to set
  3204. * @returns {FWorksheet} This worksheet instance for chaining
  3205. * @example
  3206. * ```ts
  3207. * const fWorkbook = univerAPI.getActiveWorkbook();
  3208. * const fWorkSheet = fWorkbook.getActiveSheet();
  3209. * fWorkSheet.setColumnCustom({ 0: { key: 'value' } });
  3210. * ```
  3211. */
  3212. setColumnCustom(e) {
  3213. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = {};
  3214. for (const [o, h] of Object.entries(e))
  3215. s[Number(o)] = {
  3216. custom: h
  3217. };
  3218. const i = {
  3219. unitId: t,
  3220. subUnitId: n,
  3221. columnData: s
  3222. };
  3223. return this._commandService.syncExecuteCommand($u.id, i), this;
  3224. }
  3225. // #region merge cells
  3226. /**
  3227. * Get all merged cells in the current sheet
  3228. * @returns {FRange[]} all merged cells
  3229. * @example
  3230. * ```typescript
  3231. * const sheet = workbook.getActiveSheet();
  3232. * // Get all merged ranges in the sheet
  3233. * const mergedRanges = sheet.getMergedRanges();
  3234. * // Process each merged range
  3235. * mergedRanges.forEach(range => {
  3236. * console.log(range.getA1Notation());
  3237. * });
  3238. * ```
  3239. */
  3240. getMergedRanges() {
  3241. return this._worksheet.getSnapshot().mergeData.map((t) => this._injector.createInstance(S, this._workbook, this._worksheet, t));
  3242. }
  3243. /**
  3244. * Get the merged cell data of the specified row and column.
  3245. * @param {number} row - The row index
  3246. * @param {number} column - The column index
  3247. * @returns {FRange|undefined} The merged cell data, or undefined if the cell is not merged
  3248. * @example
  3249. * ```ts
  3250. * const fWorkbook = univerAPI.getActiveWorkbook();
  3251. * const fWorkSheet = fWorkbook.getActiveSheet();
  3252. * const merge = fWorkSheet.getCellMergeData(0, 0);
  3253. * if (merge) {
  3254. * console.log('Merged range:', merge.getA1Notation());
  3255. * }
  3256. * ```
  3257. */
  3258. getCellMergeData(e, t) {
  3259. const s = this._worksheet.getMergedCell(e, t);
  3260. if (s)
  3261. return this._injector.createInstance(S, this._workbook, this._worksheet, s);
  3262. }
  3263. // #endregion
  3264. /**
  3265. * Returns the selected range in the active sheet, or null if there is no active range.
  3266. * @returns {FRange | null} the active range
  3267. * @example
  3268. * ```typescript
  3269. * const sheet = workbook.getActiveSheet();
  3270. * // Get the currently active range
  3271. * const activeRange = sheet.getActiveRange();
  3272. * if (activeRange) {
  3273. * console.log('Active range:', activeRange.getA1Notation());
  3274. * }
  3275. * ```
  3276. */
  3277. getActiveRange() {
  3278. return this._fWorkbook.getActiveRange();
  3279. }
  3280. /**
  3281. * Sets the active selection region for this sheet.
  3282. * @param {FRange} range - The range to set as the active selection
  3283. * @returns {FWorksheet} This sheet, for chaining
  3284. * @example
  3285. * ```ts
  3286. * const fWorkbook = univerAPI.getActiveWorkbook();
  3287. * const fWorkSheet = fWorkbook.getActiveSheet();
  3288. * fWorkSheet.setActiveRange(fWorkSheet.getRange('A1'));
  3289. * ```
  3290. */
  3291. setActiveRange(e) {
  3292. const { unitId: t, sheetId: n } = e.getRange();
  3293. if (t !== this._workbook.getUnitId() || n !== this._worksheet.getSheetId())
  3294. throw new Error("Specified range must be part of the sheet.");
  3295. return this._fWorkbook.setActiveRange(e), this;
  3296. }
  3297. /**
  3298. * Sets the frozen state of the current sheet.
  3299. * @param {IFreeze} freeze - the scrolling viewport start range and count of freezed rows and columns.
  3300. * 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 }
  3301. * @deprecated use `setFrozenRows` and `setFrozenColumns` instead.
  3302. * @returns {FWorksheet} This worksheet instance for chaining
  3303. * @example
  3304. * ```typescript
  3305. * const sheet = workbook.getActiveSheet();
  3306. * // Freeze first 3 rows and 2 columns
  3307. * sheet.setFreeze({
  3308. * startRow: 3,
  3309. * startColumn: 2,
  3310. * xSplit: 2,
  3311. * ySplit: 3
  3312. * });
  3313. * ```
  3314. */
  3315. setFreeze(e) {
  3316. return this._logService.warn("setFreeze is deprecated, use setFrozenRows and setFrozenColumns instead"), this._commandService.syncExecuteCommand(Bu.id, {
  3317. ...e,
  3318. unitId: this._workbook.getUnitId(),
  3319. subUnitId: this.getSheetId()
  3320. }), this;
  3321. }
  3322. /**
  3323. * Cancels the frozen state of the current sheet.
  3324. * @returns {FWorksheet} This worksheet instance for chaining
  3325. * @example
  3326. * ```typescript
  3327. * const sheet = workbook.getActiveSheet();
  3328. * // Cancel freeze
  3329. * sheet.cancelFreeze();
  3330. * ```
  3331. */
  3332. cancelFreeze() {
  3333. return this._commandService.syncExecuteCommand(Fu.id, {
  3334. unitId: this._workbook.getUnitId(),
  3335. subUnitId: this.getSheetId()
  3336. }), this;
  3337. }
  3338. /**
  3339. * Get the freeze state of the current sheet.
  3340. * @returns {IFreeze} The freeze state of the current sheet
  3341. * @example
  3342. * ```typescript
  3343. * const sheet = workbook.getActiveSheet();
  3344. * // Get the freeze state of the current sheet
  3345. * const freeze = sheet.getFreeze();
  3346. * console.log(freeze);
  3347. * ```
  3348. */
  3349. getFreeze() {
  3350. return this._worksheet.getFreeze();
  3351. }
  3352. setFrozenColumns(...e) {
  3353. const t = this.getFreeze();
  3354. if (arguments.length === 1) {
  3355. const n = e[0];
  3356. this.setFreeze({
  3357. ...t,
  3358. startColumn: n > 0 ? n : -1,
  3359. xSplit: n
  3360. });
  3361. } else if (arguments.length === 2) {
  3362. let [n = 0, s = 0] = e;
  3363. n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(Bu.id, {
  3364. startColumn: s + 1,
  3365. xSplit: s - n + 1,
  3366. startRow: t.startRow,
  3367. ySplit: t.ySplit,
  3368. unitId: this._workbook.getUnitId(),
  3369. subUnitId: this.getSheetId()
  3370. });
  3371. }
  3372. return this;
  3373. }
  3374. setFrozenRows(...e) {
  3375. const t = this.getFreeze();
  3376. if (arguments.length === 1) {
  3377. const n = e[0];
  3378. this.setFreeze({
  3379. ...t,
  3380. startRow: n > 0 ? n : -1,
  3381. ySplit: n
  3382. });
  3383. } else if (arguments.length === 2) {
  3384. let [n = 0, s = 0] = e;
  3385. n > s && ([n, s] = [s, n]), this._commandService.syncExecuteCommand(Bu.id, {
  3386. startRow: s + 1,
  3387. ySplit: s - n + 1,
  3388. startColumn: t.startColumn,
  3389. xSplit: t.xSplit,
  3390. unitId: this._workbook.getUnitId(),
  3391. subUnitId: this.getSheetId()
  3392. });
  3393. }
  3394. return this;
  3395. }
  3396. /**
  3397. * Get the number of frozen columns.
  3398. * @returns {number} The number of frozen columns, returns 0 if no columns are frozen.
  3399. * @example
  3400. * ```typescript
  3401. * const fWorkbook = univerAPI.getActiveWorkbook();
  3402. * const fWorkSheet = fWorkbook.getActiveSheet();
  3403. * // Get the number of frozen columns
  3404. * const frozenColumns = fWorkSheet.getFrozenColumns();
  3405. * console.log(frozenColumns);
  3406. * ```
  3407. */
  3408. getFrozenColumns() {
  3409. const e = this.getFreeze();
  3410. return e.startColumn === -1 ? 0 : e.startColumn;
  3411. }
  3412. /**
  3413. * Get the number of frozen rows.
  3414. * @returns {number} The number of frozen rows. returns 0 if no rows are frozen.
  3415. * @example
  3416. * ```typescript
  3417. * const fWorkbook = univerAPI.getActiveWorkbook();
  3418. * const fWorkSheet = fWorkbook.getActiveSheet();
  3419. * // Get the number of frozen rows
  3420. * const frozenRows = fWorkSheet.getFrozenRows();
  3421. * console.log(frozenRows);
  3422. * ```
  3423. */
  3424. getFrozenRows() {
  3425. const e = this.getFreeze();
  3426. return e.startRow === -1 ? 0 : e.startRow;
  3427. }
  3428. /**
  3429. * Get freezed rows.
  3430. * @returns {IRowRange} The range of the frozen rows.
  3431. * @example
  3432. * ```ts
  3433. * const fWorkbook = univerAPI.getActiveWorkbook();
  3434. * const fWorkSheet = fWorkbook.getActiveSheet();
  3435. * // Get the range of the frozen rows
  3436. * const frozenRows = fWorkSheet.getFrozenRowRange();
  3437. * console.log(frozenRows);
  3438. * ```
  3439. */
  3440. getFrozenRowRange() {
  3441. const e = this._worksheet.getFreeze();
  3442. return {
  3443. startRow: e.startRow - e.ySplit,
  3444. endRow: e.startRow - 1
  3445. };
  3446. }
  3447. /**
  3448. * Get freezed columns
  3449. * @returns {IColumnRange} The range of the frozen columns.
  3450. * @example
  3451. * ```ts
  3452. * const fWorkbook = univerAPI.getActiveWorkbook();
  3453. * const fWorkSheet = fWorkbook.getActiveSheet();
  3454. * // Get the range of the frozen columns
  3455. * const frozenColumns = fWorkSheet.getFrozenColumnRange();
  3456. * console.log(frozenColumns);
  3457. * ```
  3458. */
  3459. getFrozenColumnRange() {
  3460. const e = this._worksheet.getFreeze();
  3461. return {
  3462. startColumn: e.startColumn - e.xSplit,
  3463. endColumn: e.startColumn - 1
  3464. };
  3465. }
  3466. /**
  3467. * Returns true if the sheet's gridlines are hidden; otherwise returns false. Gridlines are visible by default.
  3468. * @returns {boolean} True if the sheet's gridlines are hidden; otherwise false.
  3469. * @example
  3470. * ```ts
  3471. * const fWorkbook = univerAPI.getActiveWorkbook();
  3472. * const fWorkSheet = fWorkbook.getActiveSheet();
  3473. * // check if the gridlines are hidden
  3474. * if (fWorkSheet.hasHiddenGridLines()) {
  3475. * console.log('Gridlines are hidden');
  3476. * }
  3477. * ```
  3478. */
  3479. hasHiddenGridLines() {
  3480. return this._worksheet.getConfig().showGridlines === we.FALSE;
  3481. }
  3482. /**
  3483. * Hides or reveals the sheet gridlines.
  3484. * @param {boolean} hidden - If `true`, hide gridlines in this sheet; otherwise show the gridlines.
  3485. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3486. * @example
  3487. * ``` ts
  3488. * const fWorkbook = univerAPI.getActiveWorkbook();
  3489. * const fWorkSheet = fWorkbook.getActiveSheet();
  3490. * // hide the gridlines
  3491. * fWorkSheet.setHiddenGridlines(true);
  3492. * ```
  3493. */
  3494. setHiddenGridlines(e) {
  3495. return this._commandService.syncExecuteCommand(Nl.id, {
  3496. unitId: this._workbook.getUnitId(),
  3497. subUnitId: this._worksheet.getSheetId(),
  3498. showGridlines: e ? we.FALSE : we.TRUE
  3499. }), this;
  3500. }
  3501. /**
  3502. * Set the color of the gridlines in the sheet.
  3503. * @param {string|undefined} color - The color to set for the gridlines.Undefined or null to reset to the default color.
  3504. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3505. * @example
  3506. * ```ts
  3507. * const fWorkbook = univerAPI.getActiveWorkbook();
  3508. * const fWorkSheet = fWorkbook.getActiveSheet();
  3509. * // set the gridlines color to red
  3510. * fWorkSheet.setGridLinesColor('#ff0000');
  3511. * ```
  3512. */
  3513. setGridLinesColor(e) {
  3514. return this._commandService.syncExecuteCommand(ju.id, {
  3515. unitId: this._workbook.getUnitId(),
  3516. subUnitId: this._worksheet.getSheetId(),
  3517. color: e
  3518. }), this;
  3519. }
  3520. /**
  3521. * Get the color of the gridlines in the sheet.
  3522. * @returns {string | undefined} The color of the gridlines in the sheet or undefined. The default color is 'rgb(214, 216, 219)'.
  3523. * @example
  3524. * ```ts
  3525. * const fWorkbook = univerAPI.getActiveWorkbook();
  3526. * const fWorkSheet = fWorkbook.getActiveSheet();
  3527. * // get the gridlines color of the sheet
  3528. * console.log(fWorkSheet.getGridLinesColor());
  3529. * ```
  3530. */
  3531. getGridLinesColor() {
  3532. return this._worksheet.getGridlinesColor();
  3533. }
  3534. /**
  3535. * Sets the sheet tab color.
  3536. * @param {string|null|undefined} color - A color code in CSS notation (like '#ffffff' or 'white'), or null to reset the tab color.
  3537. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3538. * @example
  3539. * ```ts
  3540. * const fWorkbook = univerAPI.getActiveWorkbook();
  3541. * const fWorkSheet = fWorkbook.getActiveSheet();
  3542. * // set the tab color to red
  3543. * fWorkSheet.setTabColor('#ff0000');
  3544. * ```
  3545. */
  3546. setTabColor(e) {
  3547. return this._commandService.syncExecuteCommand(al2.id, {
  3548. unitId: this._workbook.getUnitId(),
  3549. subUnitId: this._worksheet.getSheetId(),
  3550. color: e
  3551. }), this;
  3552. }
  3553. /**
  3554. * Get the tab color of the sheet.
  3555. * @returns {string} The tab color of the sheet or undefined.
  3556. * The default color is css style property 'unset'.
  3557. * @example
  3558. * ```ts
  3559. * const fWorkbook = univerAPI.getActiveWorkbook();
  3560. * const fWorkSheet = fWorkbook.getActiveSheet();
  3561. * // get the tab color of the sheet
  3562. * console.log(fWorkSheet.getTabColor());
  3563. * ```
  3564. */
  3565. getTabColor() {
  3566. return this._worksheet.getTabColor();
  3567. }
  3568. // eslint-disable-next-line
  3569. /**
  3570. * @deprecated use `univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback)` instead
  3571. */
  3572. onCellDataChange(e) {
  3573. return this._injector.get(Pt).onCommandExecuted((n) => {
  3574. if (n.id === Q.id) {
  3575. const s = n.params;
  3576. s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new kt(s.cellValue));
  3577. }
  3578. });
  3579. }
  3580. // eslint-disable-next-line
  3581. /**
  3582. * @deprecated use `univerAPI.addEvent(univerAPI.Event.SheetValueChanged, callback)` instead
  3583. */
  3584. onBeforeCellDataChange(e) {
  3585. return this._injector.get(Pt).beforeCommandExecuted((n) => {
  3586. if (n.id === Q.id) {
  3587. const s = n.params;
  3588. s.unitId === this._workbook.getUnitId() && s.subUnitId === this._worksheet.getSheetId() && s.cellValue && e(new kt(s.cellValue));
  3589. }
  3590. });
  3591. }
  3592. /**
  3593. * 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.
  3594. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3595. * @example
  3596. * ```ts
  3597. * const fWorkbook = univerAPI.getActiveWorkbook();
  3598. * const fWorkSheet = fWorkbook.getActiveSheet();
  3599. * // hide the active sheet
  3600. * fWorkSheet.hideSheet();
  3601. * ```
  3602. */
  3603. hideSheet() {
  3604. const e = this._injector.get(Pt);
  3605. if (this._workbook.getSheets().filter((i) => i.isSheetHidden() !== we.TRUE).length <= 1)
  3606. throw new Error("Cannot hide the only visible sheet");
  3607. return e.syncExecuteCommand(hl.id, {
  3608. unitId: this._workbook.getUnitId(),
  3609. subUnitId: this._worksheet.getSheetId()
  3610. }), this;
  3611. }
  3612. /**
  3613. * Shows this sheet. Has no effect if the sheet is already visible.
  3614. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3615. * @example
  3616. * ```ts
  3617. * const fWorkbook = univerAPI.getActiveWorkbook();
  3618. * const fWorkSheets = fWorkbook.getSheets();
  3619. * // show the last sheet
  3620. * fWorkSheets[fWorkSheets.length - 1].showSheet();
  3621. * ```
  3622. */
  3623. showSheet() {
  3624. return this._injector.get(Pt).syncExecuteCommand(Fr.id, {
  3625. unitId: this._workbook.getUnitId(),
  3626. subUnitId: this._worksheet.getSheetId()
  3627. }), this;
  3628. }
  3629. /**
  3630. * Returns true if the sheet is currently hidden.
  3631. * @returns {boolean} True if the sheet is hidden; otherwise, false.
  3632. */
  3633. isSheetHidden() {
  3634. return this._worksheet.isSheetHidden() === we.TRUE;
  3635. }
  3636. /**
  3637. * Sets the sheet name.
  3638. * @param {string} name - The new name for the sheet.
  3639. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3640. * @example
  3641. * ```ts
  3642. * const fWorkbook = univerAPI.getActiveWorkbook();
  3643. * const fWorkSheet = fWorkbook.getActiveSheet();
  3644. * // set the sheet name to 'Sheet1'
  3645. * fWorkSheet.setName('Sheet1');
  3646. * ```
  3647. */
  3648. setName(e) {
  3649. return this._commandService.syncExecuteCommand(Do.id, {
  3650. unitId: this._workbook.getUnitId(),
  3651. subUnitId: this._worksheet.getSheetId(),
  3652. name: e
  3653. }), this;
  3654. }
  3655. /**
  3656. * Activates this sheet. Does not alter the sheet itself, only the parent's notion of the active sheet.
  3657. * @returns {FWorksheet} Current sheet, for chaining.
  3658. */
  3659. activate() {
  3660. return this._fWorkbook.setActiveSheet(this), this;
  3661. }
  3662. /**
  3663. * Gets the position of the sheet in its parent spreadsheet. Starts at 0.
  3664. * @returns {number} The position of the sheet in its parent spreadsheet.
  3665. * @example
  3666. * ```ts
  3667. * const fWorkbook = univerAPI.getActiveWorkbook();
  3668. * const fWorkSheet = fWorkbook.getActiveSheet();
  3669. * // get the position of the active sheet
  3670. * const position = fWorkSheet.getIndex();
  3671. * console.log(position); // 0
  3672. * ```
  3673. */
  3674. getIndex() {
  3675. return this._workbook.getSheetIndex(this._worksheet);
  3676. }
  3677. /**
  3678. * Clears the sheet of content and formatting information.Or Optionally clears only the contents or only the formatting.
  3679. * @param {IFacadeClearOptions} [options] - Options for clearing the sheet. If not provided, the contents and formatting are cleared both.
  3680. * @param {boolean} [options.contentsOnly] - If true, the contents of the sheet are cleared. If false, the contents and formatting are cleared. Default is false.
  3681. * @param {boolean} [options.formatOnly] - If true, the formatting of the sheet is cleared. If false, the contents and formatting are cleared. Default is false.
  3682. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3683. * @example
  3684. * ```ts
  3685. * const fWorkbook = univerAPI.getActiveWorkbook();
  3686. * const fWorkSheet = fWorkbook.getActiveSheet();
  3687. * // clear the sheet of content and formatting information
  3688. * fWorkSheet.clear();
  3689. * // clear the sheet of content only
  3690. * fWorkSheet.clear({ contentsOnly: true });
  3691. * ```
  3692. */
  3693. clear(e) {
  3694. e && e.contentsOnly && !e.formatOnly && this.clearContents(), e && e.formatOnly && !e.contentsOnly && this.clearFormats();
  3695. const t = this._workbook.getUnitId(), n = this._worksheet.getSheetId(), s = this._injector.get(Pt), i = {
  3696. startRow: 0,
  3697. endRow: this._worksheet.getRowCount() - 1,
  3698. startColumn: 0,
  3699. endColumn: this._worksheet.getColumnCount() - 1
  3700. };
  3701. return s.syncExecuteCommand(po.id, {
  3702. unitId: t,
  3703. subUnitId: n,
  3704. ranges: [i],
  3705. options: e
  3706. }), this;
  3707. }
  3708. /**
  3709. * Clears the sheet of contents, while preserving formatting information.
  3710. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3711. * @example
  3712. * ```typescript
  3713. * const fWorkbook = univerAPI.getActiveWorkbook();
  3714. * const fWorkSheet = fWorkbook.getActiveSheet();
  3715. * // clear the sheet of content only
  3716. * fWorkSheet.clearContents();
  3717. * ```
  3718. */
  3719. clearContents() {
  3720. const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(Pt), s = {
  3721. startRow: 0,
  3722. endRow: this._worksheet.getRowCount() - 1,
  3723. startColumn: 0,
  3724. endColumn: this._worksheet.getColumnCount() - 1
  3725. };
  3726. return n.syncExecuteCommand(Co.id, {
  3727. unitId: e,
  3728. subUnitId: t,
  3729. ranges: [s]
  3730. }), this;
  3731. }
  3732. /**
  3733. * Clears the sheet of formatting, while preserving contents.
  3734. * @returns {FWorksheet} Returns the current worksheet instance for method chaining
  3735. * @example
  3736. * ```typescript
  3737. * const fWorkbook = univerAPI.getActiveWorkbook();
  3738. * const fWorkSheet = fWorkbook.getActiveSheet();
  3739. * // clear the sheet of formatting only
  3740. * fWorkSheet.clearFormats();
  3741. * ```
  3742. */
  3743. clearFormats() {
  3744. const e = this._workbook.getUnitId(), t = this._worksheet.getSheetId(), n = this._injector.get(Pt), s = {
  3745. startRow: 0,
  3746. endRow: this._worksheet.getRowCount() - 1,
  3747. startColumn: 0,
  3748. endColumn: this._worksheet.getColumnCount() - 1
  3749. };
  3750. return n.syncExecuteCommand(So.id, {
  3751. unitId: e,
  3752. subUnitId: t,
  3753. ranges: [s]
  3754. }), this;
  3755. }
  3756. /**
  3757. * Returns a Range corresponding to the dimensions in which data is present.
  3758. * This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).
  3759. * @returns {FRange} The range of the data in the sheet.
  3760. * @example
  3761. * ```ts
  3762. * const fWorkbook = univerAPI.getActiveWorkbook();
  3763. * const fWorkSheet = fWorkbook.getActiveSheet();
  3764. * // the sheet is a empty sheet
  3765. * const cellRange = fWorkSheet.getRange(200, 10, 1, 1);
  3766. * cellRange.setValue('Hello World');
  3767. * console.log(fWorkSheet.getDataRange().getA1Notation()); // A1:J200
  3768. * ```
  3769. */
  3770. getDataRange() {
  3771. const e = this.getLastRows(), t = this.getLastColumns();
  3772. return this.getRange(0, 0, e + 1, t + 1);
  3773. }
  3774. /**
  3775. * Returns the position of the last column that has content.
  3776. * @returns {number} the last column of the sheet that contains content.
  3777. * @example
  3778. * ```ts
  3779. * const fWorkbook = univerAPI.getActiveWorkbook();
  3780. * const fWorkSheet = fWorkbook.getActiveSheet();
  3781. * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
  3782. * console.log(fWorkSheet.getLastColumns()); // 20
  3783. * ```
  3784. */
  3785. getLastColumns() {
  3786. return this._worksheet.getLastColumnWithContent();
  3787. }
  3788. /**
  3789. * @deprecated use getLastColumn instead.
  3790. * Returns the position of the last column that has content. Same as getLastColumns.
  3791. * @returns {number} the last column of the sheet that contains content.
  3792. * @example
  3793. * ```ts
  3794. * const fWorkbook = univerAPI.getActiveWorkbook();
  3795. * const fWorkSheet = fWorkbook.getActiveSheet();
  3796. * const fRange = fWorkSheet.getRange(100, 20, 1, 1);
  3797. * console.log(fWorkSheet.getLastColumn());
  3798. * ```
  3799. */
  3800. getLastColumn() {
  3801. return this._worksheet.getLastColumnWithContent();
  3802. }
  3803. /**
  3804. * @deprecated use getLastRow instead.
  3805. * Returns the position of the last row that has content.
  3806. * @returns {number} the last row of the sheet that contains content.
  3807. * @example
  3808. * ```ts
  3809. * const fWorkbook = univerAPI.getActiveWorkbook();
  3810. * const fWorkSheet = fWorkbook.getActiveSheet();
  3811. * const fRange = fWorkSheet.getRange(100,1,1,1);
  3812. * fRange.setValue('Hello World');
  3813. * console.log(fWorkSheet.getLastRows()); // 100
  3814. */
  3815. getLastRows() {
  3816. return this._worksheet.getLastRowWithContent();
  3817. }
  3818. /**
  3819. * Returns the position of the last row that has content, same as getLastRows().
  3820. * @returns {number} the last row of the sheet that contains content.
  3821. * @example
  3822. * ```ts
  3823. * const fWorkbook = univerAPI.getActiveWorkbook();
  3824. * const fWorkSheet = fWorkbook.getActiveSheet();
  3825. * const fRange = fWorkSheet.getRange(100,1,1,1);
  3826. * fRange.setValue('Hello World');
  3827. * console.log(fWorkSheet.getLastRow());
  3828. */
  3829. getLastRow() {
  3830. return this._worksheet.getLastRowWithContent();
  3831. }
  3832. /**
  3833. * Judge whether provided FWorksheet is equal to current.
  3834. * @param {FWorksheet} other - the FWorksheet to compare with.
  3835. * @returns {boolean} true if the FWorksheet is equal to the current FWorksheet, false otherwise.
  3836. * @example
  3837. * ```ts
  3838. * const fWorkbook = univerAPI.getActiveWorkbook();
  3839. * const fWorkSheet = fWorkbook.getActiveSheet();
  3840. * const fWorkSheet2 = fWorkbook.getSheetByName('Sheet1');
  3841. * console.log(fWorkSheet.equals(fWorkSheet2)); // true, if the active sheet is 'Sheet1'
  3842. * ```
  3843. */
  3844. equalTo(e) {
  3845. return e instanceof m ? this._worksheet.getSheetId() === e.getSheetId() && this._workbook.getUnitId() === e.getWorkbook().getUnitId() : false;
  3846. }
  3847. /*
  3848. * Insert a defined name for worksheet.
  3849. * @param {string} name - The name of the defined name to insert
  3850. * @param {string} formulaOrRefString - The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
  3851. * @example
  3852. * ```ts
  3853. * // The code below inserts a defined name
  3854. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  3855. * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
  3856. * sheet1.insertDefinedName('MyDefinedName', 'Sheet1!A1');
  3857. * ```
  3858. */
  3859. insertDefinedName(e, t) {
  3860. const s = this._injector.createInstance(V).setName(e).setRef(t).build();
  3861. s.localSheetId = this.getSheetId(), this._fWorkbook.insertDefinedNameBuilder(s);
  3862. }
  3863. /**
  3864. * Get all the defined names in the worksheet.
  3865. * @returns {FDefinedName[]} All the defined names in the worksheet
  3866. * @example
  3867. * ```ts
  3868. * // The code below gets all the defined names in the worksheet
  3869. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  3870. * const sheet1 = activeSpreadsheet.getSheetByName('Sheet1');
  3871. * const definedNames = sheet1.getDefinedNames();
  3872. * ```
  3873. */
  3874. getDefinedNames() {
  3875. return this._fWorkbook.getDefinedNames().filter((t) => t.getLocalSheetId() === this.getSheetId());
  3876. }
  3877. /**
  3878. * Set custom metadata of worksheet
  3879. * @param {CustomData | undefined} custom - custom metadata
  3880. * @returns {FWorksheet}
  3881. * @example
  3882. * ```ts
  3883. * const fWorkbook = univerAPI.getActiveWorkbook();
  3884. * const fWorkSheet = fWorkbook.getActiveSheet();
  3885. * fWorkSheet.setCustomMetadata({ key: 'value' });
  3886. * ```
  3887. */
  3888. setCustomMetadata(e) {
  3889. return this._worksheet.setCustomMetadata(e), this;
  3890. }
  3891. /**
  3892. * Set custom metadata of row
  3893. * @param {number} index - row index
  3894. * @param {CustomData | undefined} custom - custom metadata
  3895. * @returns {FWorksheet} Current worksheet, for chaining.
  3896. * @example
  3897. * ```ts
  3898. * const fWorkbook = univerAPI.getActiveWorkbook();
  3899. * const fWorkSheet = fWorkbook.getActiveSheet();
  3900. * fWorkSheet.setRowCustomMetadata(0, { key: 'value' });
  3901. * ```
  3902. */
  3903. setRowCustomMetadata(e, t) {
  3904. return this._worksheet.getRowManager().setCustomMetadata(e, t), this;
  3905. }
  3906. /**
  3907. * Set custom metadata of column
  3908. * @param {number} index - column index
  3909. * @param {CustomData | undefined} custom - custom metadata
  3910. * @returns {FWorksheet} Current worksheet, for chaining.
  3911. * @example
  3912. * ```ts
  3913. * const fWorkbook = univerAPI.getActiveWorkbook();
  3914. * const fWorkSheet = fWorkbook.getActiveSheet();
  3915. * fWorkSheet.setColumnCustomMetadata(0, { key: 'value' });
  3916. * ```
  3917. */
  3918. setColumnCustomMetadata(e, t) {
  3919. return this._worksheet.getColumnManager().setCustomMetadata(e, t), this;
  3920. }
  3921. /**
  3922. * Get custom metadata of row
  3923. * @param {number} index - row index
  3924. * @returns {CustomData | undefined} custom metadata
  3925. * @example
  3926. * ```ts
  3927. * const fWorkbook = univerAPI.getActiveWorkbook();
  3928. * const fWorkSheet = fWorkbook.getActiveSheet();
  3929. * const custom = fWorkSheet.getRowCustomMetadata(0);
  3930. * ```
  3931. */
  3932. getRowCustomMetadata(e) {
  3933. return this._worksheet.getRowManager().getCustomMetadata(e);
  3934. }
  3935. /**
  3936. * Get custom metadata of column
  3937. * @param {number} index - column index
  3938. * @returns {CustomData | undefined} custom metadata
  3939. * @example
  3940. * ```ts
  3941. * const fWorkbook = univerAPI.getActiveWorkbook();
  3942. * const fWorkSheet = fWorkbook.getActiveSheet();
  3943. * const custom = fWorkSheet.getColumnCustomMetadata(0);
  3944. * ```
  3945. */
  3946. getColumnCustomMetadata(e) {
  3947. return this._worksheet.getColumnManager().getCustomMetadata(e);
  3948. }
  3949. /**
  3950. * Get all merged cells in the current worksheet
  3951. * @returns {FRange[]} All the merged cells in the worksheet
  3952. * @example
  3953. * ```ts
  3954. * const workbook = univerAPI.getActiveWorkbook();
  3955. * const worksheet = workbook.getActiveSheet();
  3956. * const rangeFirst = worksheet.getRange(0, 0, 2, 2);
  3957. * const mergeFirst = rangeFirst.merge();
  3958. * const rangeSecond = worksheet.getRange(5, 0, 2, 2);
  3959. * const mergeSecond = rangeSecond.merge();
  3960. * const mergeData = worksheet.getMergeData();
  3961. * console.log('debugger', mergeData);
  3962. * ```
  3963. */
  3964. getMergeData() {
  3965. return this._worksheet.getMergeData().map((e) => this._injector.createInstance(S, this._workbook, this._worksheet, e));
  3966. }
  3967. };
  3968. m = gn([
  3969. B(3, ot(Ot)),
  3970. B(4, ot(F)),
  3971. B(5, ot(Mt)),
  3972. B(6, Pt)
  3973. ], m);
  3974. var ln = Object.defineProperty;
  3975. var mn = Object.getOwnPropertyDescriptor;
  3976. var _n2 = (r, e, t, n) => {
  3977. for (var s = n > 1 ? void 0 : n ? mn(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  3978. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  3979. return n && s && ln(e, t, s), s;
  3980. };
  3981. var C = (r, e) => (t, n) => e(t, n, r);
  3982. var f = class extends al {
  3983. constructor(e, t, n, s, i, o, h, a, d, c) {
  3984. super(t);
  3985. b(this, "id");
  3986. 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();
  3987. }
  3988. /**
  3989. * Get the Workbook instance.
  3990. * @returns {Workbook} The Workbook instance.
  3991. * @example
  3992. * ```ts
  3993. * // The code below gets the Workbook instance
  3994. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  3995. * const workbook = activeSpreadsheet.getWorkbook();
  3996. * ```
  3997. */
  3998. getWorkbook() {
  3999. return this._workbook;
  4000. }
  4001. /**
  4002. * Get the id of the workbook.
  4003. * @returns {string} The id of the workbook.
  4004. * @example
  4005. * ```ts
  4006. * // The code below gets the id of the workbook
  4007. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4008. * const id = activeSpreadsheet.getId();
  4009. * ```
  4010. */
  4011. getId() {
  4012. return this.id;
  4013. }
  4014. /**
  4015. * Get the name of the workbook.
  4016. * @returns {string} The name of the workbook.
  4017. * @example
  4018. * ```ts
  4019. * // The code below gets the name of the workbook
  4020. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4021. * const name = activeSpreadsheet.getName();
  4022. * ```
  4023. */
  4024. getName() {
  4025. return this._workbook.name;
  4026. }
  4027. /**
  4028. * Set the name of the workbook.
  4029. * @param {string} name The new name of the workbook.
  4030. * @returns {void}
  4031. * @example
  4032. * ```ts
  4033. * // The code below sets the name of the workbook
  4034. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4035. * activeSpreadsheet.setName('MyWorkbook');
  4036. * ```
  4037. */
  4038. setName(e) {
  4039. this._workbook.setName(e);
  4040. }
  4041. /**
  4042. * Save workbook snapshot data, including conditional formatting, data validation, and other plugin data.
  4043. * @returns {IWorkbookData} Workbook snapshot data
  4044. * @example
  4045. * ```ts
  4046. * // The code below saves the workbook snapshot data
  4047. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4048. * const snapshot = activeSpreadsheet.save();
  4049. * ```
  4050. */
  4051. save() {
  4052. return this._resourceLoaderService.saveUnit(this._workbook.getUnitId());
  4053. }
  4054. /**
  4055. * @deprecated use 'save' instead.
  4056. * @returns {IWorkbookData} Workbook snapshot data
  4057. * @memberof FWorkbook
  4058. * @example
  4059. * ```ts
  4060. * // The code below saves the workbook snapshot data
  4061. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4062. * const snapshot = activeSpreadsheet.getSnapshot();
  4063. * ```
  4064. */
  4065. getSnapshot() {
  4066. return this._logService.warn("use 'save' instead of 'getSnapshot'"), this.save();
  4067. }
  4068. /**
  4069. * Get the active sheet of the workbook.
  4070. * @returns {FWorksheet} The active sheet of the workbook
  4071. * @example
  4072. * ```ts
  4073. * // The code below gets the active sheet of the workbook
  4074. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4075. * const activeSheet = activeSpreadsheet.getActiveSheet();
  4076. * ```
  4077. */
  4078. getActiveSheet() {
  4079. const e = this._workbook.getActiveSheet();
  4080. return this._injector.createInstance(m, this, this._workbook, e);
  4081. }
  4082. /**
  4083. * Gets all the worksheets in this workbook
  4084. * @returns {FWorksheet[]} An array of all the worksheets in the workbook
  4085. * @example
  4086. * ```ts
  4087. * // The code below gets all the worksheets in the workbook
  4088. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4089. * const sheets = activeSpreadsheet.getSheets();
  4090. * ```
  4091. */
  4092. getSheets() {
  4093. return this._workbook.getSheets().map((e) => this._injector.createInstance(m, this, this._workbook, e));
  4094. }
  4095. /**
  4096. * Create a new worksheet and returns a handle to it.
  4097. * @param {string} name Name of the new sheet
  4098. * @param {number} rows How many rows would the new sheet have
  4099. * @param {number} column How many columns would the new sheet have
  4100. * @returns {FWorksheet} The new created sheet
  4101. * @example
  4102. * ```ts
  4103. * // The code below creates a new sheet
  4104. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4105. * const newSheet = activeSpreadsheet.create('MyNewSheet', 10, 10);
  4106. * ```
  4107. */
  4108. create(e, t, n) {
  4109. const s = Q_({});
  4110. s.rowCount = t, s.columnCount = n, s.name = e, s.id = e.toLowerCase().replace(/ /g, "-"), this._commandService.syncExecuteCommand(fu.id, {
  4111. unitId: this.id,
  4112. index: this._workbook.getSheets().length,
  4113. sheet: s
  4114. }), this._commandService.syncExecuteCommand(an.id, {
  4115. unitId: this.id,
  4116. subUnitId: this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId()
  4117. });
  4118. const i = this._workbook.getActiveSheet();
  4119. if (!i)
  4120. throw new Error("No active sheet found");
  4121. return this._injector.createInstance(m, this, this._workbook, i);
  4122. }
  4123. /**
  4124. * Get a worksheet by sheet id.
  4125. * @param {string} sheetId The id of the sheet to get.
  4126. * @returns {FWorksheet | null} The worksheet with given sheet id
  4127. * @example
  4128. * ```ts
  4129. * // The code below gets a worksheet by sheet id
  4130. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4131. * const sheet = activeSpreadsheet.getSheetBySheetId('sheetId');
  4132. * ```
  4133. */
  4134. getSheetBySheetId(e) {
  4135. const t = this._workbook.getSheetBySheetId(e);
  4136. return t ? this._injector.createInstance(m, this, this._workbook, t) : null;
  4137. }
  4138. /**
  4139. * Get a worksheet by sheet name.
  4140. * @param {string} name The name of the sheet to get.
  4141. * @returns {FWorksheet | null} The worksheet with given sheet name
  4142. * @example
  4143. * ```ts
  4144. * // The code below gets a worksheet by sheet name
  4145. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4146. * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
  4147. * ```
  4148. */
  4149. getSheetByName(e) {
  4150. const t = this._workbook.getSheetBySheetName(e);
  4151. return t ? this._injector.createInstance(m, this, this._workbook, t) : null;
  4152. }
  4153. /**
  4154. * Sets the given worksheet to be the active worksheet in the workbook.
  4155. * @param {FWorksheet | string} sheet The worksheet to set as the active worksheet.
  4156. * @returns {FWorksheet} The active worksheet
  4157. * @example
  4158. * ```ts
  4159. * // The code below sets the given worksheet to be the active worksheet
  4160. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4161. * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
  4162. * activeSpreadsheet.setActiveSheet(sheet);
  4163. * ```
  4164. */
  4165. setActiveSheet(e) {
  4166. return this._commandService.syncExecuteCommand(an.id, {
  4167. unitId: this.id,
  4168. subUnitId: typeof e == "string" ? e : e.getSheetId()
  4169. }), typeof e == "string" ? this.getSheetBySheetId(e) : e;
  4170. }
  4171. /**
  4172. * Inserts a new worksheet into the workbook.
  4173. * Using a default sheet name. The new sheet becomes the active sheet
  4174. * @param {string} [sheetName] The name of the new sheet
  4175. * @returns {FWorksheet} The new sheet
  4176. * @example
  4177. * ```ts
  4178. * // The code below inserts a new sheet into the workbook
  4179. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4180. * activeSpreadsheet.insertSheet();
  4181. *
  4182. * // The code below inserts a new sheet into the workbook, using a custom name
  4183. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4184. * activeSpreadsheet.insertSheet('MyNewSheet');
  4185. * ```
  4186. */
  4187. insertSheet(e) {
  4188. e != null ? this._commandService.syncExecuteCommand(fu.id, { sheet: { name: e } }) : this._commandService.syncExecuteCommand(fu.id);
  4189. const t = this.id, n = this._workbook.getSheets()[this._workbook.getSheets().length - 1].getSheetId();
  4190. this._commandService.syncExecuteCommand(an.id, {
  4191. unitId: t,
  4192. subUnitId: n
  4193. });
  4194. const s = this._workbook.getActiveSheet();
  4195. if (!s)
  4196. throw new Error("No active sheet found");
  4197. return this._injector.createInstance(m, this, this._workbook, s);
  4198. }
  4199. /**
  4200. * Deletes the specified worksheet.
  4201. * @param {FWorksheet | string} sheet The worksheet to delete.
  4202. * @returns {boolean} True if the worksheet was deleted, false otherwise.
  4203. * @example
  4204. * ```ts
  4205. * // The code below deletes the specified worksheet
  4206. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4207. * const sheet = activeSpreadsheet.getSheetByName('Sheet1');
  4208. * activeSpreadsheet.deleteSheet(sheet);
  4209. * ```
  4210. */
  4211. deleteSheet(e) {
  4212. const t = this.id, n = typeof e == "string" ? e : e.getSheetId();
  4213. return this._commandService.syncExecuteCommand(ko.id, {
  4214. unitId: t,
  4215. subUnitId: n
  4216. });
  4217. }
  4218. // #region editing
  4219. /**
  4220. * Undo the last action.
  4221. * @returns {FWorkbook} A promise that resolves to true if the undo was successful, false otherwise.
  4222. * @example
  4223. * ```ts
  4224. * // The code below undoes the last action
  4225. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4226. * activeSpreadsheet.undo();
  4227. * ```
  4228. */
  4229. undo() {
  4230. return this._univerInstanceService.focusUnit(this.id), this._commandService.syncExecuteCommand(Nn.id), this;
  4231. }
  4232. /**
  4233. * Redo the last undone action.
  4234. * @returns {FWorkbook} A promise that resolves to true if the redo was successful, false otherwise.
  4235. * @example
  4236. * ```ts
  4237. * // The code below redoes the last undone action
  4238. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4239. * activeSpreadsheet.redo();
  4240. * ```
  4241. */
  4242. redo() {
  4243. return this._univerInstanceService.focusUnit(this.id), this._commandService.syncExecuteCommand(Tn.id), this;
  4244. }
  4245. /**
  4246. * Callback for command execution.
  4247. * @callback onBeforeCommandExecuteCallback
  4248. * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed.
  4249. */
  4250. /**
  4251. * Register a callback that will be triggered before invoking a command targeting the Univer sheet.
  4252. * @param {onBeforeCommandExecuteCallback} callback the callback.
  4253. * @returns {IDisposable} A function to dispose the listening.
  4254. * @example
  4255. * ```ts
  4256. * // The code below registers a callback that will be triggered before invoking a command targeting the Univer sheet
  4257. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4258. * activeSpreadsheet.onBeforeCommandExecute((command) => {
  4259. * console.log('Command executed:', command);
  4260. * });
  4261. * ```
  4262. */
  4263. onBeforeCommandExecute(e) {
  4264. return this._commandService.beforeCommandExecuted((t) => {
  4265. var n;
  4266. ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
  4267. });
  4268. }
  4269. /**
  4270. * Callback for command execution.
  4271. * @callback onCommandExecutedCallback
  4272. * @param {ICommandInfo<ISheetCommandSharedParams>} command The command that was executed
  4273. */
  4274. /**
  4275. * Register a callback that will be triggered when a command is invoked targeting the Univer sheet.
  4276. * @param {onCommandExecutedCallback} callback the callback.
  4277. * @returns {IDisposable} A function to dispose the listening.
  4278. * @example
  4279. * ```ts
  4280. * // The code below registers a callback that will be triggered when a command is invoked targeting the Univer sheet
  4281. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4282. * activeSpreadsheet.onCommandExecuted((command) => {
  4283. * console.log('Command executed:', command);
  4284. * });
  4285. * ```
  4286. */
  4287. onCommandExecuted(e) {
  4288. return this._commandService.onCommandExecuted((t) => {
  4289. var n;
  4290. ((n = t.params) == null ? void 0 : n.unitId) === this.id && e(t);
  4291. });
  4292. }
  4293. /**
  4294. * Callback for selection changes.
  4295. * @callback onSelectionChangeCallback
  4296. * @param {IRange[]} selections The new selection.
  4297. */
  4298. /**
  4299. * Register a callback that will be triggered when the selection changes.
  4300. * @param {onSelectionChangeCallback} callback The callback.
  4301. * @returns {IDisposable} A function to dispose the listening
  4302. */
  4303. onSelectionChange(e) {
  4304. return Ze(
  4305. this._selectionManagerService.selectionMoveEnd$.subscribe((t) => {
  4306. this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET).getUnitId() === this.id && (t != null && t.length ? e(t.map((n) => n.range)) : e([]));
  4307. })
  4308. );
  4309. }
  4310. /**
  4311. * Used to modify the editing permissions of the workbook. When the value is false, editing is not allowed.
  4312. * @param {boolean} value editable value want to set
  4313. * @returns {FWorkbook} FWorkbook instance
  4314. */
  4315. setEditable(e) {
  4316. const t = new Me(this._workbook.getUnitId());
  4317. return this._permissionService.getPermissionPoint(t.id) || this._permissionService.addPermissionPoint(t), this._permissionService.updatePermissionPoint(t.id, e), this;
  4318. }
  4319. /**
  4320. * Sets the selection region for active sheet.
  4321. * @param {FRange} range The range to set as the active selection.
  4322. * @returns {FWorkbook} FWorkbook instance
  4323. */
  4324. setActiveRange(e) {
  4325. const t = this.getActiveSheet(), n = e.getRange().sheetId || t.getSheetId(), s = n ? this._workbook.getSheetBySheetId(n) : this._workbook.getActiveSheet(true);
  4326. if (!s)
  4327. throw new Error("No active sheet found");
  4328. s.getSheetId() !== t.getSheetId() && this.setActiveSheet(this._injector.createInstance(m, this, this._workbook, s));
  4329. const i = {
  4330. unitId: this.getId(),
  4331. subUnitId: n,
  4332. selections: [e].map((o) => ({ range: o.getRange(), primary: ve(o.getRange(), s), style: null }))
  4333. };
  4334. return this._commandService.syncExecuteCommand(re2.id, i), this;
  4335. }
  4336. /**
  4337. * Returns the selected range in the active sheet, or null if there is no active range.
  4338. * @returns {FRange | null} The active range
  4339. */
  4340. // could sheet have no active range ?
  4341. getActiveRange() {
  4342. const e = this._workbook.getActiveSheet(), n = this._selectionManagerService.getCurrentSelections().find((s) => !!s.primary);
  4343. return n ? this._injector.createInstance(S, this._workbook, e, n.range) : null;
  4344. }
  4345. /**
  4346. * Deletes the currently active sheet.
  4347. * @returns {boolean} true if the sheet was deleted, false otherwise
  4348. * @example
  4349. * ```ts
  4350. * // The code below deletes the currently active sheet and stores the new active
  4351. * // sheet in a variable
  4352. * const sheet = univerAPI.getActiveWorkbook().deleteActiveSheet();
  4353. * ```
  4354. */
  4355. deleteActiveSheet() {
  4356. const e = this.getActiveSheet();
  4357. return this.deleteSheet(e);
  4358. }
  4359. /**
  4360. * Duplicates the given worksheet.
  4361. * @param {FWorksheet} sheet The worksheet to duplicate.
  4362. * @returns {FWorksheet} The duplicated worksheet
  4363. * @example
  4364. * ```ts
  4365. * // The code below duplicates the given worksheet
  4366. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4367. * const activeSheet = activeSpreadsheet.getActiveSheet();
  4368. * activeSpreadsheet.duplicateSheet(activeSheet);
  4369. * ```
  4370. */
  4371. duplicateSheet(e) {
  4372. return this._commandService.syncExecuteCommand(xs.id, {
  4373. unitId: e.getWorkbook().getUnitId(),
  4374. subUnitId: e.getSheetId()
  4375. }), this._injector.createInstance(m, this, this._workbook, this._workbook.getActiveSheet());
  4376. }
  4377. /**
  4378. * Duplicates the active sheet.
  4379. * @returns {FWorksheet} The duplicated worksheet
  4380. * @example
  4381. * ```ts
  4382. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4383. * activeSpreadsheet.duplicateActiveSheet();
  4384. * ```
  4385. */
  4386. duplicateActiveSheet() {
  4387. const e = this.getActiveSheet();
  4388. return this.duplicateSheet(e);
  4389. }
  4390. /**
  4391. * Get the number of sheets in the workbook.
  4392. * @returns {number} The number of sheets in the workbook
  4393. * @example
  4394. * ```ts
  4395. * // The code below gets the number of sheets in the workbook
  4396. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4397. * const numSheets = activeSpreadsheet.getNumSheets();
  4398. * ```
  4399. */
  4400. getNumSheets() {
  4401. return this._workbook.getSheets().length;
  4402. }
  4403. /**
  4404. * Get the locale of the workbook.
  4405. * @returns {LocaleType} The locale of the workbook
  4406. * @example
  4407. * ```ts
  4408. * // The code below gets the locale of the workbook
  4409. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4410. * const locale = activeSpreadsheet.getLocale();
  4411. * ```
  4412. */
  4413. getLocale() {
  4414. return this._localeService.getCurrentLocale();
  4415. }
  4416. /**
  4417. * @deprecated use setSpreadsheetLocale instead.
  4418. * @param {LocaleType} locale - The locale to set
  4419. */
  4420. setLocale(e) {
  4421. this._localeService.setLocale(e);
  4422. }
  4423. /**
  4424. * Set the locale of the workbook.
  4425. * @param {LocaleType} locale The locale to set
  4426. * @returns {FWorkbook} This workbook, for chaining
  4427. * @example
  4428. * ```ts
  4429. * // The code below sets the locale of the workbook
  4430. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4431. * activeSpreadsheet.setLocale(LocaleType.EN_US);
  4432. * ```
  4433. */
  4434. setSpreadsheetLocale(e) {
  4435. return this._localeService.setLocale(e), this;
  4436. }
  4437. /**
  4438. * Get the URL of the workbook.
  4439. * @returns {string} The URL of the workbook
  4440. * @example
  4441. * ```ts
  4442. * // The code below gets the URL of the workbook
  4443. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4444. * const url = activeSpreadsheet.getUrl();
  4445. * ```
  4446. */
  4447. getUrl() {
  4448. return location.href;
  4449. }
  4450. /**
  4451. * Move the sheet to the specified index.
  4452. * @param {FWorksheet} sheet The sheet to move
  4453. * @param {number} index The index to move the sheet to
  4454. * @returns {FWorkbook} This workbook, for chaining
  4455. * @example
  4456. * ```ts
  4457. * // The code below moves the sheet to the specified index
  4458. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4459. * const sheet = activeSpreadsheet.getActiveSheet();
  4460. * activeSpreadsheet.moveSheet(sheet, 1);
  4461. * ```
  4462. */
  4463. moveSheet(e, t) {
  4464. let n = t;
  4465. return n < 0 ? n = 0 : n > this._workbook.getSheets().length - 1 && (n = this._workbook.getSheets().length - 1), this._commandService.syncExecuteCommand(Wr.id, {
  4466. unitId: e.getWorkbook().getUnitId(),
  4467. order: n,
  4468. subUnitId: e.getSheetId()
  4469. }), this;
  4470. }
  4471. /**
  4472. * Move the active sheet to the specified index.
  4473. * @param {number} index The index to move the active sheet to
  4474. * @returns {FWorkbook} This workbook, for chaining
  4475. * @example
  4476. * ```ts
  4477. * // The code below moves the active sheet to the specified index
  4478. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4479. * activeSpreadsheet.moveActiveSheet(1);
  4480. * ```
  4481. */
  4482. moveActiveSheet(e) {
  4483. const t = this.getActiveSheet();
  4484. return this.moveSheet(t, e);
  4485. }
  4486. /**
  4487. * Get the PermissionInstance.
  4488. * @returns {FPermission} - The PermissionInstance.
  4489. */
  4490. getPermission() {
  4491. return this._injector.createInstance(j);
  4492. }
  4493. /**
  4494. * Get the defined name by name.
  4495. * @param {string} name The name of the defined name to get
  4496. * @returns {FDefinedName | null} The defined name with the given name
  4497. * @example
  4498. * ```ts
  4499. * // The code below gets the defined name by name
  4500. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4501. * const definedName = activeSpreadsheet.getDefinedName('MyDefinedName');
  4502. * ```
  4503. */
  4504. getDefinedName(e) {
  4505. const t = this._definedNamesService.getValueByName(this.id, e);
  4506. return t ? this._injector.createInstance(F2, { ...t, unitId: this.id }) : null;
  4507. }
  4508. /**
  4509. * Get all the defined names in the workbook.
  4510. * @returns {FDefinedName[]} All the defined names in the workbook
  4511. * @example
  4512. * ```ts
  4513. * // The code below gets all the defined names in the workbook
  4514. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4515. * const definedNames = activeSpreadsheet.getDefinedNames();
  4516. * ```
  4517. */
  4518. getDefinedNames() {
  4519. const e = this._definedNamesService.getDefinedNameMap(this.id);
  4520. return e ? Object.values(e).map((t) => this._injector.createInstance(F2, { ...t, unitId: this.id })) : [];
  4521. }
  4522. /**
  4523. * Insert a defined name.
  4524. * @param {string} name The name of the defined name to insert
  4525. * @param {string} formulaOrRefString The formula(=sum(A2:b10)) or reference(A1) string of the defined name to insert
  4526. * @returns {FWorkbook} The current FWorkbook instance
  4527. * @example
  4528. * ```ts
  4529. * // The code below inserts a defined name
  4530. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4531. * activeSpreadsheet.insertDefinedName('MyDefinedName', 'Sheet1!A1');
  4532. * ```
  4533. */
  4534. insertDefinedName(e, t) {
  4535. const s = this._injector.createInstance(V).setName(e).setRef(t).build();
  4536. return s.localSheetId = ch, this.insertDefinedNameBuilder(s), this;
  4537. }
  4538. /**
  4539. * Delete the defined name with the given name.
  4540. * @param {string} name The name of the defined name to delete
  4541. * @returns {boolean} true if the defined name was deleted, false otherwise
  4542. * @example
  4543. * ```ts
  4544. * // The code below deletes the defined name with the given name
  4545. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4546. * const deleted = activeSpreadsheet.deleteDefinedName('MyDefinedName');
  4547. * ```
  4548. */
  4549. deleteDefinedName(e) {
  4550. const t = this.getDefinedName(e);
  4551. return t ? (t.delete(), true) : false;
  4552. }
  4553. /**
  4554. * Insert a defined name by builder param.
  4555. * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
  4556. * @returns {void}
  4557. * @example
  4558. * ```ts
  4559. * // The code below inserts a defined name by builder param
  4560. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4561. * const builder = univerAPI.newDefinedName();
  4562. * const param = builder.setName('MyDefinedName').setRef('Sheet1!A1').build();
  4563. * activeSpreadsheet.insertDefinedNameBuilder(param);
  4564. * ```
  4565. */
  4566. insertDefinedNameBuilder(e) {
  4567. e.unitId = this.getId(), this._commandService.syncExecuteCommand(Ur.id, e);
  4568. }
  4569. /**
  4570. * Update the defined name with the given name.
  4571. * @param {ISetDefinedNameMutationParam} param The param to insert the defined name
  4572. * @returns {void}
  4573. * @example
  4574. * ```ts
  4575. * // The code below updates the defined name with the given name
  4576. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4577. * const builder = activeSpreadsheet.getDefinedName('MyDefinedName').toBuilder();
  4578. * builder.setRef('Sheet1!A2').setName('MyDefinedName1').build();
  4579. * activeSpreadsheet.updateDefinedNameBuilder(param);
  4580. * ```
  4581. */
  4582. updateDefinedNameBuilder(e) {
  4583. this._commandService.syncExecuteCommand(Ur.id, e);
  4584. }
  4585. /**
  4586. * Gets the registered range themes.
  4587. * @returns {string[]} The name list of registered range themes.
  4588. * @example
  4589. * ```ts
  4590. * // The code below gets the registered range themes
  4591. * const activeSpreadsheet = univerAPI.getActiveWorkbook();
  4592. * const themes = activeSpreadsheet.getRegisteredRangeThemes();
  4593. * console.log(themes);
  4594. * ```
  4595. */
  4596. getRegisteredRangeThemes() {
  4597. return this._injector.get(ho).getRegisteredRangeThemes();
  4598. }
  4599. /**
  4600. * Register a custom range theme style.
  4601. * @param {RangeThemeStyle} rangeThemeStyle The range theme style to register
  4602. * @returns {void}
  4603. * @example
  4604. * ```ts
  4605. * // import {RangeThemeStyle} from '@univerjs/sheets';
  4606. * const fWorkbook = univerAPI.getActiveWorkbook();
  4607. * const rangeThemeStyle = new RangeThemeStyle('MyTheme');
  4608. * rangeThemeStyle.setSecondRowStyle({
  4609. * bg: {
  4610. * rgb: 'rgb(214,231,241)',
  4611. * },
  4612. * });
  4613. * fWorkbook.registerRangeTheme(rangeThemeStyle);
  4614. * ```
  4615. */
  4616. registerRangeTheme(e) {
  4617. this._commandService.syncExecuteCommand(wu2.id, {
  4618. unitId: this.getId(),
  4619. rangeThemeStyle: e
  4620. });
  4621. }
  4622. /**
  4623. * Unregister a custom range theme style.
  4624. * @param {string} themeName The name of the theme to unregister
  4625. * @returns {void}
  4626. * @example
  4627. * ```ts
  4628. * const fWorkbook = univerAPI.getActiveWorkbook();
  4629. * fWorkbook.unregisterRangeTheme('MyTheme');
  4630. * ```
  4631. */
  4632. unregisterRangeTheme(e) {
  4633. this._commandService.syncExecuteCommand(Ol.id, {
  4634. unitId: this.getId(),
  4635. themeName: e
  4636. });
  4637. }
  4638. /**
  4639. * Set custom metadata of workbook
  4640. * @param {CustomData | undefined} custom custom metadata
  4641. * @returns {FWorkbook} FWorkbook
  4642. * @example
  4643. * ```ts
  4644. * const fWorkbook = univerAPI.getActiveWorkbook();
  4645. * fWorkbook.setCustomMetadata({ key: 'value' });
  4646. * ```
  4647. */
  4648. setCustomMetadata(e) {
  4649. return this._workbook.setCustomMetadata(e), this;
  4650. }
  4651. /**
  4652. * Get custom metadata of workbook
  4653. * @returns {CustomData | undefined} custom metadata
  4654. * @example
  4655. * ```ts
  4656. * const fWorkbook = univerAPI.getActiveWorkbook();
  4657. * const custom = fWorkbook.getCustomMetadata();
  4658. * ```
  4659. */
  4660. getCustomMetadata() {
  4661. return this._workbook.getCustomMetadata();
  4662. }
  4663. };
  4664. f = _n2([
  4665. C(1, ot(Ot)),
  4666. C(2, ot(va)),
  4667. C(3, ot(F)),
  4668. C(4, _n),
  4669. C(5, Pt),
  4670. C(6, UE),
  4671. C(7, Mt),
  4672. C(8, ot(Vr)),
  4673. C(9, pr)
  4674. ], f);
  4675. var kn = class extends pi {
  4676. getCommandSheetTarget(e) {
  4677. var i;
  4678. const t = e.params;
  4679. if (!t)
  4680. return;
  4681. const n = t.unitId ? this.getUniverSheet(t.unitId) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
  4682. if (!n)
  4683. return;
  4684. const s = n.getSheetBySheetId(t.subUnitId || t.sheetId) || n.getActiveSheet();
  4685. if (s)
  4686. return { workbook: n, worksheet: s };
  4687. }
  4688. getSheetTarget(e, t) {
  4689. const n = this.getUniverSheet(e);
  4690. if (!n)
  4691. return;
  4692. const s = n.getSheetBySheetId(t);
  4693. if (s)
  4694. return { workbook: n, worksheet: s };
  4695. }
  4696. _initWorkbookEvent(e) {
  4697. const t = e.get(_n);
  4698. this.disposeWithMe(
  4699. t.unitDisposed$.subscribe((n) => {
  4700. this._eventRegistry.get(this.Event.WorkbookDisposed) && n.type === Fe.UNIVER_SHEET && this.fireEvent(
  4701. this.Event.WorkbookDisposed,
  4702. {
  4703. unitId: n.getUnitId(),
  4704. unitType: n.type,
  4705. snapshot: n.getSnapshot()
  4706. }
  4707. );
  4708. })
  4709. ), this.disposeWithMe(
  4710. t.unitAdded$.subscribe((n) => {
  4711. if (this._eventRegistry.get(this.Event.WorkbookCreated) && n.type === Fe.UNIVER_SHEET) {
  4712. const s = n, i = e.createInstance(f, s);
  4713. this.fireEvent(
  4714. this.Event.WorkbookCreated,
  4715. {
  4716. unitId: n.getUnitId(),
  4717. type: n.type,
  4718. workbook: i,
  4719. unit: i
  4720. }
  4721. );
  4722. }
  4723. })
  4724. );
  4725. }
  4726. // eslint-disable-next-line max-lines-per-function
  4727. _initialize(e) {
  4728. const t = e.get(Pt);
  4729. this.disposeWithMe(
  4730. // eslint-disable-next-line max-lines-per-function, complexity
  4731. t.beforeCommandExecuted((n) => {
  4732. var s, i, o, h;
  4733. switch (n.id) {
  4734. case fu.id: {
  4735. 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);
  4736. if (!k)
  4737. return;
  4738. const ge = {
  4739. workbook: k,
  4740. index: c,
  4741. sheet: v
  4742. };
  4743. if (this.fireEvent(
  4744. this.Event.BeforeSheetCreate,
  4745. ge
  4746. ), ge.cancel)
  4747. throw new xf();
  4748. break;
  4749. }
  4750. case Ar.id: {
  4751. if (!this._eventListend(this.Event.BeforeActiveSheetChange))
  4752. return;
  4753. const { subUnitId: a, unitId: d } = n.params, c = d ? this.getUniverSheet(d) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
  4754. if (!c || !a)
  4755. return;
  4756. const v = c.getSheetBySheetId(a), k = c.getActiveSheet();
  4757. if (!v || !k)
  4758. return;
  4759. this._fireBeforeActiveSheetChange(c, v, k);
  4760. break;
  4761. }
  4762. case ko.id: {
  4763. if (!this._eventListend(this.Event.BeforeSheetDelete))
  4764. return;
  4765. const a = this.getCommandSheetTarget(n);
  4766. if (!a)
  4767. return;
  4768. const { workbook: d, worksheet: c } = a;
  4769. this._fireBeforeSheetDelete(d, c);
  4770. break;
  4771. }
  4772. case Wr.id: {
  4773. if (!this._eventListend(this.Event.BeforeSheetMove))
  4774. return;
  4775. const { fromOrder: a, toOrder: d } = n.params, c = this.getCommandSheetTarget(n);
  4776. if (!c)
  4777. return;
  4778. this._fireBeforeSheetMove(c.workbook, c.worksheet, d, a);
  4779. break;
  4780. }
  4781. case Do.id: {
  4782. if (!this._eventListend(this.Event.BeforeSheetNameChange))
  4783. return;
  4784. const { name: a } = n.params, d = this.getCommandSheetTarget(n);
  4785. if (!d)
  4786. return;
  4787. this._fireBeforeSheetNameChange(d.workbook, d.worksheet, a, d.worksheet.getSheetName());
  4788. break;
  4789. }
  4790. case al2.id: {
  4791. if (!this._eventListend(this.Event.BeforeSheetTabColorChange))
  4792. return;
  4793. const { color: a } = n.params, d = this.getCommandSheetTarget(n);
  4794. if (!d)
  4795. return;
  4796. this._fireBeforeSheetTabColorChange(d.workbook, d.worksheet, a, d.worksheet.getTabColor());
  4797. break;
  4798. }
  4799. case hl.id: {
  4800. if (!this._eventListend(this.Event.BeforeSheetHideChange))
  4801. return;
  4802. const { hidden: a } = n.params, d = this.getCommandSheetTarget(n);
  4803. if (!d)
  4804. return;
  4805. this._fireBeforeSheetHideChange(d.workbook, d.worksheet, !!a);
  4806. break;
  4807. }
  4808. case ju.id: {
  4809. if (!this._eventListend(this.Event.BeforeGridlineColorChange))
  4810. return;
  4811. const a = this.getCommandSheetTarget(n);
  4812. if (!a)
  4813. return;
  4814. this.fireEvent(this.Event.BeforeGridlineColorChange, {
  4815. ...a,
  4816. color: (o = n.params) == null ? void 0 : o.color
  4817. });
  4818. break;
  4819. }
  4820. case Nl.id: {
  4821. if (!this._eventListend(this.Event.BeforeGridlineEnableChange))
  4822. return;
  4823. const a = this.getCommandSheetTarget(n);
  4824. if (!a)
  4825. return;
  4826. this.fireEvent(this.Event.BeforeGridlineEnableChange, {
  4827. ...a,
  4828. enabled: !!((h = n.params) != null && h.showGridlines)
  4829. });
  4830. break;
  4831. }
  4832. }
  4833. })
  4834. ), this.disposeWithMe(
  4835. // eslint-disable-next-line max-lines-per-function, complexity
  4836. t.onCommandExecuted((n) => {
  4837. var s, i;
  4838. if (fh.indexOf(n.id) > -1) {
  4839. if (!this._eventListend(this.Event.SheetValueChanged) || !this.getActiveSheet())
  4840. return;
  4841. const h = Rh(n).map(
  4842. (a) => {
  4843. var d, c;
  4844. return (c = (d = this.getWorkbook(a.unitId)) == null ? void 0 : d.getSheetBySheetId(a.subUnitId)) == null ? void 0 : c.getRange(a.range);
  4845. }
  4846. ).filter(Boolean);
  4847. if (!h.length)
  4848. return;
  4849. this.fireEvent(this.Event.SheetValueChanged, {
  4850. payload: n,
  4851. effectedRanges: h
  4852. });
  4853. return;
  4854. }
  4855. switch (n.id) {
  4856. case fu.id: {
  4857. const o = n.params, { unitId: h } = o || {}, a = h ? this.getUniverSheet(h) : (s = this.getActiveWorkbook) == null ? void 0 : s.call(this);
  4858. if (!a)
  4859. return;
  4860. const d = a.getActiveSheet();
  4861. if (!d)
  4862. return;
  4863. const c = {
  4864. workbook: a,
  4865. worksheet: d
  4866. };
  4867. this.fireEvent(
  4868. this.Event.SheetCreated,
  4869. c
  4870. );
  4871. break;
  4872. }
  4873. case Ar.id: {
  4874. if (!this._eventListend(this.Event.ActiveSheetChanged))
  4875. return;
  4876. const o = this.getActiveSheet();
  4877. if (!o)
  4878. return;
  4879. const { workbook: h, worksheet: a } = o;
  4880. this._fireActiveSheetChanged(h, a);
  4881. break;
  4882. }
  4883. case ko.id: {
  4884. if (!this._eventListend(this.Event.SheetDeleted))
  4885. return;
  4886. const { subUnitId: o, unitId: h } = n.params, a = h ? this.getUniverSheet(h) : (i = this.getActiveWorkbook) == null ? void 0 : i.call(this);
  4887. if (!a || !o)
  4888. return;
  4889. this._fireSheetDeleted(a, o);
  4890. break;
  4891. }
  4892. case Wr.id: {
  4893. if (!this._eventListend(this.Event.SheetMoved))
  4894. return;
  4895. const { toOrder: o } = n.params, h = this.getCommandSheetTarget(n);
  4896. if (!h)
  4897. return;
  4898. this._fireSheetMoved(h.workbook, h.worksheet, o);
  4899. break;
  4900. }
  4901. case Do.id: {
  4902. if (!this._eventListend(this.Event.SheetNameChanged))
  4903. return;
  4904. const { name: o } = n.params, h = this.getCommandSheetTarget(n);
  4905. if (!h)
  4906. return;
  4907. this._fireSheetNameChanged(h.workbook, h.worksheet, o);
  4908. break;
  4909. }
  4910. case al2.id: {
  4911. if (!this._eventListend(this.Event.SheetTabColorChanged))
  4912. return;
  4913. const { color: o } = n.params, h = this.getCommandSheetTarget(n);
  4914. if (!h)
  4915. return;
  4916. this._fireSheetTabColorChanged(h.workbook, h.worksheet, o);
  4917. break;
  4918. }
  4919. case hl.id: {
  4920. if (!this._eventListend(this.Event.SheetHideChanged))
  4921. return;
  4922. const { hidden: o } = n.params, h = this.getCommandSheetTarget(n);
  4923. if (!h)
  4924. return;
  4925. this._fireSheetHideChanged(h.workbook, h.worksheet, !!o);
  4926. break;
  4927. }
  4928. case ju.id:
  4929. case Nl.id: {
  4930. if (!this._eventListend(this.Event.GridlineChanged))
  4931. return;
  4932. const o = this.getCommandSheetTarget(n);
  4933. if (!o)
  4934. return;
  4935. this.fireEvent(this.Event.GridlineChanged, {
  4936. ...o,
  4937. enabled: !o.worksheet.hasHiddenGridLines(),
  4938. color: o.worksheet.getGridLinesColor()
  4939. });
  4940. break;
  4941. }
  4942. }
  4943. })
  4944. ), this._initWorkbookEvent(e);
  4945. }
  4946. createUniverSheet(e) {
  4947. const n = this._injector.get(_n).createUnit(Fe.UNIVER_SHEET, e);
  4948. return this._injector.createInstance(f, n);
  4949. }
  4950. createWorkbook(e) {
  4951. return this.createUniverSheet(e);
  4952. }
  4953. getActiveWorkbook() {
  4954. const e = this._univerInstanceService.getCurrentUnitForType(Fe.UNIVER_SHEET);
  4955. return e ? this._injector.createInstance(f, e) : null;
  4956. }
  4957. getActiveUniverSheet() {
  4958. return this.getActiveWorkbook();
  4959. }
  4960. getUniverSheet(e) {
  4961. const t = this._univerInstanceService.getUnit(e, Fe.UNIVER_SHEET);
  4962. return t ? this._injector.createInstance(f, t) : null;
  4963. }
  4964. getWorkbook(e) {
  4965. return this.getUniverSheet(e);
  4966. }
  4967. getPermission() {
  4968. return this._injector.createInstance(j);
  4969. }
  4970. onUniverSheetCreated(e) {
  4971. const t = this._univerInstanceService.getTypeOfUnitAdded$(Fe.UNIVER_SHEET).subscribe((n) => {
  4972. const s = this._injector.createInstance(f, n);
  4973. e(s);
  4974. });
  4975. return Ze(t);
  4976. }
  4977. newDefinedName() {
  4978. return this._injector.createInstance(V);
  4979. }
  4980. getActiveSheet() {
  4981. const e = this.getActiveWorkbook();
  4982. if (!e)
  4983. return null;
  4984. const t = e.getActiveSheet();
  4985. return t ? { workbook: e, worksheet: t } : null;
  4986. }
  4987. _fireBeforeActiveSheetChange(e, t, n) {
  4988. this.fireEvent(this.Event.BeforeActiveSheetChange, {
  4989. workbook: e,
  4990. activeSheet: t,
  4991. oldActiveSheet: n
  4992. });
  4993. }
  4994. _fireActiveSheetChanged(e, t) {
  4995. this.fireEvent(this.Event.ActiveSheetChanged, {
  4996. workbook: e,
  4997. activeSheet: t
  4998. });
  4999. }
  5000. _fireBeforeSheetDelete(e, t) {
  5001. this.fireEvent(this.Event.BeforeSheetDelete, {
  5002. workbook: e,
  5003. worksheet: t
  5004. });
  5005. }
  5006. _fireSheetDeleted(e, t) {
  5007. this.fireEvent(this.Event.SheetDeleted, {
  5008. workbook: e,
  5009. sheetId: t
  5010. });
  5011. }
  5012. _fireBeforeSheetMove(e, t, n, s) {
  5013. this.fireEvent(this.Event.BeforeSheetMove, {
  5014. workbook: e,
  5015. worksheet: t,
  5016. newIndex: n,
  5017. oldIndex: s
  5018. });
  5019. }
  5020. _fireSheetMoved(e, t, n) {
  5021. this.fireEvent(this.Event.SheetMoved, {
  5022. workbook: e,
  5023. worksheet: t,
  5024. newIndex: n
  5025. });
  5026. }
  5027. _fireBeforeSheetNameChange(e, t, n, s) {
  5028. this.fireEvent(this.Event.BeforeSheetNameChange, {
  5029. workbook: e,
  5030. worksheet: t,
  5031. newName: n,
  5032. oldName: s
  5033. });
  5034. }
  5035. _fireSheetNameChanged(e, t, n) {
  5036. this.fireEvent(this.Event.SheetNameChanged, {
  5037. workbook: e,
  5038. worksheet: t,
  5039. newName: n
  5040. });
  5041. }
  5042. _fireBeforeSheetTabColorChange(e, t, n, s) {
  5043. this.fireEvent(this.Event.BeforeSheetTabColorChange, {
  5044. workbook: e,
  5045. worksheet: t,
  5046. newColor: n,
  5047. oldColor: s
  5048. });
  5049. }
  5050. _fireSheetTabColorChanged(e, t, n) {
  5051. this.fireEvent(this.Event.SheetTabColorChanged, {
  5052. workbook: e,
  5053. worksheet: t,
  5054. newColor: n
  5055. });
  5056. }
  5057. _fireBeforeSheetHideChange(e, t, n) {
  5058. this.fireEvent(this.Event.BeforeSheetHideChange, {
  5059. workbook: e,
  5060. worksheet: t,
  5061. hidden: n
  5062. });
  5063. }
  5064. _fireSheetHideChanged(e, t, n) {
  5065. this.fireEvent(this.Event.SheetHideChanged, {
  5066. workbook: e,
  5067. worksheet: t,
  5068. hidden: n
  5069. });
  5070. }
  5071. };
  5072. pi.extend(kn);
  5073. var Sn = class {
  5074. get SheetValueChangeType() {
  5075. return vd;
  5076. }
  5077. get SheetSkeletonChangeType() {
  5078. return Id;
  5079. }
  5080. };
  5081. ci.extend(Sn);
  5082. var wn = class extends hi {
  5083. get SheetCreated() {
  5084. return "SheetCreated";
  5085. }
  5086. get BeforeSheetCreate() {
  5087. return "BeforeSheetCreate";
  5088. }
  5089. get WorkbookCreated() {
  5090. return "WorkbookCreated";
  5091. }
  5092. get WorkbookDisposed() {
  5093. return "WorkbookDisposed";
  5094. }
  5095. get GridlineChanged() {
  5096. return "GridlineChanged";
  5097. }
  5098. get BeforeGridlineEnableChange() {
  5099. return "BeforeGridlineEnableChange";
  5100. }
  5101. get BeforeGridlineColorChange() {
  5102. return "BeforeGridlineColorChange";
  5103. }
  5104. get BeforeActiveSheetChange() {
  5105. return "BeforeActiveSheetChange";
  5106. }
  5107. get ActiveSheetChanged() {
  5108. return "ActiveSheetChanged";
  5109. }
  5110. get SheetDeleted() {
  5111. return "SheetDeleted";
  5112. }
  5113. get BeforeSheetDelete() {
  5114. return "BeforeSheetDelete";
  5115. }
  5116. get SheetMoved() {
  5117. return "SheetMoved";
  5118. }
  5119. get BeforeSheetMove() {
  5120. return "BeforeSheetMove";
  5121. }
  5122. get SheetNameChanged() {
  5123. return "SheetNameChanged";
  5124. }
  5125. get BeforeSheetNameChange() {
  5126. return "BeforeSheetNameChange";
  5127. }
  5128. get SheetTabColorChanged() {
  5129. return "SheetTabColorChanged";
  5130. }
  5131. get BeforeSheetTabColorChange() {
  5132. return "BeforeSheetTabColorChange";
  5133. }
  5134. get SheetHideChanged() {
  5135. return "SheetHideChanged";
  5136. }
  5137. get BeforeSheetHideChange() {
  5138. return "BeforeSheetHideChange";
  5139. }
  5140. get SheetValueChanged() {
  5141. return "SheetValueChanged";
  5142. }
  5143. };
  5144. hi.extend(wn);
  5145. var Cn = Object.defineProperty;
  5146. var fn2 = Object.getOwnPropertyDescriptor;
  5147. var vn = (r, e, t, n) => {
  5148. for (var s = n > 1 ? void 0 : n ? fn2(e, t) : e, i = r.length - 1, o; i >= 0; i--)
  5149. (o = r[i]) && (s = (n ? o(e, t, s) : o(s)) || s);
  5150. return n && s && Cn(e, t, s), s;
  5151. };
  5152. var In = (r, e) => (t, n) => e(t, n, r);
  5153. var xe = class extends Fi {
  5154. constructor(r) {
  5155. super(), this._injector = r;
  5156. }
  5157. };
  5158. xe = vn([
  5159. In(0, ot(Ot))
  5160. ], xe);
  5161. export {
  5162. j,
  5163. S,
  5164. L,
  5165. m,
  5166. f,
  5167. Sn,
  5168. wn,
  5169. xe
  5170. };
  5171. //# sourceMappingURL=chunk-CLOCSTN3.js.map