Exemplo n.º 1
0
        /// <summary>
        /// Writes a row of a table section.
        /// </summary>
        /// <param name="iRow">The row number.</param>
        /// <param name="numberOfColumns">The number of columns to write.</param>
        /// <param name="secType">The section type.</param>
        /// <param name="data">The table section data.</param>
        private void WriteSectionRow(SectionType secType, TableSectionData data, int iRow, int numberOfColumns)
        {
            // Start the table row tag.
            writer.RenderBeginTag(HtmlTextWriterTag.Tr);

            // Loop over the table section row.
            for (int iCol = data.FirstColumnNumber; iCol < numberOfColumns; iCol++)
            {
                // Skip already written cells
                if (writtenCells.Contains(new Tuple <int, int>(iRow, iCol)))
                {
                    continue;
                }

                // Get style
                TableCellStyle style             = data.GetTableCellStyle(iRow, iCol);
                int            numberOfStyleTags = 1;



                // Merged cells
                TableMergedCell mergedCell = data.GetMergedCell(iRow, iCol);

                // If merged cell spans multiple columns
                if (mergedCell.Left != mergedCell.Right)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Colspan, (mergedCell.Right - mergedCell.Left + 1).ToString());
                }

                // If merged cell spans multiple rows
                if (mergedCell.Top != mergedCell.Bottom)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Rowspan, (mergedCell.Bottom - mergedCell.Top + 1).ToString());
                }

                // Remember all written cells related to the merge
                for (int iMergedRow = mergedCell.Top; iMergedRow <= mergedCell.Bottom; iMergedRow++)
                {
                    for (int iMergedCol = mergedCell.Left; iMergedCol <= mergedCell.Right; iMergedCol++)
                    {
                        writtenCells.Add(new Tuple <int, int>(iMergedRow, iMergedCol));
                    }
                }

                // Write formatting attributes for the upcoming cell
                // Background color
                if (!ColorsEqual(style.BackgroundColor, White))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Bgcolor, GetColorHtmlString(style.BackgroundColor));
                }

                // Horizontal alignment
                writer.AddAttribute(HtmlTextWriterAttribute.Align, GetAlignString(style.FontHorizontalAlignment));

                // Write cell tag
                writer.RenderBeginTag(HtmlTextWriterTag.Td);

                // Write subtags for the cell
                // Underline
                if (style.IsFontUnderline)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.U);
                    numberOfStyleTags++;
                }

                //Italic
                if (style.IsFontItalic)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.I);
                    numberOfStyleTags++;
                }

                //Bold
                if (style.IsFontBold)
                {
                    writer.RenderBeginTag(HtmlTextWriterTag.B);
                    numberOfStyleTags++;
                }

                // Write cell text
                String cellText = theSchedule.GetCellText(secType, iRow, iCol);
                if (cellText.Length > 0)
                {
                    writer.Write(cellText);
                }
                else
                {
                    writer.Write("&nbsp;");
                }

                // Close open style tags & cell tag
                for (int i = 0; i < numberOfStyleTags; i++)
                {
                    writer.RenderEndTag();
                }
            }
            // Close row tag
            writer.RenderEndTag();
        }
Exemplo n.º 2
0
        private RevitDataTable GetRevitDataTable(ViewSchedule schedule)
        {
            ScheduleDefinition scheduleDefinition = schedule.Definition;
            TableSectionData   bodyData           = schedule.GetTableData().GetSectionData(SectionType.Body);
            TableSectionData   headerData         = schedule.GetTableData().GetSectionData(SectionType.Header);

            RevitDataTable   dataTable   = new RevitDataTable(schedule.Name);
            RevitDataSection dataSection = new RevitDataSection("Без названия");

            dataTable.Sections.Add(dataSection);
            // заголовки
            int start_i;

            if (scheduleDefinition.ShowHeaders)
            {
                RevitDataRow header = new RevitDataRow(0);
                for (int col = 0; col < bodyData.NumberOfColumns; col++)
                {
                    RevitDataCell dataCell = new RevitDataCell(
                        schedule.GetCellText(SectionType.Body, 0, col),
                        bodyData.GetCellType(0, col),
                        bodyData.GetCellParamId(col));
                    header.Cells.Add(dataCell);
                }
                start_i          = 1;
                dataTable.Header = header;
            }
            else
            {
                start_i = 0;
            }
            //ищем секции
            for (int row = start_i; row < bodyData.NumberOfRows; row++)
            {
                if (bodyData.GetCellType(row, 0) == CellType.Text &&
                    bodyData.GetMergedCell(row, 0).Right == bodyData.LastColumnNumber)
                {
                    string header = bodyData.GetCellText(row, 0);
                    header      = string.IsNullOrEmpty(header) ? "Без названия" : header;
                    dataSection = new RevitDataSection(header);
                    dataTable.Sections.Add(dataSection);
                    continue;
                }

                RevitDataRow dataRow = new RevitDataRow(row);
                for (int col = 0; col < bodyData.NumberOfColumns; col++)
                {
                    RevitDataCell dataCell = new RevitDataCell(
                        schedule.GetCellText(SectionType.Body, row, col),
                        bodyData.GetCellType(row, col),
                        bodyData.GetCellParamId(col));
                    dataRow.Cells.Add(dataCell);
                }
                dataSection.Rows.Add(dataRow);
            }
            if (dataTable["Без названия"].Rows.Count == 0)
            {
                dataTable.Sections.Remove(dataTable["Без названия"]);
            }
            return(dataTable);
        }