Guest User

Untitled

a guest
Feb 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. #region Create table -->Body
  2.  
  3.  
  4. Microsoft.Office.Interop.Word.Paragraph para1 = document.Content.Paragraphs.Add(ref missing);
  5. //nRows =5;//Number of rows
  6. int nRows = cats.Count + 1;
  7. Table firstTable = document.Tables.Add(para1.Range, nRows, 3, ref missing, ref missing);
  8. #region Style
  9.  
  10. // object setStyle = Microsoft.Office.Interop.Word.WdTableFormat.wdTableFormatProfessional;
  11. object setStyle = "Table Professional ";
  12. firstTable.set_Style(ref setStyle);
  13.  
  14.  
  15. // object styleName = "Table Professional";
  16. // object styleName = Microsoft.Office.Interop.Word.WdTableFormat.wdTableFormatProfessional;
  17. // firstTable.set_Style(ref styleName);
  18. int tcount = 0;
  19. bool isfirstCellInRow = false;
  20. firstTable.Borders.Enable = 1;
  21. firstTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleEngrave3D;
  22. firstTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleEmboss3D;
  23. firstTable.TableDirection = Microsoft.Office.Interop.Word.WdTableDirection.wdTableDirectionRtl;
  24. firstTable.Shading.BackgroundPatternColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdAuto;
  25. // firstTable.PreferredWidth = Microsoft.Office.Interop.Word.;
  26. #endregion
  27.  
  28. int rowcount = -1;
  29.  
  30. foreach (Row row in firstTable.Rows)
  31. {
  32. isfirstCellInRow = true;
  33.  
  34. foreach (Cell cell in row.Cells)
  35. {
  36. cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
  37. #region Fill Header ^_^
  38. if (cell.RowIndex == 1)
  39. {
  40. //------------------------------- Set Header
  41. if (cell.RowIndex == 1 && cell.ColumnIndex == 1)
  42. {
  43. cell.Range.Text = "م";
  44. // cell.Column.SetWidth(33f, WdRulerStyle.wdAdjustNone);
  45. }
  46. else if (cell.RowIndex == 1 && cell.ColumnIndex == 2)
  47. {
  48. cell.Range.Text = " العميل ";
  49. }
  50. else if (cell.RowIndex == 1 && cell.ColumnIndex == 3)
  51. {
  52. cell.Range.Text = "المنطقه ";
  53. }
  54.  
  55. cell.Range.Font.Bold = 1;
  56. //other format properties goes here
  57. cell.Range.Font.Name = "verdana";
  58. cell.Range.Font.Size = 10;
  59. //cell.Range.Font.ColorIndex = WdColorIndex.wdGray25;
  60. cell.Shading.BackgroundPatternColor = WdColor.wdColorGray25;
  61. //Center alignment for the Header cells
  62. cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
  63. cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
  64.  
  65. }
  66. #endregion
  67. //Data row
  68. else
  69. {
  70. //if (isfirstCellInRow)
  71. //{
  72. // cell.Range.Text = (rowcount + 1).ToString(); //(cell.RowIndex - 2 + cell.ColumnIndex).ToString();
  73. //}
  74. //else
  75. switch (cell.ColumnIndex)
  76. {
  77. case 1:
  78. cell.Range.Text = (rowcount + 1).ToString(); //(cell.RowIndex - 2 + cell.ColumnIndex).ToString();
  79. break;
  80. case 2:
  81. cell.Range.Text = cats[rowcount].Name;
  82. break;
  83. case 3:
  84. cell.Range.Text = cats[rowcount].SubDistricts;
  85. break;
  86. default:
  87. break;
  88. }
  89. }
  90.  
  91. isfirstCellInRow = false;
  92. }
  93. rowcount++;
  94. tcount++;
  95. }
  96. #endregion
Add Comment
Please, Sign In to add comment