public override void CreateHorizontalTable(NamedLookup data, int splits, bool header) { // create table start this.htmlString += "<table>"; // 2 splits = 4 columns int currentColumnCount = 2 * splits; // if header needed if (header) CreateHeader(data.GetName()); // get a list of the keys List<string> tableKeys = data.GetLookup().Keys.ToList(); // determine the optimal number of rows for the table int optimalRowNumber = (tableKeys.Count() / splits) + (tableKeys.Count() % splits); int counter = 0; for (int i = 1; i <= optimalRowNumber; i++) { this.htmlString += "<tr>"; for (int j = 1; j <= currentColumnCount; j++) { this.htmlString += "<td>"; string currentKey = ""; if (counter != tableKeys.Count()) currentKey = tableKeys.ElementAt(counter); if (j % 2 != 0) { this.htmlString += currentKey; } else { if (counter != tableKeys.Count()) { if (currentKey.Equals("Source")) { this.htmlString += settings["Team Project Path"] + "/" + settings["Project Name"] + "/_workitems" + Environment.NewLine + data[currentKey]; } else { this.htmlString += data[currentKey]; } counter++; } else { this.htmlString += ""; } } this.htmlString += "</td>"; } this.htmlString += "</tr>"; } this.htmlString += "</table>"; }
/// <summary> /// Creates a horizontal data table in Excel /// </summary> /// <param name="data"></param> /// <param name="splits"></param> /// <param name="header"></param> public override void CreateHorizontalTable(NamedLookup data, int splits, bool header) { // 2 splits = 4 columns this.currentColumnCount = 2 * splits; this.starterRow = this.currentRow + 1; // if header needed if (header) CreateHeader(data.GetName()); // get a list of the keys List<string> tableKeys = data.GetLookup().Keys.ToList(); // determine the optimal number of rows for the table int optimalRowNumber = (tableKeys.Count() / splits) + (tableKeys.Count() % splits); // counter variable int counter = 0; for (int i = 1; i <= optimalRowNumber; i++) { for (int j = 1; j <= this.currentColumnCount; j++) { ExcelRange cellRange = GetSingleCellRange(worksheet, j + currentColumnOffset - 1, currentRow); string currentKey = ""; if (counter != tableKeys.Count()) currentKey = tableKeys.ElementAt(counter); worksheet.Row(i).Height = 18; cellRange.Style.Fill.PatternType = ExcelFillStyle.Solid; cellRange.Style.VerticalAlignment = ExcelVerticalAlignment.Center; cellRange.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; cellRange.Style.Font.Bold = true; cellRange.Style.Font.Size = 10; cellRange.Style.Font.Name = "Arial"; if (j % 2 != 0) { cellRange.Style.Fill.BackgroundColor.SetColor(Color.LightGray); cellRange.Value = currentKey; } else { if (counter != tableKeys.Count()) { cellRange.Style.Font.Color.SetColor(Color.FromArgb(0, 112, 192)); if (currentKey.Equals("Source")) { // hyperlink cellRange.Style.Font.Name = "Arial"; cellRange.Style.Font.Size = 10; cellRange.Style.Font.Bold = true; cellRange.Value = settings["Team Project Path"] + "/" + settings["Project Name"] + "/_versionControl" + Environment.NewLine + data[currentKey]; string address = settings["Team Project Path"] + "/" + settings["Project Name"] + "/_versionControl"; cellRange.Hyperlink = new Uri(address); } else { cellRange.Value = data[currentKey]; } counter++; } else { cellRange.Value = ""; } cellRange.Style.Fill.BackgroundColor.SetColor(Color.White); } } if (i == optimalRowNumber) { // style with basic theme SetBasicTheme(true); } AdvanceRow(0); } // insert final table split AdvanceRow(); }
/// <summary> /// Creates a horizontal data table in Excel /// </summary> /// <param name="data"></param> /// <param name="splits"></param> /// <param name="header"></param> public override void CreateHorizontalTable(NamedLookup data, int splits, bool header) { // 2 splits = 4 columns this.currentColumnCount = 2 * splits; this.starterRow = this.currentRow + 1; // if header needed if (header) CreateHeader(data.GetName()); // get a list of the keys List<string> tableKeys = data.GetLookup().Keys.ToList(); // determine the optimal number of rows for the table int optimalRowNumber = (tableKeys.Count() / splits) + (tableKeys.Count() % splits); // counter variable int counter = 0; for (int i = 1; i <= optimalRowNumber; i++) { for (int j = 1; j <= this.currentColumnCount; j++) { Excel.Range cellRange = GetSingleCellRange(worksheet, j + currentColumnOffset - 1, currentRow); string currentKey = ""; if (counter != tableKeys.Count()) currentKey = tableKeys.ElementAt(counter); cellRange.RowHeight = 18; cellRange.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; cellRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft; cellRange.Font.Bold = 1; cellRange.Font.Size = 10; cellRange.Font.Name = "Arial"; if (j % 2 != 0) { cellRange.Interior.Color = Excel.XlRgbColor.rgbLightGrey; cellRange.Value = currentKey; } else { if (counter != tableKeys.Count()) { cellRange.Font.Color = ColorTranslator.ToOle(Color.FromArgb(0, 112, 192)); if (currentKey.Equals("Source")) { // hyperlink cellRange.Font.Name = "Arial"; cellRange.Font.Size = 10; cellRange.Font.Bold = 1; cellRange.Hyperlinks.Add(cellRange, settings["Team Project Path"] + "/" + settings["Project Name"] + "/_workitems", Type.Missing, "Work Items", settings["Team Project Path"] + "/" + settings["Project Name"] + "/_workitems" + Environment.NewLine + data[currentKey]); } else { cellRange.Value = data[currentKey]; } counter++; } else { cellRange.Value = ""; } } } if (i == optimalRowNumber) { // style with basic theme SetBasicTheme(true); } AdvanceRow(0); } // insert final table split AdvanceRow(); }
/// <summary> /// Creates a gorizontal stacked table in Word /// </summary> /// <param name="data"></param> /// <param name="splits"></param> /// <param name="header"></param> public override void CreateHorizontalTable(NamedLookup data, int splits, bool header) { // test preconditions base.CreateHorizontalTable(data, splits, header); // if header needed if (header) CreateHeader(data.GetName()); // add another paragraph Word.Paragraph paragraph = document.Paragraphs.Add(); Word.Range range = paragraph.Range; // 2 splits = 4 columns int numberOfColumns = 2 * splits; // get a list of the keys List<string> tableKeys = data.GetLookup().Keys.ToList(); // determine the optimal number of rows for the table int optimalNumberOfRows = (tableKeys.Count() / splits) + (tableKeys.Count() % splits); // create the entire table with styling Word.Table table = document.Tables.Add(range, optimalNumberOfRows, numberOfColumns, Word.WdDefaultTableBehavior.wdWord9TableBehavior, Word.WdAutoFitBehavior.wdAutoFitFixed); table.PreferredWidth = app.InchesToPoints(6.0F); table.Rows.Alignment = Word.WdRowAlignment.wdAlignRowCenter; // goto first cell Word.Cell tableCell = table.Cell(1, 1); // counter variable int counter = 0; // style the entire table table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; table.Borders.InsideLineWidth = Word.WdLineWidth.wdLineWidth100pt; table.Borders.InsideColor = Word.WdColor.wdColorGray45; table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; table.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth150pt; table.Borders.OutsideColor = Word.WdColor.wdColorGray55; // set styling for horizontal columns for (int i = 1; i <= optimalNumberOfRows; i++) { for (int j = 1; j <= numberOfColumns; j++) { tableCell = table.Cell(i, j); string currentKey = ""; if (counter != tableKeys.Count()) currentKey = tableKeys.ElementAt(counter); tableCell.Height = 18; tableCell.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter; tableCell.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft; tableCell.Range.Bold = 1; tableCell.Range.Font.Size = 8; tableCell.Range.Font.Name = "Arial"; if (j % 2 != 0) { tableCell.Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10; tableCell.Range.Text = currentKey; } else { tableCell.Range.Font.TextColor.RGB = ColorTranslator.ToOle(Color.FromArgb(0, 112, 192)); if (counter != tableKeys.Count()) { if (currentKey.Equals("Source")) { tableCell.Range.Hyperlinks.Add(document.Range(tableCell.Range.Start, tableCell.Range.End), data[currentKey], Type.Missing, "Source Control", data[currentKey], Type.Missing); tableCell.Range.Font.Name = "Arial"; tableCell.Range.Font.Size = 8; } else { tableCell.Range.Text = data[currentKey]; } counter++; } else { tableCell.Range.Text = ""; } } } } // split InsertTableSplit(paragraph); }