facade.js 169 KB

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