Пример #1
0
        /**
         * Write the content of the <code>RtfCell</code>.
         *
         * @param os The <code>Stream</code> to which to write the content of
         * the <code>RtfCell</code> to.
         * @return true if writing the cell content succeeded
         * @throws DocumentException
         */
        public bool WriteCellContent(MemoryStream os)
        {
            try {
                if (mergeType == MERGE_HORIZ_PREV || mergeType == MERGE_BOTH_PREV)
                {
                    return(true);
                }

                if (!emptyCell)
                {
                    Paragraph    container    = null;
                    ListIterator cellIterator = new ListIterator(store.Elements);
                    while (cellIterator.HasNext())
                    {
                        IElement element = (IElement)cellIterator.Next();
                        // should we wrap it in a paragraph
                        if (!(element is Paragraph))
                        {
                            if (container != null)
                            {
                                container.Add(element);
                            }
                            else
                            {
                                container           = new Paragraph();
                                container.Alignment = store.HorizontalAlignment;
                                container.Add(element);
                            }
                        }
                        else
                        {
                            if (container != null)
                            {
                                writer.AddElement(container, os);
                                container = null;
                                container = null;
                            }


                            // if horizontal alignment is undefined overwrite
                            // with that of enclosing cell
                            if (element is Paragraph && ((Paragraph)element).Alignment == Element.ALIGN_UNDEFINED)
                            {
                                ((Paragraph)element).Alignment = store.HorizontalAlignment;
                            }
                            writer.AddElement(element, os);
                            if (element.Type == Element.PARAGRAPH && cellIterator.HasNext())
                            {
                                os.WriteByte(RtfWriter.escape);
                                os.Write(RtfWriter.paragraph, 0, RtfWriter.paragraph.Length);
                            }
                        }
                    }
                    if (container != null)
                    {
                        writer.AddElement(container, os);
                        container = null;
                    }
                }
                else
                {
                    os.WriteByte(RtfWriter.escape);
                    os.Write(RtfWriter.paragraphDefaults, 0, RtfWriter.paragraphDefaults.Length);
                    os.WriteByte(RtfWriter.escape);
                    os.Write(cellInTable, 0, cellInTable.Length);
                }
                os.WriteByte(RtfWriter.escape);
                os.Write(cellEnd, 0, cellEnd.Length);
            } catch (IOException) {
                return(false);
            }
            return(true);
        }