Ejemplo n.º 1
0
        /// <summary>
        /// Add content row to the table.
        /// </summary>
        private static TableRow AddContentRow(ReportResult reportResult, DataRow contentRow)
        {
            TableCell tc;
            TableRow  tr          = new TableRow();
            int       dataColIndx = 0;

            foreach (ReportColumn col in reportResult.Metadata.ReportColumns.Values)
            {
                if (!col.IsHidden && col.Type != "Image")
                {
                    string       cellValue = ExportDataHelper.GetCellValue(contentRow, dataColIndx);
                    DatabaseType cellType  = DatabaseTypeHelper.ConvertFromDisplayName(col.Type);
                    if (!string.IsNullOrEmpty(col.AutoNumberDisplayPattern))
                    {
                        cellType = DatabaseType.AutoIncrementType;
                    }
                    if (!string.IsNullOrEmpty(cellValue))
                    {
                        cellValue = ExportDataHelper.GetFormattedCellValue(cellType, cellValue, col);

                        if (cellType is DateTimeType || cellType is TimeType || cellType is DateType || cellType is Int32Type || cellType is NumericType <decimal> || cellType is NumericType <Single> )
                        {
                            AddContentRow_NonString(tr, cellValue);
                        }
                        else if (cellType is StructureLevelsType)
                        {
                            AddContentRow_StructureLevel(tr, cellValue);
                        }
                        else
                        {
                            AddContentRow_String(tr, cellValue);
                        }
                    }
                    else
                    {
                        tc = new TableCell(new Paragraph(new Run(
                                                             new DocumentFormat.OpenXml.Wordprocessing.Text(""))));
                        tr.Append(tc);
                    }
                }
                dataColIndx++;
            }
            return(tr);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create content row of the datatable.
        /// </summary>
        private static Row CreateContentRow(ReportResult reportResults, DataRow contentRow, int rowIndex)
        {
            Row row = new Row
            {
                RowIndex = (UInt32)rowIndex
            };

            int columnIndex     = 0;
            int dataColumnIndex = 0;

            foreach (ReportColumn col in reportResults.Metadata.ReportColumns.Values)
            {
                if (!col.IsHidden && col.Type != "Image")
                {
                    Cell         cell;
                    string       cellValue = ExportDataHelper.GetCellValue(contentRow, dataColumnIndex);
                    DatabaseType cellType  = DatabaseTypeHelper.ConvertFromDisplayName(col.Type);

                    if (!string.IsNullOrEmpty(col.AutoNumberDisplayPattern))
                    {
                        cellType = DatabaseType.AutoIncrementType;
                        col.Type = "AutoIncrement";
                    }
                    object value = DatabaseTypeHelper.ConvertFromString(cellType, cellValue);
                    if (string.IsNullOrEmpty(cellValue))
                    {
                        cell = CreateTextCell(null);
                        sharedStrings.TryAdd(sharedStringIndex, null);
                    }
                    else
                    {
                        DateTime dateValue;
                        switch (col.Type)
                        {
                        case "DateTime":
                            dateValue = Convert.ToDateTime(value);
                            cell      = CreateDateValueCell(dateValue, 4);
                            break;

                        case "Date":
                            dateValue = Convert.ToDateTime(value);
                            cell      = CreateDateValueCell(dateValue, 1);
                            break;

                        case "Time":
                            dateValue = OADateOrigin + (Convert.ToDateTime(value)).ToUniversalTime().TimeOfDay;
                            cell      = CreateDateValueCell(dateValue, 10);
                            break;

                        case "Int32":
                            cell = CreateNumericCell(value, 5);
                            break;

                        case "Decimal":
                            cell = CreateNumericCell(value, 6);
                            break;

                        case "Currency":
                            cell = CreateNumericCell(value, 9);
                            break;

                        case "AutoIncrement":
                            cellValue = ExportDataHelper.GetFormattedCellValue(cellType, cellValue, col);
                            cell      = CreateTextCell(null);
                            sharedStrings.TryAdd(sharedStringIndex, cellValue);
                            break;

                        case "StructureLevels":
                            cellValue = ExportDataHelper.GetStructureLevelCellValue(cellValue, true);
                            cell      = CreateTextCell(8);
                            sharedStrings.TryAdd(sharedStringIndex, cellValue);
                            break;

                        default:
                            cellValue = ExportDataHelper.GetFormattedCellValue(cellType, cellValue, col);
                            cell      = CreateTextCell(8);
                            sharedStrings.TryAdd(sharedStringIndex, cellValue);
                            break;
                        }
                    }

                    // Append the cell
                    SetCellLocation(cell, columnIndex, rowIndex);
                    row.AppendChild(cell);
                    columnIndex++;
                }
                dataColumnIndex++;
            }
            return(row);
        }