There is no set formula as to what to say. Only one rule should guide you in writing letters of condolence: Say what you truly feel. Your clear expression of sympathy and caring for your co-worker is what matters the most. Sit down at your desk as soon as you hear of the death and let your thoughts be with your co-worker as you write to her.
If you knew the person they lost, some kind words about them - perhaps an anecdote, would mean a lot. If you didn't know them, you could mention something special you've heard about them. Ask, or offer, to be helpful to your friend, perhaps by helping them with her workload the day of the funeral or memorial service. Close with warm words, such as "With deepest sympathy."
Don't forget that you can also e-mail your co-worker to express your thoughts before you write your condolence note. E-mail is an immediate way to reach out and say, "I'm sorry. I'm here for you." And unlike a phone call or a personal visit, e-mail doesn't require an immediate response from the recipient. E-mail shouldn't replace a handwritten condolence note, but it's a nice way to remind your co-worker that you're there for them.