Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Create table -->Body
- Microsoft.Office.Interop.Word.Paragraph para1 = document.Content.Paragraphs.Add(ref missing);
- //nRows =5;//Number of rows
- int nRows = cats.Count + 1;
- Table firstTable = document.Tables.Add(para1.Range, nRows, 3, ref missing, ref missing);
- #region Style
- // object setStyle = Microsoft.Office.Interop.Word.WdTableFormat.wdTableFormatProfessional;
- object setStyle = "Table Professional ";
- firstTable.set_Style(ref setStyle);
- // object styleName = "Table Professional";
- // object styleName = Microsoft.Office.Interop.Word.WdTableFormat.wdTableFormatProfessional;
- // firstTable.set_Style(ref styleName);
- int tcount = 0;
- bool isfirstCellInRow = false;
- firstTable.Borders.Enable = 1;
- firstTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleEngrave3D;
- firstTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleEmboss3D;
- firstTable.TableDirection = Microsoft.Office.Interop.Word.WdTableDirection.wdTableDirectionRtl;
- firstTable.Shading.BackgroundPatternColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdAuto;
- // firstTable.PreferredWidth = Microsoft.Office.Interop.Word.;
- #endregion
- int rowcount = -1;
- foreach (Row row in firstTable.Rows)
- {
- isfirstCellInRow = true;
- foreach (Cell cell in row.Cells)
- {
- cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
- #region Fill Header ^_^
- if (cell.RowIndex == 1)
- {
- //------------------------------- Set Header
- if (cell.RowIndex == 1 && cell.ColumnIndex == 1)
- {
- cell.Range.Text = "م";
- // cell.Column.SetWidth(33f, WdRulerStyle.wdAdjustNone);
- }
- else if (cell.RowIndex == 1 && cell.ColumnIndex == 2)
- {
- cell.Range.Text = " العميل ";
- }
- else if (cell.RowIndex == 1 && cell.ColumnIndex == 3)
- {
- cell.Range.Text = "المنطقه ";
- }
- cell.Range.Font.Bold = 1;
- //other format properties goes here
- cell.Range.Font.Name = "verdana";
- cell.Range.Font.Size = 10;
- //cell.Range.Font.ColorIndex = WdColorIndex.wdGray25;
- cell.Shading.BackgroundPatternColor = WdColor.wdColorGray25;
- //Center alignment for the Header cells
- cell.VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalCenter;
- cell.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
- }
- #endregion
- //Data row
- else
- {
- //if (isfirstCellInRow)
- //{
- // cell.Range.Text = (rowcount + 1).ToString(); //(cell.RowIndex - 2 + cell.ColumnIndex).ToString();
- //}
- //else
- switch (cell.ColumnIndex)
- {
- case 1:
- cell.Range.Text = (rowcount + 1).ToString(); //(cell.RowIndex - 2 + cell.ColumnIndex).ToString();
- break;
- case 2:
- cell.Range.Text = cats[rowcount].Name;
- break;
- case 3:
- cell.Range.Text = cats[rowcount].SubDistricts;
- break;
- default:
- break;
- }
- }
- isfirstCellInRow = false;
- }
- rowcount++;
- tcount++;
- }
- #endregion
Add Comment
Please, Sign In to add comment