How do I remain in good spirits? Simple: I don't. Not all the time anyway. I let myself freely feel whatever it is I'm feeling without hiding it. If I feel estatic, I jump for joy. If I'm sad, I cry until I'm all out of tears. If I'm angry, I scream into a pillow (or punch one, depending on which I'd rather do at the moment). Stuff like that. It's healthy to do for my own emotional regulation and balance of emotions. It keeps my emotions from bottling up. Not only that, but other people can more easily guess my current emotional state and know what to do or say to help based on that.
If I'm in a place where the emotion I want to express and/or the way I want to express it isn't appropriate (getting angry at customers, feeling way too giddy at a formal meeting, crying during a college class, etc), I excuse myself to temporarily leave the room, get the worst of it out of me and come back. If they refuse to let me do that (hasn't happened, but it hypothetically could), I'd just ask to use the bathroom since they're less likely to object to that for obvious reasons, and do it in there instead.
This helps me by letting all my bad emotions or any strong feelings I have (good or bad) out instead of keeping them to myself. Once it's all out of my system, I can go back to my default mood of happiness. I'm almost always happy unless I have a reason not to be, or at least to not be experiencing another emotion more strongly. That's just how I am.
Another thing I do is try and find at least one silver lining in every bad situation I'm in, no matter how bad the situation is and how small the silver lining is. Sometimes the only silver lining I think of is something basic like being able to breathe, having clean air, water or food available, clothes I like, an education, internet access and so on. As long as I can think of something, I remind myself that no matter how bad my current situation is, it could be worse, and that eventually, it will get better. It's important that you don't go to any toxic extremes while doing this, to the point where you force yourself to be happy all the time and deny yourself to feel remorseful over bad things that happen to you, but I find that these type of mindsets can help me a lot in small doses and if it comes naturally to me and doesn't feel forced. All good things in moderation.
If doing stuff physically doesn't help, or you'd rather not go down that path, I'm sure you could achieve similar results by venting somewhere (either to yourself or another person or group of people), or journaling your emotions, as other users on here have already suggested. I prefer venting or physical stuff though, because I am too through for my own good, and get too caught up in making sure I describe every second of my life when journaling, but with venting, my only goal is to type until I feel better, and how through or coherent I am doesn't matter in the slightest, so I don't overthink that aspect as much, which is why it's better for me. What works for me may not work for you and vice versa though, so try a bit of everything until you find out what works for you.