/// <summary> /// Add content row to the table. /// </summary> private static TableRow AddContentRow(QueryResult queryResult, DataRow contentRow) { TableCell tc; TableRow tr = new TableRow( ); int dataColIndx = 0; foreach (ResultColumn col in queryResult.Columns) { if (!col.IsHidden) { object cellValue = contentRow[dataColIndx]; if (cellValue != null) { if (col.ColumnType is AutoIncrementType) { string displayPattern = null; if (contentRow.Table.Columns[dataColIndx].ExtendedProperties.ContainsKey("DisplayPattern")) { displayPattern = ( string )contentRow.Table.Columns[dataColIndx].ExtendedProperties["DisplayPattern"]; } var intStringVal = cellValue as string; int temp; if (intStringVal != null) { temp = int.Parse(intStringVal); } else { temp = ( int )cellValue; } if (string.IsNullOrEmpty(displayPattern)) { AddContentRow_NonString(tr, col, temp); } else { AddContentRow_String(tr, col, temp.ToString(displayPattern)); } } else if (col.ColumnType is DateTimeType || col.ColumnType is TimeType || col.ColumnType is DateType || col.ColumnType is Int32Type || col.ColumnType is NumericType <decimal> || col.ColumnType is NumericType <Single> ) { AddContentRow_NonString(tr, col, cellValue); } else if (col.ColumnType is StructureLevelsType) { //Get the structure view cell value string cellText = ExportDataHelper.GetStructureLevelCellValue(( string )contentRow[dataColIndx], true); string[] views = cellText.Split(new[] { Environment.NewLine }, StringSplitOptions.None); int i = 1; tc = new TableCell( ); Paragraph paragraph = new Paragraph( ); Run run = new Run( ); foreach (string structureView in views) { run.Append(new DocumentFormat.OpenXml.Wordprocessing.Text(structureView)); if (i != views.Length) { //Insert a break for new line. run.Append(new Break( )); } else { paragraph.Append(run); tc.Append(paragraph); tr.Append(tc); } i++; } } else { AddContentRow_String(tr, col, cellValue); } } else { tc = new TableCell(new Paragraph(new Run( new DocumentFormat.OpenXml.Wordprocessing.Text("")))); tr.Append(tc); } } dataColIndx++; } return(tr); }
/// <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); }