Arm yourself. First mentally, then emotionally and finally physically.
Mentally arm yourself by taking in your current location relative to what and who else are around you. Look for any immediate dangers: hostile people or physical obstacles. Plan an escape route.
Emotionally arm yourself. Remember to breathe and stay calm. Focus on your escape route. Can you, without endangering yourself, bring others with you? Might you have to get physical with anyone or anything along that route? If so, is there a better route? If there is no better route, emotionally prepare yourself to do what needs to be done to get to safety.
Physically arm yourself. Can you find anything that can be used as a defensive weapon? A top rail of a cubicle, a power strip, a chair or anything that can be swung or thrown if needed to distract any threats you may come upon while getting to safety. Keep as many physical barriers between yourself and active threats as you can without cornering yourself.
If you are in a work environment where an event like this is a realistic possibility, such as a convenience store, a courthouse, a payday loan office, or even just a workplace in the wrong part of town, prepare before there is a real threat by mentally arming yourself. Memorize your exit paths, take into account where desks, shelving or other barriers are and may be shoved to (defensively or offensively). Ensure your co-workers are also prepared if a threat occurs.
If the possibility of such an event is probable consider taking self defense classes to further physically arm yourself. Practice meditation to help you keep your emotions in control when something happens.
If you choose to carry a traditional weapon (club, knife, gun, etc.), learn and practice using it correctly. When a real threat happens, it will be more likely to harm you than your attacker if your not prepared to use it. If you have a concealed weapon and are not physically, mentally and emotionally prepared to use it, do not even reveal it. Do not attempt to be a hero with your weapon, you'll only further endanger yourself and others.
Most people will never be in a situation where any of this is necessary. If you're not at an elevated risk for attack, it is still good to be prepared, but do not allow your preparation to make you paranoid or pessimistic. Remember though, when seconds matter the police are only minutes away.