TableCellProperties

We found 10 examples in language CSharp for this search. You will see 37 fragments of code.
        // Creates an TableCellProperties instance and adds its children.
        public TableCellProperties Create(params OpenXmlElement[] newChildren)
        {
            TableCellProperties tableCellProperties = new TableCellProperties();
            tableCellProperties.Append(newChildren);
            return tableCellProperties;
        }

		private static Drawing PictureElement(string relationshipId)
		{
			// Define the reference of the image.
			var element =
				 new Drawing(
					 new Inline(
						 new Extent() { Cx = 990000L, Cy = 792000L },
						 new EffectExtent()
						 {
							 LeftEdge = 0L,
							 TopEdge = 0L,
							 RightEdge = 0L,
							 BottomEdge = 0L
						 },
						 new DocProperties()
						 {
							 Id = (UInt32Value)1U,
							 Name = "Picture 1"
						 },
						 new NonVisualGraphicFrameDrawingProperties(
							 new A.GraphicFrameLocks() { NoChangeAspect = true }),
						 new A.Graphic(
							 new A.GraphicData(
								 new PIC.Picture(
									 new PIC.NonVisualPictureProperties(
										 new PIC.NonVisualDrawingProperties()
										 {
											 Id = (UInt32Value)0U,
											 Name = "New Bitmap Image.jpg"
										 },
										 new PIC.NonVisualPictureDrawingProperties()),
									 new PIC.BlipFill(
										 new A.Blip(
											 new A.BlipExtensionList(
												 new A.BlipExtension()
												 {
													 Uri =
													   "{28A0092B-C50C-407E-A947-70E740481C1C}"
												 })
										 )
										 {
											 Embed = relationshipId,
											 CompressionState =
											 A.BlipCompressionValues.Print
										 },
										 new A.Stretch(
											 new A.FillRectangle())),
									 new PIC.ShapeProperties(
										 new A.Transform2D(
											 new A.Offset() { X = 0L, Y = 0L },
											 new A.Extents() { Cx = 990000L, Cy = 792000L }),
										 new A.PresetGeometry(
											 new A.AdjustValueList()
										 ) { Preset = A.ShapeTypeValues.Rectangle }))
							 ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
					 )
					 {
						 DistanceFromTop = (UInt32Value)0U,
						 DistanceFromBottom = (UInt32Value)0U,
						 DistanceFromLeft = (UInt32Value)0U,
						 DistanceFromRight = (UInt32Value)0U,
						 EditId = "50D07946"
					 });
			return element;
		}
		// Creates an Paragraph instance and adds its children.
		public TableRow GenerateTableRow(IndividualInfo ii, string iid)
		{
			TableRow tableRow1 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00442AD3" };

			TableRowProperties tableRowProperties1 = new TableRowProperties();
			CantSplit cantSplit1 = new CantSplit();

			tableRowProperties1.Append(cantSplit1);

			TableCell tableCell1 = new TableCell();

			TableCellProperties tableCellProperties1 = new TableCellProperties();
			TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };

			tableCellProperties1.Append(tableCellWidth1);

			Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run1 = new Run();
			Break break1 = new Break();

			run1.Append(break1);

			Run run2 = new Run();

			RunProperties runProperties1 = new RunProperties();
			NoProof noProof1 = new NoProof();

			runProperties1.Append(noProof1);
			Text text1 = new Text();
			text1.Text = ii.FirstName;

			run2.Append(runProperties1);
			run2.Append(text1);

			Run run3 = new Run();
			Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text2.Text = " ";

			run3.Append(text2);

			Run run4 = new Run();

			RunProperties runProperties2 = new RunProperties();
			NoProof noProof2 = new NoProof();

			runProperties2.Append(noProof2);
			Text text3 = new Text();
			text3.Text = ii.LastName;

			run4.Append(runProperties2);
			run4.Append(text3);

			paragraph1.Append(run1);
			paragraph1.Append(run2);
			paragraph1.Append(run3);
			paragraph1.Append(run4);

			Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run5 = new Run();

			RunProperties runProperties3 = new RunProperties();
			NoProof noProof3 = new NoProof();

			runProperties3.Append(noProof3);
			Text text4 = new Text();
			text4.Text = ii.Address;

			run5.Append(runProperties3);
			run5.Append(text4);

			paragraph2.Append(run5);


			Paragraph paragraph2a = null;
			if (ii.Address2.HasValue())
			{
				paragraph2a = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };
				Run r = new Run();

				RunProperties rp = new RunProperties();
				NoProof np = new NoProof();

				rp.Append(np);
				Text tt = new Text();
				tt.Text = ii.Address;

				r.Append(rp);
				r.Append(tt);

				paragraph2a.Append(r);
			}


			Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run6 = new Run();

			RunProperties runProperties4 = new RunProperties();
			NoProof noProof4 = new NoProof();

			runProperties4.Append(noProof4);
			Text text5 = new Text();
			text5.Text = ii.CityStateZip;
			run6.Append(runProperties4);
			run6.Append(text5);

			paragraph3.Append(run6);

			Paragraph paragraph4 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Table table1 = new Table();

			TableProperties tableProperties1 = new TableProperties();
			TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" };
			TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };

			TableBorders tableBorders1 = new TableBorders();
			TopBorder topBorder1 = new TopBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			LeftBorder leftBorder1 = new LeftBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			BottomBorder bottomBorder1 = new BottomBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			RightBorder rightBorder1 = new RightBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };

			tableBorders1.Append(topBorder1);
			tableBorders1.Append(leftBorder1);
			tableBorders1.Append(bottomBorder1);
			tableBorders1.Append(rightBorder1);
			tableBorders1.Append(insideHorizontalBorder1);
			tableBorders1.Append(insideVerticalBorder1);
			TableLook tableLook1 = new TableLook() { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };

			tableProperties1.Append(tableStyle1);
			tableProperties1.Append(tableWidth1);
			tableProperties1.Append(tableBorders1);
			tableProperties1.Append(tableLook1);

			TableGrid tableGrid1 = new TableGrid();
			GridColumn gridColumn1 = new GridColumn() { Width = "1435" };
			GridColumn gridColumn2 = new GridColumn() { Width = "3122" };

			tableGrid1.Append(gridColumn1);
			tableGrid1.Append(gridColumn2);

			TableRow tableRow2 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell2 = new TableCell();

			TableCellProperties tableCellProperties2 = new TableCellProperties();
			TableCellWidth tableCellWidth2 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties2.Append(tableCellWidth2);

			Paragraph paragraph5 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run11 = new Run();
			Text text10 = new Text();
			text10.Text = "Email";

			run11.Append(text10);

			paragraph5.Append(run11);

			tableCell2.Append(tableCellProperties2);
			tableCell2.Append(paragraph5);

			TableCell tableCell3 = new TableCell();

			TableCellProperties tableCellProperties3 = new TableCellProperties();
			TableCellWidth tableCellWidth3 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties3.Append(tableCellWidth3);
			Paragraph paragraph6 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			paragraph6.Append(new Run(new Text(ii.Email)));

			tableCell3.Append(tableCellProperties3);
			tableCell3.Append(paragraph6);

			tableRow2.Append(tableCell2);
			tableRow2.Append(tableCell3);

			TableRow tableRow3 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell4 = new TableCell();

			TableCellProperties tableCellProperties4 = new TableCellProperties();
			TableCellWidth tableCellWidth4 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties4.Append(tableCellWidth4);

			Paragraph paragraph7 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run12 = new Run();
			Text text11 = new Text();
			text11.Text = "Home Phone";

			run12.Append(text11);

			paragraph7.Append(run12);

			tableCell4.Append(tableCellProperties4);
			tableCell4.Append(paragraph7);

			TableCell tableCell5 = new TableCell();

			TableCellProperties tableCellProperties5 = new TableCellProperties();
			TableCellWidth tableCellWidth5 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties5.Append(tableCellWidth5);

			Paragraph paragraph8 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			Run run13 = new Run();

			RunProperties runProperties7 = new RunProperties();
			NoProof noProof7 = new NoProof();

			runProperties7.Append(noProof7);
			Text text12 = new Text();
			text12.Text = ii.HomePhone.FmtFone();

			run13.Append(runProperties7);
			run13.Append(text12);

			Run run14 = new Run();
			Text text13 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text13.Text = " ";

			run14.Append(text13);

			paragraph8.Append(run13);
			paragraph8.Append(run14);

			tableCell5.Append(tableCellProperties5);
			tableCell5.Append(paragraph8);

			tableRow3.Append(tableCell4);
			tableRow3.Append(tableCell5);

			TableRow tableRow4 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell6 = new TableCell();

			TableCellProperties tableCellProperties6 = new TableCellProperties();
			TableCellWidth tableCellWidth6 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties6.Append(tableCellWidth6);

			Paragraph paragraph9 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run15 = new Run();
			Text text14 = new Text();
			text14.Text = "Cell Phone";

			run15.Append(text14);

			paragraph9.Append(run15);

			tableCell6.Append(tableCellProperties6);
			tableCell6.Append(paragraph9);

			TableCell tableCell7 = new TableCell();

			TableCellProperties tableCellProperties7 = new TableCellProperties();
			TableCellWidth tableCellWidth7 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties7.Append(tableCellWidth7);

			Paragraph paragraph10 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run16 = new Run();

			RunProperties runProperties8 = new RunProperties();
			NoProof noProof8 = new NoProof();

			runProperties8.Append(noProof8);
			Text text15 = new Text();
			text15.Text = ii.CellPhone.FmtFone();

			run16.Append(runProperties8);
			run16.Append(text15);

			paragraph10.Append(run16);

			tableCell7.Append(tableCellProperties7);
			tableCell7.Append(paragraph10);

			tableRow4.Append(tableCell6);
			tableRow4.Append(tableCell7);

			TableRow tableRow5 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell8 = new TableCell();

			TableCellProperties tableCellProperties8 = new TableCellProperties();
			TableCellWidth tableCellWidth8 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties8.Append(tableCellWidth8);

			Paragraph paragraph11 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run17 = new Run();
			Text text16 = new Text();
			text16.Text = "Work Phone";

			run17.Append(text16);

			paragraph11.Append(run17);

			tableCell8.Append(tableCellProperties8);
			tableCell8.Append(paragraph11);

			TableCell tableCell9 = new TableCell();

			TableCellProperties tableCellProperties9 = new TableCellProperties();
			TableCellWidth tableCellWidth9 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties9.Append(tableCellWidth9);

			Paragraph paragraph12 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run18 = new Run();

			RunProperties runProperties9 = new RunProperties();
			NoProof noProof9 = new NoProof();

			runProperties9.Append(noProof9);
			Text text17 = new Text();
			text17.Text = ii.WorkPhone.FmtFone();

			run18.Append(runProperties9);
			run18.Append(text17);

			paragraph12.Append(run18);

			tableCell9.Append(tableCellProperties9);
			tableCell9.Append(paragraph12);

			tableRow5.Append(tableCell8);
			tableRow5.Append(tableCell9);

			TableRow tableRow6 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell10 = new TableCell();

			TableCellProperties tableCellProperties10 = new TableCellProperties();
			TableCellWidth tableCellWidth10 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties10.Append(tableCellWidth10);

			Paragraph paragraph13 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run19 = new Run();
			Text text18 = new Text();
			text18.Text = "Birthday";

			run19.Append(text18);

			paragraph13.Append(run19);

			tableCell10.Append(tableCellProperties10);
			tableCell10.Append(paragraph13);

			TableCell tableCell11 = new TableCell();

			TableCellProperties tableCellProperties11 = new TableCellProperties();
			TableCellWidth tableCellWidth11 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties11.Append(tableCellWidth11);

			Paragraph paragraph14 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00BC57A3", RsidRunAdditionDefault = "00FB1F22" };

			Run run20 = new Run();

			RunProperties runProperties10 = new RunProperties();
			NoProof noProof10 = new NoProof();

			runProperties10.Append(noProof10);
			Text text19 = new Text();
			text19.Text = ii.BirthDay;

			run20.Append(runProperties10);
			run20.Append(text19);

			paragraph14.Append(run20);

			tableCell11.Append(tableCellProperties11);
			tableCell11.Append(paragraph14);

			tableRow6.Append(tableCell10);
			tableRow6.Append(tableCell11);

			TableRow tableRow7 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell12 = new TableCell();

			TableCellProperties tableCellProperties12 = new TableCellProperties();
			TableCellWidth tableCellWidth12 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties12.Append(tableCellWidth12);

			Paragraph paragraph15 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "006D0F9D", RsidRunAdditionDefault = "00FB1F22" };

			Run run21 = new Run();
			Text text20 = new Text();
			text20.Text = "Anniversary";

			run21.Append(text20);

			paragraph15.Append(run21);

			tableCell12.Append(tableCellProperties12);
			tableCell12.Append(paragraph15);

			TableCell tableCell13 = new TableCell();

			TableCellProperties tableCellProperties13 = new TableCellProperties();
			TableCellWidth tableCellWidth13 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties13.Append(tableCellWidth13);
			Paragraph paragraph16 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			paragraph16.Append(new Run(new Text(ii.Anniversary)));

			tableCell13.Append(tableCellProperties13);
			tableCell13.Append(paragraph16);

			tableRow7.Append(tableCell12);
			tableRow7.Append(tableCell13);

			TableRow tableRow8 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell14 = new TableCell();

			TableCellProperties tableCellProperties14 = new TableCellProperties();
			TableCellWidth tableCellWidth14 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties14.Append(tableCellWidth14);

			Paragraph paragraph17 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run22 = new Run();
			Text text21 = new Text();
			text21.Text = "Spouse";

			run22.Append(text21);

			paragraph17.Append(run22);

			tableCell14.Append(tableCellProperties14);
			tableCell14.Append(paragraph17);

			TableCell tableCell15 = new TableCell();

			TableCellProperties tableCellProperties15 = new TableCellProperties();
			TableCellWidth tableCellWidth15 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties15.Append(tableCellWidth15);

			Paragraph paragraph18 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			ParagraphProperties paragraphProperties1 = new ParagraphProperties();

			ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
			NoProof noProof11 = new NoProof();

			paragraphMarkRunProperties1.Append(noProof11);

			paragraphProperties1.Append(paragraphMarkRunProperties1);

			Run run23 = new Run();

			RunProperties runProperties11 = new RunProperties();
			NoProof noProof12 = new NoProof();

			runProperties11.Append(noProof12);
			Text text22 = new Text();
			text22.Text = ii.Spouse;

			run23.Append(runProperties11);
			run23.Append(text22);

			paragraph18.Append(paragraphProperties1);
			paragraph18.Append(run23);

			tableCell15.Append(tableCellProperties15);
			tableCell15.Append(paragraph18);

			tableRow8.Append(tableCell14);
			tableRow8.Append(tableCell15);

			table1.Append(tableProperties1);
			table1.Append(tableGrid1);
			table1.Append(tableRow2);
			table1.Append(tableRow3);
			table1.Append(tableRow4);
			table1.Append(tableRow5);
			table1.Append(tableRow6);
			table1.Append(tableRow7);
			table1.Append(tableRow8);
			Paragraph paragraph19 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			tableCell1.Append(tableCellProperties1);
			tableCell1.Append(paragraph1);
			tableCell1.Append(paragraph2);
			if (paragraph2a != null)
				tableCell1.Append(paragraph2a);
			tableCell1.Append(paragraph3);
			tableCell1.Append(paragraph4);
			tableCell1.Append(table1);
			tableCell1.Append(paragraph19);

			TableCell tableCell16 = new TableCell();

			TableCellProperties tableCellProperties16 = new TableCellProperties();
			TableCellWidth tableCellWidth16 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };
			TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };

			tableCellProperties16.Append(tableCellWidth16);
			tableCellProperties16.Append(tableCellVerticalAlignment1);
			tableCell16.Append(tableCellProperties16);

			Paragraph paragraph20 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00960953", RsidRunAdditionDefault = "00FB1F22" };
			ParagraphProperties paragraphProperties2 = new ParagraphProperties();
			Justification justification1 = new Justification() { Val = JustificationValues.Center };

			paragraphProperties2.Append(justification1);
			paragraph20.Append(paragraphProperties2);

			if (iid.HasValue())
			{
				Run run24 = new Run();

				RunProperties runProperties12 = new RunProperties();
				NoProof noProof13 = new NoProof();

				runProperties12.Append(noProof13);

				Drawing drawing1 = new Drawing();

				Wp.Inline inline1 = new Wp.Inline()
									{
										DistanceFromTop = (UInt32Value)0U,
										DistanceFromBottom = (UInt32Value)0U,
										DistanceFromLeft = (UInt32Value)0U,
										DistanceFromRight = (UInt32Value)0U
									};
				Wp.Extent extent1 = new Wp.Extent() { Cx = 1428750L, Cy = 1905000L };
				Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L };
				Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)1U, Name = "Picture 1", Description = "D:\\Pictures\\ttt.jpg" };

				Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 =
					new Wp.NonVisualGraphicFrameDrawingProperties();

				A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoChangeAspect = true };
				graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);

				A.Graphic graphic1 = new A.Graphic();
				graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };

				Pic.Picture picture1 = new Pic.Picture();
				picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");

				Pic.NonVisualPictureProperties nonVisualPictureProperties1 = new Pic.NonVisualPictureProperties();
				Pic.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Pic.NonVisualDrawingProperties()
																			 {
																				 Id = (UInt32Value)0U,
																				 Name = "Picture 459",
																				 Description = "D:\\Pictures\\ttt.jpg"
																			 };

				Pic.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 =
					new Pic.NonVisualPictureDrawingProperties();
				A.PictureLocks pictureLocks1 = new A.PictureLocks() { NoChangeAspect = false, NoChangeArrowheads = true };

				nonVisualPictureDrawingProperties1.Append(pictureLocks1);

				nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
				nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);

				Pic.BlipFill blipFill1 = new Pic.BlipFill();

				A.Blip blip1 = new A.Blip() { Embed = iid };

				A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

				A.BlipExtension blipExtension1 = new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

				A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi() { Val = false };
				useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

				blipExtension1.Append(useLocalDpi1);

				blipExtensionList1.Append(blipExtension1);

				blip1.Append(blipExtensionList1);
				A.SourceRectangle sourceRectangle1 = new A.SourceRectangle();

				A.Stretch stretch1 = new A.Stretch();
				A.FillRectangle fillRectangle1 = new A.FillRectangle();

				stretch1.Append(fillRectangle1);

				blipFill1.Append(blip1);
				blipFill1.Append(sourceRectangle1);
				blipFill1.Append(stretch1);

				Pic.ShapeProperties shapeProperties1 = new Pic.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };

				A.Transform2D transform2D1 = new A.Transform2D();
				A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
				A.Extents extents1 = new A.Extents() { Cx = 1428750L, Cy = 1905000L };

				transform2D1.Append(offset1);
				transform2D1.Append(extents1);

				A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
				A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

				presetGeometry1.Append(adjustValueList1);
				A.NoFill noFill1 = new A.NoFill();

				A.Outline outline1 = new A.Outline();
				A.NoFill noFill2 = new A.NoFill();

				outline1.Append(noFill2);

				shapeProperties1.Append(transform2D1);
				shapeProperties1.Append(presetGeometry1);
				shapeProperties1.Append(noFill1);
				shapeProperties1.Append(outline1);

				picture1.Append(nonVisualPictureProperties1);
				picture1.Append(blipFill1);
				picture1.Append(shapeProperties1);

				graphicData1.Append(picture1);

				graphic1.Append(graphicData1);

				inline1.Append(extent1);
				inline1.Append(effectExtent1);
				inline1.Append(docProperties1);
				inline1.Append(nonVisualGraphicFrameDrawingProperties1);
				inline1.Append(graphic1);

				drawing1.Append(inline1);

				run24.Append(runProperties12);
				run24.Append(drawing1);

				paragraph20.Append(run24);
			}
			tableCell16.Append(paragraph20);

			BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
			BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };

			tableRow1.Append(tableRowProperties1);
			tableRow1.Append(tableCell1);
			tableRow1.Append(tableCell16);
			tableRow1.Append(bookmarkStart1);
			tableRow1.Append(bookmarkEnd1);
			return tableRow1;
		}


        private static string CreateEmptyString(int spaceLength)
        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < spaceLength; i++)
            {
                buf.Append(Resources.Space);
            }
            return buf.ToString();
        }

        private static int GetRealColumnCount(int? columnCount)
        {
            //Underline otherwise
            int minColumnCount = 1;
            //use the larger when the maximum number of characters is greater than the default length in the free answer method
            int realColumnCount = minColumnCount;
            if (columnCount.HasValue && columnCount > minColumnCount)
            {
                realColumnCount = (int)columnCount;
            }
            return realColumnCount;
        }

        private static int GetRealRowCount(int? rowCount)
        {
            //Underline otherwise
            int minRowCount = 1;
            //use the larger when the maximum number of characters is greater than the default length in the free answer method
            int realRowCount = minRowCount;
            if (rowCount.HasValue && rowCount > minRowCount)
            {
                realRowCount = (int)rowCount;
            }
            return realRowCount;
        }

        private static int CalcBoxCellWidth(int columnCount)
        {
            return BOX_CELL_WIDTH * columnCount;
        }

        private static int CalcHalfBoxCellWidth(int columnCount)
        {
            return HALF_BOX_CELL_WIDTH * columnCount;
        }

        private static string ToPx(double val)
        {
            return val + "pt";
        }

    using (WordprocessingDocument document = WordprocessingDocument.Open(@"C:\Path\filename.docx", true))
    {
        var mainPart = document.MainDocumentPart;
        var res = from bm in mainPart.Document.Body.Descendants<BookmarkStart>()
                  where bm.Name == "BookmarkName"
                  select bm;
        var bookmark = res.SingleOrDefault();
        if (bookmark != null)
        {
            var parent = bookmark.Parent;   // bookmark's parent element
    
            // simple paragraph in one declaration
            //Paragraph newParagraph = new Paragraph(new Run(new Text("Hello, World!")));
    
            // build paragraph piece by piece
            Text text = new Text("Hello, World!");
            Run run = new Run(new RunProperties(new Bold()));
            run.Append(text);
            Paragraph newParagraph = new Paragraph(run);
    
            // insert after bookmark parent
            parent.InsertAfterSelf(newParagraph);
    
            var table = new Table(
            new TableProperties(
                new TableStyle() { Val = "TableGrid" },
                new TableWidth() { Width = 0, Type = TableWidthUnitValues.Auto }
                ),
                new TableGrid(
                    new GridColumn() { Width = (UInt32Value)1018U },
                    new GridColumn() { Width = (UInt32Value)3544U }),
            new TableRow(
                new TableCell(
                    new TableCellProperties(
                        new TableCellWidth() { Width = 0, Type = TableWidthUnitValues.Auto }),
                    new Paragraph(
                        new Run(
                            new Text("Category Name"))
                    )),
                new TableCell(
                    new TableCellProperties(
                        new TableCellWidth() { Width = 4788, Type = TableWidthUnitValues.Dxa }),
                    new Paragraph(
                        new Run(
                            new Text("Value"))
                    ))
            ),
            new TableRow(
                new TableCell(
                    new TableCellProperties(
                        new TableCellWidth() { Width = 0, Type = TableWidthUnitValues.Auto }),
                    new Paragraph(
                        new Run(
                            new Text("C1"))
                    )),
                new TableCell(
                    new TableCellProperties(
                        new TableCellWidth() { Width = 0, Type = TableWidthUnitValues.Auto }),
                    new Paragraph(
                        new Run(
                            new Text("V1"))
                    ))
            ));
    
            // insert after new paragraph
            newParagraph.InsertAfterSelf(table);
        }
    
        // close saves all parts and closes the document
        document.Close();
    }


        private static string CreateEmptyString(int spaceLength)
        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < spaceLength; i++)
            {
                buf.Append(Resources.Space);
            }
            return buf.ToString();
        }

        private static int GetRealColumnCount(int? columnCount)
        {
            //それ以外はアンダーライン
            int minColumnCount = 1;
            //自由回答方式でマックスがデフォルト長を上回っている場合それを使う
            int realColumnCount = minColumnCount;
            if (columnCount.HasValue && columnCount > minColumnCount)
            {
                realColumnCount = (int)columnCount;
            }
            return realColumnCount;
        }

        private static int GetRealRowCount(int? rowCount)
        {
            //それ以外はアンダーライン
            int minRowCount = 1;
            //自由回答方式でマックスがデフォルト長を上回っている場合それを使う
            int realRowCount = minRowCount;
            if (rowCount.HasValue && rowCount > minRowCount)
            {
                realRowCount = (int)rowCount;
            }
            return realRowCount;
        }

        private static int CalcBoxCellWidth(int columnCount)
        {
            return BOX_CELL_WIDTH * columnCount;
        }

        private static int CalcHalfBoxCellWidth(int columnCount)
        {
            return HALF_BOX_CELL_WIDTH * columnCount;
        }

        private static string ToPx(double val)
        {
            return val + "pt";
        }


        [HttpPost]
        public async Task<IActionResult> GenerateDocument([FromBody] InsuranceDocumentDetails documentDetails)
        {
            try
            {

                //string filePath = Environment.CurrentDirectory + @"\\Documents\\" + documentDetails[0].clientDetails.FamilyName.ToString().Trim() + "," + documentDetails[0].clientDetails.ClientName.ToString().Trim() + "-" + documentDetails[0].clientDetails.ClientId.ToString().Trim() + ".docx";
                MemoryStream ms = new MemoryStream();
                string _storageConnection = Configuration.GetConnectionString("StorageConnectionString");
                CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(_storageConnection);
                CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
                CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("plstorage");

                if (await cloudBlobContainer.CreateIfNotExistsAsync())
                {
                    await cloudBlobContainer.SetPermissionsAsync(new BlobContainerPermissions
                    {
                        PublicAccess = BlobContainerPublicAccessType.Blob
                    });
                }
                string filePath = documentDetails.clientDetails.FamilyName.ToString().Trim() + "," + documentDetails.clientDetails.ClientName.ToString().Trim() + "-" + documentDetails.clientDetails.ClientId.ToString().Trim() + "-Insurance.docx";

                CloudBlockBlob blockBlob = cloudBlobContainer.GetBlockBlobReference(filePath);
                using (WordprocessingDocument package = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document))
                {

                    MainDocumentPart mainPart = package.AddMainDocumentPart();
                    mainPart.Document = new Document();
                    Body body = mainPart.Document.AppendChild(new Body());
                    SectionProperties sectionProperties1 = new SectionProperties() { RsidRPr = "008818E9", RsidR = "00543A0D" };
                    FooterReference footerReference1 = new FooterReference() { Type = HeaderFooterValues.Default, Id = "rId8" };

                    sectionProperties1.Append(footerReference1);

                    body.Append(sectionProperties1);





                    NumberingDefinitionsPart numberinfPart = mainPart.AddNewPart<NumberingDefinitionsPart>("numbering");
                    Numbering element = new Numbering(new AbstractNum(new Level(new NumberingFormat() { Val = NumberFormatValues.Bullet }, new LevelText() { Val = "•" }, new LevelJustification { Val = LevelJustificationValues.Left }, new ParagraphProperties(new Indentation { Left = "720", Hanging = "360" })) { LevelIndex = 0 }) { AbstractNumberId = 0 }, new NumberingInstance(new AbstractNumId() { Val = 0 }) { NumberID = 1 });
                    element.Save(numberinfPart);

                    Color orange = new Color() { Val = "ED7D27" };

                    //Your Risk Protection

                    var clientCurrentInsurance = documentDetails.currentInsurance.Where(x => x.Owner == "Client");
                    var partnerCurrentInsurance = documentDetails.currentInsurance.Where(x => x.Owner == "Partner");

                    if (clientCurrentInsurance.Count() > 0 || partnerCurrentInsurance.Count() > 0)
                    {
                        if (clientCurrentInsurance.Count() > 0)
                        {
                                  AddRiskProtection(body, documentDetails.clientDetails, clientCurrentInsurance, orange, 0);
                        }

                        if (partnerCurrentInsurance.Count() > 0)
                        {
                                     AddRiskProtection(body, documentDetails.clientDetails, partnerCurrentInsurance, orange, 1);
                        }
                    }

                    Paragraph break2 = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
                    body.Append(break2);

                    //Paragraph pr0 = new Paragraph();
                    //add(pr0);
                    //body.Append(pr0);

                       GenerateBody(body);
                    Run br1 = new Run(new Break());
                    Paragraph pr1 = new Paragraph();
                    pr1.Append(new OpenXmlElement[] { br1 });
                    body.Append(pr1);

                       AddPara1(body);
                    //Run br2 = new Run(new Break());
                    Paragraph pr2 = new Paragraph();
                    //pr2.Append(new OpenXmlElement[] { br2 });
                    body.Append(pr2);
                        AddPara2(body);

                    //Your Insurance Needs

                    Paragraph break3 = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
                    body.Append(break3);

                    var clientNeedsAnalysis = documentDetails.needsAnalysis.Where(x => x.Owner == "Client");
                    var partnerNeedsAnalysis = documentDetails.needsAnalysis.Where(x => x.Owner == "Partner");

                    if (clientNeedsAnalysis.Count() > 0 || partnerNeedsAnalysis.Count() > 0)
                    {
                        Paragraph InsuranceNeeds = new Paragraph(new Run(new RunProperties(new Color() { Val = "ED7D27" }, new FontSize { Val = "40" }), new Text("Your Insurance Needs")));
                        body.Append(InsuranceNeeds);


                        if (clientNeedsAnalysis.Count() > 0)
                        {
                                AddInsuranceNeeds(body, clientNeedsAnalysis.ToArray(), orange, documentDetails.clientDetails.ClientName);
                        }

                        if (partnerNeedsAnalysis.Count() > 0 && documentDetails.clientDetails.MaritalStatus != "S")
                        {
                                  AddInsuranceNeeds(body, partnerNeedsAnalysis.ToArray(), orange, documentDetails.clientDetails.PartnerName);
                        }

                    }


                    //Recommended Insurance
                    body.AppendChild(break3.CloneNode(true));
                    var clientProposedInsurance = documentDetails.proposedInsurance.Where(x => x.Owner == "Client");
                    var partnerProposedInsurance = documentDetails.proposedInsurance.Where(x => x.Owner == "Partner");

                    if (clientProposedInsurance.Count() > 0 || partnerProposedInsurance.Count() > 0)
                    {
                        if (clientProposedInsurance.Count() > 0)
                        {
                                     AddRecommendedInsurance(body, documentDetails.clientDetails, clientProposedInsurance, orange, 0);
                        }

                        if (partnerProposedInsurance.Count() > 0)
                        {
                                     AddRecommendedInsurance(body, documentDetails.clientDetails, partnerProposedInsurance, orange, 1);
                        }


                              AddStandardText(body, orange);
                    }

                    //Insurance ROP

                         AddReplacementOfProduct(body, documentDetails.currentInsurance, documentDetails.proposedInsurance, documentDetails.clientDetails, orange);

                    Paragraph break4 = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
                    body.Append(break4);


                        AddImplementation(body, documentDetails.proposedInsurance, documentDetails.clientDetails, orange);

                    //Paragraph break4 = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));
                    //body.Append(break4);


                    //if (clientProposedInsurance.Count() > 0 || partnerProposedInsurance.Count() > 0)
                    //{
                    //    Paragraph InsuranceNeeds = new Paragraph(new Run(new RunProperties(new Color() { Val = "ED7D27" }, new FontSize { Val = "40" }), new Text("Insurance replacement of product")));
                    //    body.Append(InsuranceNeeds);


                    //    if (clientNeedsAnalysis.Count() > 0)
                    //    {
                    //        AddInsuranceNeeds(body, clientNeedsAnalysis.ToArray(), orange, documentDetails.clientDetails.ClientName);
                    //    }

                    //    if (partnerNeedsAnalysis.Count() > 0 && documentDetails.clientDetails.MaritalStatus != "S")
                    //    {
                    //        AddInsuranceNeeds(body, partnerNeedsAnalysis.ToArray(), orange, documentDetails.clientDetails.PartnerName);
                    //    }

                    //}

                    //Footer
                    var t = mainPart.Document.Body.Descendants<Table>().ToList();
                    var p = mainPart.Document.Body.Descendants<Paragraph>().ToList();
                    AlterTableType(t, p, package);

                    FooterPart footerPart = mainPart.AddNewPart<FooterPart>();

                    string footerPartId = mainPart.GetIdOfPart(footerPart);
                        GeneratePartContent(footerPart);

                    IEnumerable<SectionProperties> sections = mainPart.Document.Body.Elements<SectionProperties>();
                    foreach (var section in sections)
                    {
                        section.RemoveAllChildren<FooterReference>();
                        section.PrependChild<FooterReference>(new FooterReference() { Id = footerPartId });
                    }


                    package.MainDocumentPart.Document.Save();
                    package.Close();

                }


                ms.Position = 0;
                await blockBlob.UploadFromStreamAsync(ms);


                return File(ms.ToArray(), "application/octet-stream", "test");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void AddImplementation(Body body, ProposedInsuranceViewModel[] proposedInsurance, BasicDetails clientDetails, Color orange)
        {

            var implementation = new List<ProposedInsuranceViewModel>();
            var ongoing = new List<ProposedInsuranceViewModel>();

            foreach (ProposedInsuranceViewModel pI in proposedInsurance)
            {
                if (pI.Implementation.Commission > 0)
                {
                    implementation.Add(pI);
                }
                if (pI.Ongoing.Commission > 0)
                {
                    ongoing.Add(pI);
                }
            }

            if (implementation.Count() > 0 || ongoing.Count() > 0)
            {

                if (implementation.Any())
                {

                    Paragraph s1 = body.AppendChild(new Paragraph());
                    Run r1 = s1.AppendChild(new Run());
                    RunProperties runProperties1 = r1.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));
                    Color black = new Color() { Val = "000000" };
                    runProperties1.AppendChild(orange.CloneNode(true));
                    r1.AppendChild(new Text("Implementation"));

                    Paragraph p1 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("If you wish to proceed with our advice, the following table shows the costs that apply to implement our recommendations."))));

                    //New Table

                    Table table = body.AppendChild(new Table());
                    TableProperties tableProp = new TableProperties();
                    TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };

                    TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };

                    tableProp.Append(tableStyle, tableWidth);
                    table.AppendChild(tableProp);


                    ////Header
                    TableRow type = new TableRow();

                    TableCellProperties hcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties hcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties hcp2 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                    ParagraphProperties hpp = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                    ParagraphProperties hpp1 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });

                    Justification centerJustify = new Justification() { Val = JustificationValues.Center };
                    hpp1.AppendChild((Justification)centerJustify.CloneNode(true));

                    TableCellBorders hcb = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 20, Color = "ED7D27" } };

                    Shading hs1 = new Shading() { Color = "auto", Fill = "393939", Val = ShadingPatternValues.Clear };
                    TableCellMargin hcm1 = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                    hcp.Append(hcm1, hs1, hcb);
                    hcp1.Append((TableCellMargin)hcm1.CloneNode(true), (Shading)hs1.CloneNode(true), (TableCellBorders)hcb.CloneNode(true));
                    hcp2.Append((TableCellMargin)hcm1.CloneNode(true), (Shading)hs1.CloneNode(true));

                    TableCell blank = new TableCell();
                    blank.AppendChild((ParagraphProperties)hpp.CloneNode(true));
                    blank.Append((TableCellProperties)hcp2.CloneNode(true));
                    blank.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Description"))));
                    type.Append(blank);


                    TableCell h = new TableCell();
                    h.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h.Append((TableCellProperties)hcp2.CloneNode(true));
                    h.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Cost to you"))));
                    type.Append(h);

                    TableCell h1 = new TableCell();
                    h1.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h1.Append((TableCellProperties)hcp2.CloneNode(true));
                    h1.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Calculation of amounts received by us"))));
                    type.Append(h1);

                    TableCell h2 = new TableCell();
                    h2.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h2.Append((TableCellProperties)hcp2.CloneNode(true));
                    h2.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("RI Advice Group"))));
                    type.Append(h2);

                    TableCell h3 = new TableCell();
                    h3.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h3.Append((TableCellProperties)hcp2.CloneNode(true));
                    h3.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Practice"))));
                    type.Append(h3);

                    TableCell h4 = new TableCell();
                    h4.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h4.Append((TableCellProperties)hcp2.CloneNode(true));
                    h4.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Adviser"))));
                    type.Append(h4);

                    table.Append(type);


                    //Body

                    TableCellProperties tcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties tcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties tcpN = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                    TableCellBorders tcbL = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, RightBorder = new RightBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                    TableCellBorders tcbR = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, LeftBorder = new LeftBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                    TableCellBorders tcbN = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };

                    TableCellMargin tcm = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                    ParagraphProperties pp = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                    ParagraphProperties pp1 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });


                    pp1.AppendChild((Justification)centerJustify.CloneNode(true));
                    tcp.Append(tcbL, tcm);
                    tcpN.Append((TableCellBorders)tcbN.CloneNode(true), (TableCellMargin)tcm.CloneNode(true));

                    decimal totalFeeCost = 0;
                    decimal totalAdviceGroup = 0;
                    decimal totalPractice = 0;

                    foreach (ProposedInsuranceViewModel proposed in implementation)
                    {

                        TableRow heading = new TableRow();
                        TableCell bACell = new TableCell();
                        TableCellProperties tableCellProperties9 = new TableCellProperties(new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center }, new GridSpan() { Val = 6 });
                        tableCellProperties9.Append((TableCellBorders)tcbN.CloneNode(true), (TableCellMargin)tcm.CloneNode(true));
                        bACell.Append(tableCellProperties9);
                        bACell.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        bACell.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(proposed.Owner == "Client" ? clientDetails.ClientName + " - " + proposed.Provider : clientDetails.PartnerName + " - " + proposed.Provider))));
                        heading.Append(bACell);
                        table.Append(heading);

                        TableRow impDetails = new TableRow();

                        TableCell tableCell1 = new TableCell();
                        tableCell1.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tableCell1.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell1.Append(new Paragraph(new Run(new RunProperties(), new Text("Premium paid by you your super fund to insurer. Commission paid by insurer to us, after implementation of strategy"))));
                        impDetails.Append(tableCell1);

                        var feeSum = proposed.FeeDetails.Sum(x => x.Amount);
                        //verify if error
                        var adviceGroup = feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Riadvice / 100);
                        var practice = feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Practice / 100);
                        var adviser = proposed.Implementation.Adviser == 0 ? "See note above" : string.Format("{0:n0}", feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Adviser / 100));


                        totalFeeCost += feeSum;
                        totalAdviceGroup += adviceGroup;
                        totalPractice += practice;


                        TableCell tableCell2 = new TableCell();
                        tableCell2.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell2.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell2.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", feeSum)))));
                        impDetails.Append(tableCell2);

                        TableCell tableCell3 = new TableCell();
                        tableCell3.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell3.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell3.Append(new Paragraph(new Run(new RunProperties(new FontSize { Val = new StringValue("16") }), new Text(proposed.Implementation.Commission + "% of commissionable premium"))));
                        impDetails.Append(tableCell3);



                        TableCell tableCell4 = new TableCell();
                        tableCell4.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell4.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell4.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", adviceGroup)))));
                        impDetails.Append(tableCell4);

                        TableCell tableCell5 = new TableCell();
                        tableCell5.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell5.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell5.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", practice)))));
                        impDetails.Append(tableCell5);

                        TableCell tableCell6 = new TableCell();
                        tableCell6.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell6.Append((TableCellProperties)tcpN.CloneNode(true));
                        tableCell6.Append(new Paragraph(new Run(new RunProperties(), new Text(adviser))));
                        impDetails.Append(tableCell6);

                        table.Append(impDetails);


                    }


                    TableRow totalRow = new TableRow();

                    TableCell total1 = new TableCell();
                    total1.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    total1.Append((TableCellProperties)tcp.CloneNode(true));
                    total1.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("Totals"))));
                    totalRow.Append(total1);

                    TableCell total2 = new TableCell();
                    total2.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total2.Append((TableCellProperties)tcp.CloneNode(true));
                    total2.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalFeeCost)))));
                    totalRow.Append(total2);

                    TableCell total3 = new TableCell();
                    total3.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total3.Append((TableCellProperties)tcp.CloneNode(true));
                    total3.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(""))));
                    totalRow.Append(total3);

                    TableCell total4 = new TableCell();
                    total4.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total4.Append((TableCellProperties)tcp.CloneNode(true));
                    total4.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalAdviceGroup)))));
                    totalRow.Append(total4);

                    TableCell total5 = new TableCell();
                    total5.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total5.Append((TableCellProperties)tcp.CloneNode(true));
                    total5.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalPractice)))));
                    totalRow.Append(total5);

                    TableCell total6 = new TableCell();
                    total6.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total6.Append((TableCellProperties)tcpN.CloneNode(true));
                    total6.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(""))));
                    totalRow.Append(total6);


                    table.Append(totalRow);
                }

                if (ongoing.Any())
                {

                    Run br2 = new Run(new Break());
                    Paragraph pr2 = new Paragraph();
                    pr2.Append(new OpenXmlElement[] { br2 });
                    body.Append(pr2);

                    Paragraph s1 = body.AppendChild(new Paragraph());
                    Run r1 = s1.AppendChild(new Run());
                    RunProperties runProperties1 = r1.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));
                    Color black = new Color() { Val = "000000" };
                    runProperties1.AppendChild(orange.CloneNode(true));
                    r1.AppendChild(new Text("Ongoing advice"));

                    Paragraph p1 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("The following table shows the ongoing costs. All fees are shown as annual amounts."))));

                    //New Table

                    Table table = body.AppendChild(new Table());
                    TableProperties tableProp = new TableProperties();
                    TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };

                    TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };

                    tableProp.Append(tableStyle, tableWidth);
                    table.AppendChild(tableProp);


                    ////Header
                    TableRow type = new TableRow();

                    TableCellProperties hcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties hcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties hcp2 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                    ParagraphProperties hpp = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                    ParagraphProperties hpp1 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });

                    Justification centerJustify = new Justification() { Val = JustificationValues.Center };
                    hpp1.AppendChild((Justification)centerJustify.CloneNode(true));

                    TableCellBorders hcb = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 20, Color = "ED7D27" } };

                    Shading hs1 = new Shading() { Color = "auto", Fill = "393939", Val = ShadingPatternValues.Clear };
                    TableCellMargin hcm1 = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                    hcp.Append(hcm1, hs1, hcb);
                    hcp1.Append((TableCellMargin)hcm1.CloneNode(true), (Shading)hs1.CloneNode(true), (TableCellBorders)hcb.CloneNode(true));
                    hcp2.Append((TableCellMargin)hcm1.CloneNode(true), (Shading)hs1.CloneNode(true));

                    TableCell blank = new TableCell();
                    blank.AppendChild((ParagraphProperties)hpp.CloneNode(true));
                    blank.Append((TableCellProperties)hcp2.CloneNode(true));
                    blank.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Description"))));
                    type.Append(blank);


                    TableCell h = new TableCell();
                    h.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h.Append((TableCellProperties)hcp2.CloneNode(true));
                    h.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Cost to you"))));
                    type.Append(h);

                    TableCell h1 = new TableCell();
                    h1.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h1.Append((TableCellProperties)hcp2.CloneNode(true));
                    h1.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Calculation of amounts received by us"))));
                    type.Append(h1);

                    TableCell h2 = new TableCell();
                    h2.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h2.Append((TableCellProperties)hcp2.CloneNode(true));
                    h2.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("RI Advice Group"))));
                    type.Append(h2);

                    TableCell h3 = new TableCell();
                    h3.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h3.Append((TableCellProperties)hcp2.CloneNode(true));
                    h3.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Practice"))));
                    type.Append(h3);

                    TableCell h4 = new TableCell();
                    h4.AppendChild((ParagraphProperties)hpp1.CloneNode(true));
                    h4.Append((TableCellProperties)hcp2.CloneNode(true));
                    h4.Append(new Paragraph(new Run(new RunProperties(new Bold(), new FontSize { Val = new StringValue("16") }), new Text("Adviser"))));
                    type.Append(h4);

                    table.Append(type);


                    //Body

                    TableCellProperties tcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties tcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                    TableCellProperties tcpN = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                    TableCellBorders tcbL = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, RightBorder = new RightBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                    TableCellBorders tcbR = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, LeftBorder = new LeftBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                    TableCellBorders tcbN = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };

                    TableCellMargin tcm = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                    ParagraphProperties pp = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                    ParagraphProperties pp1 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });


                    pp1.AppendChild((Justification)centerJustify.CloneNode(true));
                    tcp.Append(tcbL, tcm);
                    tcpN.Append((TableCellBorders)tcbN.CloneNode(true), (TableCellMargin)tcm.CloneNode(true));

                    decimal totalFeeCost = 0;
                    decimal totalAdviceGroup = 0;
                    decimal totalPractice = 0;

                    foreach (ProposedInsuranceViewModel proposed in ongoing)
                    {

                        TableRow heading = new TableRow();
                        TableCell bACell = new TableCell();
                        TableCellProperties tableCellProperties9 = new TableCellProperties(new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center }, new GridSpan() { Val = 6 });
                        tableCellProperties9.Append((TableCellBorders)tcbN.CloneNode(true), (TableCellMargin)tcm.CloneNode(true));
                        bACell.Append(tableCellProperties9);
                        bACell.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        bACell.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(proposed.Owner == "Client" ? clientDetails.ClientName + " - " + proposed.Provider : clientDetails.PartnerName + " - " + proposed.Provider))));
                        heading.Append(bACell);
                        table.Append(heading);

                        TableRow impDetails = new TableRow();

                        TableCell tableCell1 = new TableCell();
                        tableCell1.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tableCell1.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell1.Append(new Paragraph(new Run(new RunProperties(), new Text("Premium paid by you your super fund to insurer. Commission paid by insurer to us, after implementation of strategy"))));
                        impDetails.Append(tableCell1);

                        var feeSum = proposed.FeeDetails.Sum(x => x.Amount);
                        //verify if error
                        var adviceGroup = feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Riadvice / 100);
                        var practice = feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Practice / 100);
                        var adviser = proposed.Implementation.Adviser == 0 ? "See note above" : string.Format("{0:n0}", feeSum * (proposed.Implementation.Commission / 100) * (proposed.Implementation.Adviser / 100));


                        totalFeeCost += feeSum;
                        totalAdviceGroup += adviceGroup;
                        totalPractice += practice;


                        TableCell tableCell2 = new TableCell();
                        tableCell2.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell2.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell2.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", feeSum)))));
                        impDetails.Append(tableCell2);

                        TableCell tableCell3 = new TableCell();
                        tableCell3.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell3.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell3.Append(new Paragraph(new Run(new RunProperties(new FontSize { Val = new StringValue("16") }), new Text(proposed.Implementation.Commission + "% of commissionable premium"))));
                        impDetails.Append(tableCell3);



                        TableCell tableCell4 = new TableCell();
                        tableCell4.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell4.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell4.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", adviceGroup)))));
                        impDetails.Append(tableCell4);

                        TableCell tableCell5 = new TableCell();
                        tableCell5.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell5.Append((TableCellProperties)tcp.CloneNode(true));
                        tableCell5.Append(new Paragraph(new Run(new RunProperties(), new Text(string.Format("{0:n0}", practice)))));
                        impDetails.Append(tableCell5);

                        TableCell tableCell6 = new TableCell();
                        tableCell6.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tableCell6.Append((TableCellProperties)tcpN.CloneNode(true));
                        tableCell6.Append(new Paragraph(new Run(new RunProperties(), new Text(adviser))));
                        impDetails.Append(tableCell6);

                        table.Append(impDetails);


                    }


                    TableRow totalRow = new TableRow();

                    TableCell total1 = new TableCell();
                    total1.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    total1.Append((TableCellProperties)tcp.CloneNode(true));
                    total1.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("Totals"))));
                    totalRow.Append(total1);

                    TableCell total2 = new TableCell();
                    total2.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total2.Append((TableCellProperties)tcp.CloneNode(true));
                    total2.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalFeeCost)))));
                    totalRow.Append(total2);

                    TableCell total3 = new TableCell();
                    total3.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total3.Append((TableCellProperties)tcp.CloneNode(true));
                    total3.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(""))));
                    totalRow.Append(total3);

                    TableCell total4 = new TableCell();
                    total4.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total4.Append((TableCellProperties)tcp.CloneNode(true));
                    total4.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalAdviceGroup)))));
                    totalRow.Append(total4);

                    TableCell total5 = new TableCell();
                    total5.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total5.Append((TableCellProperties)tcp.CloneNode(true));
                    total5.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text("$" + string.Format("{0:n0}", totalPractice)))));
                    totalRow.Append(total5);

                    TableCell total6 = new TableCell();
                    total6.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    total6.Append((TableCellProperties)tcpN.CloneNode(true));
                    total6.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(""))));
                    totalRow.Append(total6);


                    table.Append(totalRow);
                }
            }


        }

        private void AddStandardText(Body body, Color orange)
        {
            Paragraph s1 = body.AppendChild(new Paragraph());
            Run r1 = s1.AppendChild(new Run());
            RunProperties runProperties1 = r1.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));
            Color black = new Color() { Val = "000000" };
            runProperties1.AppendChild(orange.CloneNode(true));
            r1.AppendChild(new Text("Other important information"));

            Paragraph p1 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("The recommended insurance cover may have exclusions applied, be loaded (higher premiums) or be declined depending on the outcome of underwriting."))));
            Paragraph p2 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("A death benefit will not be paid in the first 13 months of your life policy in the event of death by suicide."))));
            Paragraph p3 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("Your policy has a cooling off period which allows you to cancel your cover and receive a refund of premiums paid. Please refer to the PDS for details."))));


            Paragraph s2 = body.AppendChild(new Paragraph());
            Run r2 = s2.AppendChild(new Run());
            RunProperties runProperties2 = r2.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));

            runProperties2.AppendChild(orange.CloneNode(true));
            r2.AppendChild(new Text("Your duty of disclosure"));

            Paragraph p5 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("Before you apply for, extend, renew, vary or reinstate your insurance, it is important that you understand your duty of disclosure. The key elements are:"))));

            Paragraph commentary = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("You have a duty under law to disclose to the insurer every matter you know or could reasonably be expected to know that is relevant to their decision to accept your insurance application."))));
            Paragraph commentary1 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("You must provide all the information requested by the insurer. Your duty could also extend beyond the questions in the insurance application form."))));
            Paragraph commentary2 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("Your duty continues until the insurance application is accepted. You will need to disclose any relevant changes in your circumstances that occur before the insurance policy is issued."))));
            Paragraph commentary3 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("If you do not comply with your duty of disclosure, in some circumstances, your insurance may be avoided or varied, or future claims may be affected or denied. "))));

            Paragraph p6 = body.AppendChild(new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("Please refer to the relevant PDS for full details about your duty of disclosure."))));

            //Paragraph br = body.AppendChild(new Paragraph(new Run(new Break())));

            Paragraph s3 = body.AppendChild(new Paragraph());
            Run r3 = s3.AppendChild(new Run());
            RunProperties runProperties3 = r3.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));

            runProperties3.AppendChild(orange.CloneNode(true));
            r3.AppendChild(new Text("Product Disclosure Statement of retained policies"));

            Color red = new Color() { Val = "FF0000" };

            Paragraph p7 = new Paragraph(new Run(new RunProperties(new Color() { Val = "000000" }), new Text("Please read the following Product Disclosure Statement (PDS) for further information on your retained insurance ")));
            p7.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = " [policy/ies:] ", Space = SpaceProcessingModeValues.Preserve }));
            body.Append(p7);

            Paragraph commentary4 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[PDS name here]"))));

        }

        private void AddStandardTextROP(Body body, Color orange)
        {
            Paragraph s1 = body.AppendChild(new Paragraph());
            Run r1 = s1.AppendChild(new Run());
            RunProperties runProperties1 = r1.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));
            Color black = new Color() { Val = "000000" };
            runProperties1.AppendChild(orange.CloneNode(true));
            Color red = new Color() { Val = "FF0000" };
            r1.AppendChild(new Text("Product replacement recommendations"));


            Paragraph commentary = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("Based on our research and your needs and objectives, our recommendation is to replace your current insurance product."))));
            Paragraph commentary1 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[Recommended product]"))));
            commentary1.Append(new Run(new RunProperties(), new Text { Text = " was deemed appropriate for you because: ", Space = SpaceProcessingModeValues.Preserve }));

            Paragraph commentary2 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new Indentation() { Left = "1080" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[If superior features]"))));
            commentary2.Append(new Run(new RunProperties(), new Text { Text = " It provides you with additional features. ", Space = SpaceProcessingModeValues.Preserve }));

            Paragraph commentary3 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new Indentation() { Left = "1080" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[If lower premiums]"))));
            commentary3.Append(new Run(new RunProperties(), new Text { Text = " You will benefit from lower premiums. ", Space = SpaceProcessingModeValues.Preserve }));


            Paragraph commentary6 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("In making this recommendation, we compared "))));
            commentary6.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = " recommended product ", Space = SpaceProcessingModeValues.Preserve }));
            commentary6.Append(new Run(new RunProperties(), new Text { Text = "to the following other products in the market: ", Space = SpaceProcessingModeValues.Preserve }));

            Paragraph commentary7 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new Indentation() { Left = "1080" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[Alternative product 1]"))));
            commentary7.Append(new Run(new RunProperties(), new Text { Text = " could ", Space = SpaceProcessingModeValues.Preserve }));
            commentary7.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = "[save you $XXX in annual costs and you would benefit from XXX features.]  ", Space = SpaceProcessingModeValues.Preserve }));
            commentary7.Append(new Run(new RunProperties(), new Text { Text = "However we disregarded this product because ", Space = SpaceProcessingModeValues.Preserve }));
            commentary7.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = "[you specifically stated you wanted the XXX product.] ", Space = SpaceProcessingModeValues.Preserve }));

            Paragraph commentary8 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new Indentation() { Left = "1080" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties((Color)red.CloneNode(true)), new Text("[Alternative product 2]"))));
            commentary8.Append(new Run(new RunProperties(), new Text { Text = " offers ", Space = SpaceProcessingModeValues.Preserve }));
            commentary8.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = "[XXX features which could benefit you]", Space = SpaceProcessingModeValues.Preserve }));
            commentary8.Append(new Run(new RunProperties(), new Text { Text = ", however we disregarded this product because ", Space = SpaceProcessingModeValues.Preserve }));
            commentary8.Append(new Run(new RunProperties((Color)red.CloneNode(true)), new Text { Text = "[the annual costs are around $XXX more than XXX recommended product and this is more than you want to pay.] ", Space = SpaceProcessingModeValues.Preserve }));


            Paragraph s3 = body.AppendChild(new Paragraph());
            Run r3 = s3.AppendChild(new Run());
            RunProperties runProperties3 = r3.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));

            // runProperties3.AppendChild(orange.CloneNode(true));
            r3.AppendChild(new Text("Important note:"));

            Paragraph commentary4 = body.AppendChild(new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("You should maintain your existing cover until the new policy is established, and all waiting periods are served, to ensure you have continuous cover. This could mean you are paying multiple premiums for a period of time. Once your new policy is in place and all waiting periods have been satisfied, the old policy can be cancelled."))));
            Paragraph commentary5 = new Paragraph(new ParagraphProperties(new ParagraphStyleId() { Val = "ListParagraph" }, new NumberingProperties(new NumberingLevelReference() { Val = 0 }, new NumberingId() { Val = 1 })), new Run(new RunProperties(), new Text("A policy that has been in force for three years or longer may have a greater level of protection against avoidance by an insurer if the duty of disclosure is breached or innocent misrepresentation occurs.")));
            commentary5.Append(new Run(new RunProperties(new Bold()), new Text { Text = " Cancelling your existing cover to take out new cover will restart this three year period where the insurer could avoid your policy if innocent non-disclosure or misrepresentation occurs.", Space = SpaceProcessingModeValues.Preserve }));
            body.Append(commentary5);
        }

        private void AddRecommendedInsurance(Body body, BasicDetails clientDetails, IEnumerable<ProposedInsuranceViewModel> clientProposedInsurance, Color orange, int v)
        {
            Paragraph break3 = new Paragraph(new Run(new Break() { Type = BreakValues.Page }));

            Paragraph s1 = body.AppendChild(new Paragraph());
            Run r1 = s1.AppendChild(new Run());
            RunProperties runProperties1 = r1.AppendChild(new RunProperties(new Bold(), new RunFonts { Ascii = "Verdana" }, new FontSize { Val = new StringValue("20") }));
            Color black = new Color() { Val = "000000" };
            runProperties1.AppendChild(orange.CloneNode(true));

            if (v == 0)
            {
                r1.AppendChild(new Text("Recommended Insurance cover for " + clientDetails.ClientName));
            }
            else
            {
                r1.AppendChild(new Text("Recommended Insurance cover for " + clientDetails.PartnerName));
            }


            foreach (ProposedInsuranceViewModel proposed in clientProposedInsurance)
            //New Table
            {
                Table table = body.AppendChild(new Table());
                TableProperties tableProp = new TableProperties();
                TableStyle tableStyle = new TableStyle() { Val = "TableGrid" };

                TableWidth tableWidth = new TableWidth() { Width = "5000", Type = TableWidthUnitValues.Pct };

                tableProp.Append(tableStyle, tableWidth);
                table.AppendChild(tableProp);


                ////Header
                TableRow header = new TableRow();
                TableCell h1 = new TableCell();

                TableCellProperties hcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                TableCellProperties hcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                ParagraphProperties hppLeft = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                ParagraphProperties hppCenter = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });
                ParagraphProperties hppRight = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "5" });

                Justification centerJustify = new Justification() { Val = JustificationValues.Center };
                hppCenter.AppendChild((Justification)centerJustify.CloneNode(true));

                Justification rightJustify = new Justification() { Val = JustificationValues.Right };
                hppRight.AppendChild((Justification)rightJustify.CloneNode(true));

                Justification leftJustify = new Justification() { Val = JustificationValues.Left };

                TableCellBorders hcb = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 20, Color = "ED7D27" } };

                Shading hs1 = new Shading() { Color = "auto", Fill = "393939", Val = ShadingPatternValues.Clear };
                TableCellMargin hcm1 = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                hcp.Append(hcm1, hs1, hcb);
                //hcp1.Append((TableCellMargin)hcm1.CloneNode(true), (Shading)hs1.CloneNode(true), (TableCellBorders)hcb.CloneNode(true));
                h1.Append(hcp);

                h1.AppendChild((ParagraphProperties)hppLeft.CloneNode(true));

                var heading = "";
                if (proposed.ReplacementId == 0)
                {
                    heading = "Purchase";
                }
                else
                {
                    heading = "";
                }

                h1.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(heading))));

                TableCell h2 = new TableCell();
                h2.AppendChild((ParagraphProperties)hppCenter.CloneNode(true));
                h2.Append((TableCellProperties)hcp.CloneNode(true));
                h2.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(proposed.Provider))));

                TableCell h3 = new TableCell();
                h3.AppendChild((ParagraphProperties)hppCenter.CloneNode(true));
                h3.Append((TableCellProperties)hcp.CloneNode(true));
                h3.Append(new Paragraph(new Run(new RunProperties(new Bold()), new Text(""))));
                header.Append(h1, h2, h3);

                table.Append(header);
                //Body
                TableCellProperties tcp1 = new TableCellProperties(new TableCellWidth { Width = "2390", Type = TableWidthUnitValues.Auto }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                TableCellProperties tcp = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });
                TableCellProperties tcpN = new TableCellProperties(new TableCellWidth { Width = "2000", Type = TableWidthUnitValues.Pct }, new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center });

                TableCellBorders tcbL = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, RightBorder = new RightBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                TableCellBorders tcbR = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, LeftBorder = new LeftBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };
                TableCellBorders tcbN = new TableCellBorders() { BottomBorder = new BottomBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" }, TopBorder = new TopBorder() { Val = BorderValues.Single, Size = 1, Color = "D3D3D3" } };

                TableCellMargin tcm = new TableCellMargin() { RightMargin = new RightMargin() { Width = "50", Type = TableWidthUnitValues.Dxa }, LeftMargin = new LeftMargin() { Width = "50", Type = TableWidthUnitValues.Dxa } };

                ParagraphProperties pp = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "0" });
                ParagraphProperties pp1 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "0" });
                ParagraphProperties pp2 = new ParagraphProperties(new ParagraphStyleId() { Val = "No Spacing" }, new SpacingBetweenLines() { After = "0" });

                pp2.AppendChild((Justification)rightJustify.CloneNode(true));
                pp.AppendChild((Justification)leftJustify.CloneNode(true));
                tcp.Append(tcbL, tcm);
                tcpN.Append((TableCellBorders)tcbN.CloneNode(true), (TableCellMargin)tcm.CloneNode(true));


                if (proposed.LifeCover.Count() > 0)
                {

                    TableRow mtr = new TableRow();
                    TableCell mtc1 = new TableCell();

                    tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                    mtc1.Append((TableCellProperties)tcp.CloneNode(true));
                    mtc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    mtc1.Append(new Paragraph(new Run(new Text(""))));

                    TableCell mtc2 = new TableCell();
                    mtc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc2.Append((TableCellProperties)tcp1.CloneNode(true));
                    mtc2.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Cover Type")))));

                    TableCell mtc3 = new TableCell();
                    mtc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc3.Append((TableCellProperties)tcpN.CloneNode(true));
                    mtc3.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Life")))));

                    mtr.Append(mtc1, mtc2, mtc3);

                    table.AppendChild(mtr);

                    if (proposed.LifeCover.First().PolicyOwner != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Policy Owner"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.LifeCover.First().PolicyOwner == "Client" ? clientDetails.ClientName : (proposed.LifeCover.First().PolicyOwner == "Partner" ? clientDetails.PartnerName : "Super Fund")))));



                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.LifeCover.First().BenefitAmount != 0)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Benefit Amount"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text("$" + String.Format("{0:n}", proposed.LifeCover.First().BenefitAmount.ToString())))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.LifeCover.First().PremiumType != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Premium Type"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.LifeCover.First().PremiumType))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.LifeCover.First().WithinSuper < 2)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Super"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.LifeCover.First().WithinSuper == 1 ? "Yes" : "No"))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                }

                if (proposed.TpdCover.Count() > 0)
                {

                    TableRow mtr = new TableRow();
                    TableCell mtc1 = new TableCell();

                    tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                    mtc1.Append((TableCellProperties)tcp.CloneNode(true));
                    mtc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    mtc1.Append(new Paragraph(new Run(new Text(""))));

                    TableCell mtc2 = new TableCell();
                    mtc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc2.Append((TableCellProperties)tcp1.CloneNode(true));
                    mtc2.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Cover Type")))));

                    TableCell mtc3 = new TableCell();
                    mtc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc3.Append((TableCellProperties)tcpN.CloneNode(true));
                    mtc3.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("TPD")))));

                    mtr.Append(mtc1, mtc2, mtc3);

                    table.AppendChild(mtr);

                    if (proposed.TpdCover.First().PolicyOwner != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Policy Owner"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TpdCover.First().PolicyOwner == "Client" ? clientDetails.ClientName : (proposed.TpdCover.First().PolicyOwner == "Partner" ? clientDetails.PartnerName : "Super Fund")))));


                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.TpdCover.First().BenefitAmount != 0)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Benefit Amount"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text("$" + String.Format("{0:n}", proposed.TpdCover.First().BenefitAmount.ToString())))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.TpdCover.First().Definition != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Definition"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TpdCover.First().Definition))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.TpdCover.First().StandaloneOrLinked != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Stand Alone / Linked"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TpdCover.First().StandaloneOrLinked))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.TpdCover.First().PremiumType != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Premium Type"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TpdCover.First().PremiumType))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.TpdCover.First().WithinSuper != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Super"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TpdCover.First().WithinSuper))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                }

                if (proposed.TraumaCover.Count() > 0)
                {

                    TableRow mtr = new TableRow();
                    TableCell mtc1 = new TableCell();

                    tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                    mtc1.Append((TableCellProperties)tcp.CloneNode(true));
                    mtc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    mtc1.Append(new Paragraph(new Run(new Text(""))));

                    TableCell mtc2 = new TableCell();
                    mtc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc2.Append((TableCellProperties)tcp1.CloneNode(true));
                    mtc2.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Cover Type")))));

                    TableCell mtc3 = new TableCell();
                    mtc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc3.Append((TableCellProperties)tcpN.CloneNode(true));
                    mtc3.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Trauma")))));

                    mtr.Append(mtc1, mtc2, mtc3);

                    table.AppendChild(mtr);

                    if (proposed.TraumaCover.First().PolicyOwner != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Policy Owner"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TraumaCover.First().PolicyOwner == "Client" ? clientDetails.ClientName : (proposed.TraumaCover.First().PolicyOwner == "Partner" ? clientDetails.PartnerName : "Super Fund")))));


                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.TraumaCover.First().BenefitAmount != 0)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Benefit Amount"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text("$" + String.Format("{0:n}", proposed.TraumaCover.First().BenefitAmount.ToString())))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }


                    if (proposed.TraumaCover.First().StandaloneOrLinked != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Stand Alone / Linked"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TraumaCover.First().StandaloneOrLinked))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.TraumaCover.First().PremiumType != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Premium Type"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TraumaCover.First().PremiumType))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.TraumaCover.First().WithinSuper != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Super"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.TraumaCover.First().WithinSuper))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                }

                if (proposed.IncomeCover.Count() > 0)
                {

                    TableRow mtr = new TableRow();
                    TableCell mtc1 = new TableCell();

                    tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                    mtc1.Append((TableCellProperties)tcp.CloneNode(true));
                    mtc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                    mtc1.Append(new Paragraph(new Run(new Text(""))));

                    TableCell mtc2 = new TableCell();
                    mtc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc2.Append((TableCellProperties)tcp1.CloneNode(true));
                    mtc2.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Cover Type")))));

                    TableCell mtc3 = new TableCell();
                    mtc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                    mtc3.Append((TableCellProperties)tcpN.CloneNode(true));
                    mtc3.Append(new Paragraph(new Run(new Run(new RunProperties(new Bold()), new Text("Income Protection")))));

                    mtr.Append(mtc1, mtc2, mtc3);

                    table.AppendChild(mtr);

                    if (proposed.IncomeCover.First().PolicyOwner != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Policy Owner"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().PolicyOwner == "Client" ? clientDetails.ClientName : (proposed.IncomeCover.First().PolicyOwner == "Partner" ? clientDetails.PartnerName : "Super Fund")))));


                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.IncomeCover.First().MonthlyBenefitAmount != 0)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Benefit Amount"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text("$" + String.Format("{0:n}", proposed.IncomeCover.First().MonthlyBenefitAmount.ToString())))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }

                    if (proposed.IncomeCover.First().Definition != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Definition"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().Definition))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.IncomeCover.First().WaitingPeriod != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Waiting Period"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().WaitingPeriod))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.IncomeCover.First().BenefitPeriod != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Benefit Period"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().BenefitPeriod))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.IncomeCover.First().PremiumType != "")
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Premium Type"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().PremiumType))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                    if (proposed.IncomeCover.First().WithinSuper < 2)
                    {
                        TableRow tr = new TableRow();
                        TableCell tc1 = new TableCell();

                        tcp1.Append((TableCellBorders)tcbL.CloneNode(true), (TableCellMargin)tcm.CloneNode(true), (Justification)centerJustify.CloneNode(true));
                        tc1.Append((TableCellProperties)tcp.CloneNode(true));
                        tc1.AppendChild((ParagraphProperties)pp1.CloneNode(true));
                        tc1.Append(new Paragraph(new Run(new Text(""))));

                        TableCell tc2 = new TableCell();
                        tc2.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc2.Append((TableCellProperties)tcp1.CloneNode(true));
                        tc2.Append(new Paragraph(new Run(new Text("Super"))));

                        TableCell tc3 = new TableCell();
                        tc3.AppendChild((ParagraphProperties)pp.CloneNode(true));
                        tc3.Append((TableCellProperties)tcpN.CloneNode(true));
                        tc3.Append(new Paragraph(new Run(new Text(proposed.IncomeCover.First().WithinSuper == 1 ? "Yes" : "No"))));

                        tr.Append(tc1, tc2, tc3);

                        table.AppendChild(tr);
                    }
                }


                Run linebreak = new Run(new Break());
                Paragraph productCost = new Paragraph();
                productCost.Append(new OpenXmlElement[] { (Run)linebreak.CloneNode(true), new Run(new RunProperties(new Bold()), new Text("Please note the following: ")) });
                body.Append(productCost);

            }
        }

        private void add(Paragraph body)
        {
            AlternateContentChoice alternateContentChoice1 = new AlternateContentChoice() { Requires = "wps" };

            W.Drawing drawing1 = new W.Drawing();

            Wp.Anchor anchor1 = new Wp.Anchor() { DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, DistanceFromLeft = (UInt32Value)114935U, DistanceFromRight = (UInt32Value)114935U, SimplePos = false, RelativeHeight = (UInt32Value)251676672U, BehindDoc = true, Locked = false, LayoutInCell = true, AllowOverlap = true, EditId = "3A313D92", AnchorId = "5438FE6E" };
            Wp.SimplePosition simplePosition1 = new Wp.SimplePosition() { X = 0L, Y = 0L };

            Wp.HorizontalPosition horizontalPosition1 = new Wp.HorizontalPosition() { RelativeFrom = Wp.HorizontalRelativePositionValues.Column };
            Wp.PositionOffset positionOffset1 = new Wp.PositionOffset();
            positionOffset1.Text = "6030595";

            horizontalPosition1.Append(positionOffset1);

            Wp.VerticalPosition verticalPosition1 = new Wp.VerticalPosition() { RelativeFrom = Wp.VerticalRelativePositionValues.Paragraph };
            Wp.PositionOffset positionOffset2 = new Wp.PositionOffset();
            positionOffset2.Text = "97155";

            verticalPosition1.Append(positionOffset2);
            Wp.Extent extent1 = new Wp.Extent() { Cx = 35560L, Cy = 13970L };
            Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 8255L, TopEdge = 5715L, RightEdge = 3810L, BottomEdge = 8890L };
            Wp.WrapNone wrapNone1 = new Wp.WrapNone();
            Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)92U, Name = "Text Box 92" };

            Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 = new Wp.NonVisualGraphicFrameDrawingProperties();

            A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks();
            graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

            nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);

            A.Graphic graphic1 = new A.Graphic();
            graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

            A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape" };

            Wps.WordprocessingShape wordprocessingShape1 = new Wps.WordprocessingShape();

            Wps.NonVisualDrawingShapeProperties nonVisualDrawingShapeProperties1 = new Wps.NonVisualDrawingShapeProperties() { TextBox = true };
            A.ShapeLocks shapeLocks1 = new A.ShapeLocks() { NoChangeArrowheads = true };

            nonVisualDrawingShapeProperties1.Append(shapeLocks1);

            Wps.ShapeProperties shapeProperties1 = new Wps.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };

            A.Transform2D transform2D1 = new A.Transform2D();
            A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
            A.Extents extents1 = new A.Extents() { Cx = 35560L, Cy = 13970L };

            transform2D1.Append(offset1);
            transform2D1.Append(extents1);

            A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
            A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

            presetGeometry1.Append(adjustValueList1);

            A.SolidFill solidFill1 = new A.SolidFill();

            A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = "FFFFFF" };
            A.Alpha alpha1 = new A.Alpha() { Val = 0 };

            rgbColorModelHex1.Append(alpha1);

            solidFill1.Append(rgbColorModelHex1);

            A.Outline outline1 = new A.Outline();
            A.NoFill noFill1 = new A.NoFill();

            outline1.Append(noFill1);

            A.ShapePropertiesExtensionList shapePropertiesExtensionList1 = new A.ShapePropertiesExtensionList();

            A.ShapePropertiesExtension shapePropertiesExtension1 = new A.ShapePropertiesExtension() { Uri = "{91240B29-F687-4F45-9708-019B960494DF}" };

            A14.HiddenLineProperties hiddenLineProperties1 = new A14.HiddenLineProperties() { Width = 9525 };
            hiddenLineProperties1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

            A.SolidFill solidFill2 = new A.SolidFill();
            A.RgbColorModelHex rgbColorModelHex2 = new A.RgbColorModelHex() { Val = "000000" };

            solidFill2.Append(rgbColorModelHex2);
            A.Miter miter1 = new A.Miter() { Limit = 800000 };
            A.HeadEnd headEnd1 = new A.HeadEnd();
            A.TailEnd tailEnd1 = new A.TailEnd();

            hiddenLineProperties1.Append(solidFill2);
            hiddenLineProperties1.Append(miter1);
            hiddenLineProperties1.Append(headEnd1);
            hiddenLineProperties1.Append(tailEnd1);

            shapePropertiesExtension1.Append(hiddenLineProperties1);

            shapePropertiesExtensionList1.Append(shapePropertiesExtension1);

            shapeProperties1.Append(transform2D1);
            shapeProperties1.Append(presetGeometry1);
            shapeProperties1.Append(solidFill1);
            shapeProperties1.Append(outline1);
            shapeProperties1.Append(shapePropertiesExtensionList1);

            Wps.TextBoxInfo2 textBoxInfo21 = new Wps.TextBoxInfo2();

            W.TextBoxContent textBoxContent1 = new W.TextBoxContent();

            W.Paragraph paragraph1 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "04CE03A0", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties1 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId1 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties1 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts1 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold1 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript1 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties1.Append(runFonts1);
            paragraphMarkRunProperties1.Append(bold1);
            paragraphMarkRunProperties1.Append(fontSizeComplexScript1);

            paragraphProperties1.Append(paragraphStyleId1);
            paragraphProperties1.Append(paragraphMarkRunProperties1);

            W.Run run1 = new W.Run();

            W.RunProperties runProperties1 = new W.RunProperties();
            W.RunFonts runFonts2 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold2 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript2 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties1.Append(runFonts2);
            runProperties1.Append(bold2);
            runProperties1.Append(fontSizeComplexScript2);
            W.Text text1 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text1.Text = " ";

            run1.Append(runProperties1);
            run1.Append(text1);

            paragraph1.Append(paragraphProperties1);
            paragraph1.Append(run1);

            W.Paragraph paragraph2 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "6E6DB8AF", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties2 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId2 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties2 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts3 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold3 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript3 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties2.Append(runFonts3);
            paragraphMarkRunProperties2.Append(bold3);
            paragraphMarkRunProperties2.Append(fontSizeComplexScript3);

            paragraphProperties2.Append(paragraphStyleId2);
            paragraphProperties2.Append(paragraphMarkRunProperties2);

            W.Run run2 = new W.Run();

            W.RunProperties runProperties2 = new W.RunProperties();
            W.RunFonts runFonts4 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold4 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript4 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties2.Append(runFonts4);
            runProperties2.Append(bold4);
            runProperties2.Append(fontSizeComplexScript4);
            W.Text text2 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text2.Text = " ";

            run2.Append(runProperties2);
            run2.Append(text2);

            paragraph2.Append(paragraphProperties2);
            paragraph2.Append(run2);

            W.Paragraph paragraph3 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "02530E2F", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties3 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId3 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties3 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts5 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold5 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript5 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties3.Append(runFonts5);
            paragraphMarkRunProperties3.Append(bold5);
            paragraphMarkRunProperties3.Append(fontSizeComplexScript5);

            paragraphProperties3.Append(paragraphStyleId3);
            paragraphProperties3.Append(paragraphMarkRunProperties3);

            W.Run run3 = new W.Run();

            W.RunProperties runProperties3 = new W.RunProperties();
            W.RunFonts runFonts6 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold6 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript6 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties3.Append(runFonts6);
            runProperties3.Append(bold6);
            runProperties3.Append(fontSizeComplexScript6);
            W.Text text3 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text3.Text = " ";

            run3.Append(runProperties3);
            run3.Append(text3);

            paragraph3.Append(paragraphProperties3);
            paragraph3.Append(run3);

            W.Paragraph paragraph4 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "4753D73F", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties4 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId4 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties4 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts7 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold7 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript7 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties4.Append(runFonts7);
            paragraphMarkRunProperties4.Append(bold7);
            paragraphMarkRunProperties4.Append(fontSizeComplexScript7);

            paragraphProperties4.Append(paragraphStyleId4);
            paragraphProperties4.Append(paragraphMarkRunProperties4);

            paragraph4.Append(paragraphProperties4);

            W.Paragraph paragraph5 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "7675723D", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties5 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId5 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties5 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts8 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold8 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript8 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties5.Append(runFonts8);
            paragraphMarkRunProperties5.Append(bold8);
            paragraphMarkRunProperties5.Append(fontSizeComplexScript8);

            paragraphProperties5.Append(paragraphStyleId5);
            paragraphProperties5.Append(paragraphMarkRunProperties5);

            W.Run run4 = new W.Run();

            W.RunProperties runProperties4 = new W.RunProperties();
            W.RunFonts runFonts9 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold9 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript9 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties4.Append(runFonts9);
            runProperties4.Append(bold9);
            runProperties4.Append(fontSizeComplexScript9);
            W.Text text4 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text4.Text = " ";

            run4.Append(runProperties4);
            run4.Append(text4);

            paragraph5.Append(paragraphProperties5);
            paragraph5.Append(run4);

            W.Paragraph paragraph6 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "12AC83A7", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties6 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId6 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties6 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts10 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold10 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript10 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties6.Append(runFonts10);
            paragraphMarkRunProperties6.Append(bold10);
            paragraphMarkRunProperties6.Append(fontSizeComplexScript10);

            paragraphProperties6.Append(paragraphStyleId6);
            paragraphProperties6.Append(paragraphMarkRunProperties6);

            W.Run run5 = new W.Run();

            W.RunProperties runProperties5 = new W.RunProperties();
            W.RunFonts runFonts11 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold11 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript11 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties5.Append(runFonts11);
            runProperties5.Append(bold11);
            runProperties5.Append(fontSizeComplexScript11);
            W.Text text5 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text5.Text = " ";

            run5.Append(runProperties5);
            run5.Append(text5);

            paragraph6.Append(paragraphProperties6);
            paragraph6.Append(run5);

            W.Paragraph paragraph7 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "7F4349F2", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties7 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId7 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties7 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts12 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold12 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript12 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties7.Append(runFonts12);
            paragraphMarkRunProperties7.Append(bold12);
            paragraphMarkRunProperties7.Append(fontSizeComplexScript12);

            paragraphProperties7.Append(paragraphStyleId7);
            paragraphProperties7.Append(paragraphMarkRunProperties7);

            W.Run run6 = new W.Run();

            W.RunProperties runProperties6 = new W.RunProperties();
            W.RunFonts runFonts13 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold13 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript13 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties6.Append(runFonts13);
            runProperties6.Append(bold13);
            runProperties6.Append(fontSizeComplexScript13);
            W.Text text6 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text6.Text = " ";

            run6.Append(runProperties6);
            run6.Append(text6);

            paragraph7.Append(paragraphProperties7);
            paragraph7.Append(run6);

            W.Paragraph paragraph8 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "5378D687", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties8 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId8 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties8 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts14 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold14 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript14 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties8.Append(runFonts14);
            paragraphMarkRunProperties8.Append(bold14);
            paragraphMarkRunProperties8.Append(fontSizeComplexScript14);

            paragraphProperties8.Append(paragraphStyleId8);
            paragraphProperties8.Append(paragraphMarkRunProperties8);

            W.Run run7 = new W.Run();

            W.RunProperties runProperties7 = new W.RunProperties();
            W.RunFonts runFonts15 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold15 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript15 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties7.Append(runFonts15);
            runProperties7.Append(bold15);
            runProperties7.Append(fontSizeComplexScript15);
            W.Text text7 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text7.Text = " ";

            run7.Append(runProperties7);
            run7.Append(text7);

            paragraph8.Append(paragraphProperties8);
            paragraph8.Append(run7);

            W.Paragraph paragraph9 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "5DCADE92", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties9 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId9 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties9 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts16 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold16 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript16 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties9.Append(runFonts16);
            paragraphMarkRunProperties9.Append(bold16);
            paragraphMarkRunProperties9.Append(fontSizeComplexScript16);

            paragraphProperties9.Append(paragraphStyleId9);
            paragraphProperties9.Append(paragraphMarkRunProperties9);

            W.Run run8 = new W.Run();

            W.RunProperties runProperties8 = new W.RunProperties();
            W.RunFonts runFonts17 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold17 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript17 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties8.Append(runFonts17);
            runProperties8.Append(bold17);
            runProperties8.Append(fontSizeComplexScript17);
            W.Text text8 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text8.Text = " ";

            run8.Append(runProperties8);
            run8.Append(text8);

            paragraph9.Append(paragraphProperties9);
            paragraph9.Append(run8);

            W.Paragraph paragraph10 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "4AC96599", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties10 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId10 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties10 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts18 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold18 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript18 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties10.Append(runFonts18);
            paragraphMarkRunProperties10.Append(bold18);
            paragraphMarkRunProperties10.Append(fontSizeComplexScript18);

            paragraphProperties10.Append(paragraphStyleId10);
            paragraphProperties10.Append(paragraphMarkRunProperties10);

            W.Run run9 = new W.Run();

            W.RunProperties runProperties9 = new W.RunProperties();
            W.RunFonts runFonts19 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold19 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript19 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties9.Append(runFonts19);
            runProperties9.Append(bold19);
            runProperties9.Append(fontSizeComplexScript19);
            W.Text text9 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text9.Text = " ";

            run9.Append(runProperties9);
            run9.Append(text9);

            paragraph10.Append(paragraphProperties10);
            paragraph10.Append(run9);

            W.Paragraph paragraph11 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "2B4B8144", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties11 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId11 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties11 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts20 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold20 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript20 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties11.Append(runFonts20);
            paragraphMarkRunProperties11.Append(bold20);
            paragraphMarkRunProperties11.Append(fontSizeComplexScript20);

            paragraphProperties11.Append(paragraphStyleId11);
            paragraphProperties11.Append(paragraphMarkRunProperties11);

            W.Run run10 = new W.Run();

            W.RunProperties runProperties10 = new W.RunProperties();
            W.RunFonts runFonts21 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold21 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript21 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties10.Append(runFonts21);
            runProperties10.Append(bold21);
            runProperties10.Append(fontSizeComplexScript21);
            W.Text text10 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text10.Text = " ";

            run10.Append(runProperties10);
            run10.Append(text10);

            paragraph11.Append(paragraphProperties11);
            paragraph11.Append(run10);

            W.Paragraph paragraph12 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "0AAAC9A6", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties12 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId12 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties12 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts22 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold22 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript22 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties12.Append(runFonts22);
            paragraphMarkRunProperties12.Append(bold22);
            paragraphMarkRunProperties12.Append(fontSizeComplexScript22);

            paragraphProperties12.Append(paragraphStyleId12);
            paragraphProperties12.Append(paragraphMarkRunProperties12);

            W.Run run11 = new W.Run();

            W.RunProperties runProperties11 = new W.RunProperties();
            W.RunFonts runFonts23 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold23 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript23 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties11.Append(runFonts23);
            runProperties11.Append(bold23);
            runProperties11.Append(fontSizeComplexScript23);
            W.Text text11 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text11.Text = " ";

            run11.Append(runProperties11);
            run11.Append(text11);

            paragraph12.Append(paragraphProperties12);
            paragraph12.Append(run11);

            W.Paragraph paragraph13 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "5506A4C5", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties13 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId13 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties13 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts24 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold24 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript24 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties13.Append(runFonts24);
            paragraphMarkRunProperties13.Append(bold24);
            paragraphMarkRunProperties13.Append(fontSizeComplexScript24);

            paragraphProperties13.Append(paragraphStyleId13);
            paragraphProperties13.Append(paragraphMarkRunProperties13);

            W.Run run12 = new W.Run();

            W.RunProperties runProperties12 = new W.RunProperties();
            W.RunFonts runFonts25 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold25 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript25 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties12.Append(runFonts25);
            runProperties12.Append(bold25);
            runProperties12.Append(fontSizeComplexScript25);
            W.Text text12 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text12.Text = " ";

            run12.Append(runProperties12);
            run12.Append(text12);

            paragraph13.Append(paragraphProperties13);
            paragraph13.Append(run12);

            W.Paragraph paragraph14 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "7AEBEDA2", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties14 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId14 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties14 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts26 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold26 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript26 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties14.Append(runFonts26);
            paragraphMarkRunProperties14.Append(bold26);
            paragraphMarkRunProperties14.Append(fontSizeComplexScript26);

            paragraphProperties14.Append(paragraphStyleId14);
            paragraphProperties14.Append(paragraphMarkRunProperties14);

            W.Run run13 = new W.Run();

            W.RunProperties runProperties13 = new W.RunProperties();
            W.RunFonts runFonts27 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold27 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript27 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties13.Append(runFonts27);
            runProperties13.Append(bold27);
            runProperties13.Append(fontSizeComplexScript27);
            W.Text text13 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text13.Text = " ";

            run13.Append(runProperties13);
            run13.Append(text13);

            paragraph14.Append(paragraphProperties14);
            paragraph14.Append(run13);

            W.Paragraph paragraph15 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "48085869", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties15 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId15 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties15 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts28 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold28 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript28 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties15.Append(runFonts28);
            paragraphMarkRunProperties15.Append(bold28);
            paragraphMarkRunProperties15.Append(fontSizeComplexScript28);

            paragraphProperties15.Append(paragraphStyleId15);
            paragraphProperties15.Append(paragraphMarkRunProperties15);

            paragraph15.Append(paragraphProperties15);

            W.Paragraph paragraph16 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "03349807", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties16 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId16 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties16 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts29 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold29 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript29 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties16.Append(runFonts29);
            paragraphMarkRunProperties16.Append(bold29);
            paragraphMarkRunProperties16.Append(fontSizeComplexScript29);

            paragraphProperties16.Append(paragraphStyleId16);
            paragraphProperties16.Append(paragraphMarkRunProperties16);

            W.Run run14 = new W.Run();

            W.RunProperties runProperties14 = new W.RunProperties();
            W.RunFonts runFonts30 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold30 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript30 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties14.Append(runFonts30);
            runProperties14.Append(bold30);
            runProperties14.Append(fontSizeComplexScript30);
            W.Text text14 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text14.Text = " ";

            run14.Append(runProperties14);
            run14.Append(text14);

            paragraph16.Append(paragraphProperties16);
            paragraph16.Append(run14);

            W.Paragraph paragraph17 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "13B8FCE4", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties17 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId17 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties17 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts31 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold31 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript31 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties17.Append(runFonts31);
            paragraphMarkRunProperties17.Append(bold31);
            paragraphMarkRunProperties17.Append(fontSizeComplexScript31);

            paragraphProperties17.Append(paragraphStyleId17);
            paragraphProperties17.Append(paragraphMarkRunProperties17);

            paragraph17.Append(paragraphProperties17);

            W.Paragraph paragraph18 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "3ACA8116", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties18 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId18 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties18 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts32 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold32 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript32 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties18.Append(runFonts32);
            paragraphMarkRunProperties18.Append(bold32);
            paragraphMarkRunProperties18.Append(fontSizeComplexScript32);

            paragraphProperties18.Append(paragraphStyleId18);
            paragraphProperties18.Append(paragraphMarkRunProperties18);

            W.Run run15 = new W.Run();

            W.RunProperties runProperties15 = new W.RunProperties();
            W.RunFonts runFonts33 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold33 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript33 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties15.Append(runFonts33);
            runProperties15.Append(bold33);
            runProperties15.Append(fontSizeComplexScript33);
            W.Text text15 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text15.Text = " ";

            run15.Append(runProperties15);
            run15.Append(text15);

            paragraph18.Append(paragraphProperties18);
            paragraph18.Append(run15);

            W.Paragraph paragraph19 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "05C6F3B3", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties19 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId19 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties19 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts34 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold34 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript34 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties19.Append(runFonts34);
            paragraphMarkRunProperties19.Append(bold34);
            paragraphMarkRunProperties19.Append(fontSizeComplexScript34);

            paragraphProperties19.Append(paragraphStyleId19);
            paragraphProperties19.Append(paragraphMarkRunProperties19);

            W.Run run16 = new W.Run();

            W.RunProperties runProperties16 = new W.RunProperties();
            W.RunFonts runFonts35 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold35 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript35 = new W.FontSizeComplexScript() { Val = "20" };

            runProperties16.Append(runFonts35);
            runProperties16.Append(bold35);
            runProperties16.Append(fontSizeComplexScript35);
            W.Text text16 = new W.Text() { Space = SpaceProcessingModeValues.Preserve };
            text16.Text = " ";

            run16.Append(runProperties16);
            run16.Append(text16);

            paragraph19.Append(paragraphProperties19);
            paragraph19.Append(run16);

            W.Paragraph paragraph20 = new W.Paragraph() { RsidParagraphAddition = "00682DA0", RsidParagraphProperties = "00682DA0", RsidRunAdditionDefault = "00682DA0", ParagraphId = "3C7FD12D", TextId = "77777777" };

            W.ParagraphProperties paragraphProperties20 = new W.ParagraphProperties();
            W.ParagraphStyleId paragraphStyleId20 = new W.ParagraphStyleId() { Val = "BodyText" };

            W.ParagraphMarkRunProperties paragraphMarkRunProperties20 = new W.ParagraphMarkRunProperties();
            W.RunFonts runFonts36 = new W.RunFonts() { ComplexScript = "Calibri" };
            W.Bold bold36 = new W.Bold();
            W.FontSizeComplexScript fontSizeComplexScript36 = new W.FontSizeComplexScript() { Val = "20" };

            paragraphMarkRunProperties20.Append(runFonts36);
            paragraphMarkRunProperties20.Append(bold36);
            paragraphMarkRunProperties20.Append(fontSizeComplexScript36);

            paragraphProperties20.Append(paragraphStyleId20);
            paragraphProperties20.Append(paragraphMarkRunProperties20);

            paragraph20.Append(paragraphProperties20);

            textBoxContent1.Append(paragraph1);
            textBoxContent1.Append(paragraph2);
            textBoxContent1.Append(paragraph3);
            textBoxContent1.Append(paragraph4);
            textBoxContent1.Append(paragraph5);
            textBoxContent1.Append(paragraph6);
            textBoxContent1.Append(paragraph7);
            textBoxContent1.Append(paragraph8);
            textBoxContent1.Append(paragraph9);
            textBoxContent1.Append(paragraph10);
            textBoxContent1.Append(paragraph11);
            textBoxContent1.Append(paragraph12);
            textBoxContent1.Append(paragraph13);
            textBoxContent1.Append(paragraph14);
            textBoxContent1.Append(paragraph15);
            textBoxContent1.Append(paragraph16);
            textBoxContent1.Append(paragraph17);
            textBoxContent1.Append(paragraph18);
            textBoxContent1.Append(paragraph19);
            textBoxContent1.Append(paragraph20);

            textBoxInfo21.Append(textBoxContent1);

            Wps.TextBodyProperties textBodyProperties1 = new Wps.TextBodyProperties() { Rotation = 0, Vertical = A.TextVerticalValues.Horizontal, Wrap = A.TextWrappingValues.Square, LeftInset = 0, TopInset = 0, RightInset = 0, BottomInset = 0, Anchor = A.TextAnchoringTypeValues.Top, AnchorCenter = false, UpRight = true };
            A.NoAutoFit noAutoFit1 = new A.NoAutoFit();

            textBodyProperties1.Append(noAutoFit1);

            wordprocessingShape1.Append(nonVisualDrawingShapeProperties1);
            wordprocessingShape1.Append(shapeProperties1);
            wordprocessingShape1.Append(textBoxInfo21);
            wordprocessingShape1.Append(textBodyProperties1);

            graphicData1.Append(wordprocessingShape1);

            graphic1.Append(graphicData1);

            Wp14.RelativeWidth relativeWidth1 = new Wp14.RelativeWidth() { ObjectId = Wp14.SizeRelativeHorizontallyValues.Page };
            Wp14.PercentageWidth percentageWidth1 = new Wp14.PercentageWidth();
            percentageWidth1.Text = "0";

            relativeWidth1.Append(percentageWidth1);

            Wp14.RelativeHeight relativeHeight1 = new Wp14.RelativeHeight() { RelativeFrom = Wp14.SizeRelativeVerticallyValues.Page };
            Wp14.PercentageHeight percentageHeight1 = new Wp14.PercentageHeight();
            percentageHeight1.Text = "0";

            relativeHeight1.Append(percentageHeight1);

            anchor1.Append(simplePosition1);
            anchor1.Append(horizontalPosition1);
            anchor1.Append(verticalPosition1);
            anchor1.Append(extent1);
            anchor1.Append(effectExtent1);
            anchor1.Append(wrapNone1);
            anchor1.Append(docProperties1);
            anchor1.Append(nonVisualGraphicFrameDrawingProperties1);
            anchor1.Append(graphic1);
            anchor1.Append(relativeWidth1);
            anchor1.Append(relativeHeight1);

            drawing1.Append(anchor1);

            //alternateContentChoice1.Append(drawing1);
            //body.Append(alternateContentChoice1);
            //body.Append(drawing1);
            Run run = new Run();
            run.AppendChild(drawing1);

            body.Append(run);

        }

        public TableProperties getHorizontalBorderTableProperties()
        {
            return new TableProperties(
                new TableBorders(
                    new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Space = 0, Size = 4 },
                    new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Space = 0, Size = 4 },
                    new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.None), Space = 0, Size = 0 },
                    new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.None), Space = 0, Size = 0 },
                    new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Space = 0, Size = 4 },
                    new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.None), Space = 0, Size = 0 }
                ),
                new TableCellMarginDefault(
                    new LeftMargin() { Type = TableWidthUnitValues.Dxa, Width = "30" },
                    new RightMargin() { Type = TableWidthUnitValues.Dxa, Width = "30" }),
                new TableLayout() { Type = new EnumValue<TableLayoutValues>(TableLayoutValues.Fixed) }
            );
        }

        public TableCellProperties getTableCellPropBorderless(string width)
        {
            return new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = width },
                new TableCellBorders(
                    new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Nil) },
                    new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Nil) }
            ));
        }

        public TableCellProperties getTableCellPropFilled(string width, string color)
        {
            return new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = width },
                new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center },
                new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = color },
                new TableCellBorders(new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Nil) })
            );
        }

        public TableCellProperties getTableCellPropCentered(string width)
        {
            return new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = width },
                new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center },
                new TableCellBorders(new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Nil) })
            );
        }


        /// <summary>
        /// Format any row in the table that contains [LitQ] tags
        /// </summary>
        /// <param name="table"></param>
        public void FormatSubTables(Table table, int qnumCol, int varCol, int wordCol)
        {
            string qnum;
            string varname;
            string wording;
            int mainQnum = 0;
            string litqNewRow;

            string[] ROArray = null;
            int roStart;
            int roEnd;
            string respOptionsText = "";
            double placeLeft;

            var rows = table.Elements<TableRow>();

            // for each row in the table, examine the qnum for series questions
            for (int r = 1; r < rows.Count(); r++)
            {
                TableRow currentRow = rows.ElementAt(r);

                // get this row's cells
                var cells = rows.ElementAt(r).Elements<TableCell>();

                // get the cell's containing wordings, qnum and varname
                TableCell wordCell = cells.ElementAt(wordCol);
                TableCell varCell = cells.ElementAt(varCol);
                TableCell qnumCell = cells.ElementAt(qnumCol);

                varname = varCell.GetCellText();

                // skip headings
                if (varname.StartsWith("Z"))
                    continue;

                qnum = qnumCell.GetCellText();

                // skip non-series questions
                if (Char.IsDigit(Char.Parse(qnum.Substring(qnum.Length - 1, 1))))
                    continue;

                wording = wordCell.GetCellText();

                // check for [LitQ] and table tags
                if (wording.Contains("[LitQ]") && wording.Contains("[TBLROS]") && wording.Contains("[TBLROE"))
                {
                    roStart = wording.IndexOf("[TBLROS]") + "[TBLROS]".Length;
                    roEnd = wording.IndexOf("[TBLROE]") + "[TBLROE]".Length;

                    respOptionsText = wording.Substring(roStart, roEnd - roStart);

                    // now extract the LitQ from the first member of the series
                    litqNewRow = wording.Substring(wording.IndexOf("[LitQ]") + "[LitQ]".Length, wording.IndexOf("[/LitQ]") - wording.IndexOf("[LitQ]") - "[/LitQ]".Length + 1);

                    // get respOption numbers
                    ROArray = GetRespNums(wording, roStart, roEnd);

                    // and replace LitQ it with nothing
                    wording = wording.Replace("[LitQ]" + litqNewRow + "[/LitQ]", string.Empty);
                    wording = wording.Replace("[indent]", string.Empty);
                    wording = wording.Replace("[/indent]", string.Empty);
                    wording = wording.Replace("[TBLROS]", string.Empty);
                    wording = wording.Replace("[TBLROE]", string.Empty);
                    wording = wording.Replace("\r\n\r\n", "\r\n");

                    // set this cell to the question wording minus the LitQ
                    wordCell.SetCellText(wording);

                    litqNewRow = Utilities.TrimString(litqNewRow, "<br>");

                    // put indents around 'new' litq
                    litqNewRow = "[indent]" + litqNewRow + "[/indent]";

                    // merge row into a single cell, set the qnum cell to contain the wording so that the resulting merged cell contains the wording
                    qnumCell.SetCellText(wording);
                    //Utilities.SetCellText((TableCell)cells.ElementAt(varCol), string.Empty);

                    TableCellProperties firstCellProps = new TableCellProperties();
                    firstCellProps.Append(new HorizontalMerge() { Val = MergedCellValues.Restart });

                    cells.ElementAt(qnumCol).Append(firstCellProps);

                    TableCellProperties otherCellProps = new TableCellProperties();
                    otherCellProps.Append(new HorizontalMerge() { Val = MergedCellValues.Continue });

                    cells.ElementAt(varCol).Append(otherCellProps);

                    otherCellProps = new TableCellProperties();
                    otherCellProps.Append(new HorizontalMerge() { Val = MergedCellValues.Continue });

                    cells.ElementAt(wordCol).Append(otherCellProps);

                    // now add a new row after this one for the LitQ
                    TableRow newrow = new TableRow();
                    TableCell newQnum = new TableCell();
                    newQnum.SetCellText(qnum);
                    TableCell newVar = new TableCell();
                    newVar.SetCellText(varname);
                    TableCell newWording = new TableCell();
                    newWording.SetCellText(litqNewRow);

                    newrow.Append(newQnum);
                    newrow.Append(newVar);
                    newrow.Append(newWording);

                    table.InsertAfter(newrow, rows.ElementAt(r));

                    mainQnum = Int32.Parse(qnum.Substring(0, 3));
                }
                else if (Int32.Parse(qnum.Substring(0, 3)) == mainQnum && Int32.Parse(qnum.Substring(0, 3)) != 0)
                {
                    // member of the current series
                    // record qnum, varname and wording
                    if (!wording.StartsWith("[indent]"))
                        wording = "[indent]" + wording + "[/indent]";

                    placeLeft = 11 - 1 * 2;

                    TableCellProperties cellProps = new TableCellProperties();

                    TableCell currentCell;

                    // qnum
                    currentCell = currentRow.Elements<TableCell>().ElementAt(qnumCol);
                    currentCell.PrependChild(new TableCellProperties(new TableCellWidth()
                    {
                        Width = Convert.ToString(0.57 * 1440),
                        Type = TableWidthUnitValues.Dxa
                    }));
                    placeLeft -= 0.57;

                    // varname
                    currentCell = currentRow.Elements<TableCell>().ElementAt(varCol);
                    currentCell.PrependChild(new TableCellProperties(new TableCellWidth()
                    {
                        Width = Convert.ToString(1.1 * 1440),
                        Type = TableWidthUnitValues.Dxa
                    }));
                    placeLeft -= 0.57;

                    // question
                    currentCell = currentRow.Elements<TableCell>().ElementAt(wordCol);
                    currentCell.PrependChild(new TableCellProperties(new TableCellWidth()
                    {
                        Width = Convert.ToString((placeLeft - (ROArray.Length * 0.7)) * 1440),
                        Type = TableWidthUnitValues.Dxa
                    }));

                    placeLeft -= (placeLeft - (ROArray.Length - 1) * 0.7);

                    for (int i = 0; i < ROArray.Length; i++)
                    {
                        currentCell = new TableCell();
                        currentCell.SetCellText(ROArray[i]);
                        currentCell.PrependChild(new TableCellProperties(new TableCellWidth()
                        {
                            Width = Convert.ToString(0.7 * 1440),
                            Type = TableWidthUnitValues.Dxa
                        }));
                        placeLeft -= 0.7;

                        currentRow.Append(currentCell);
                    }
                }
            }

            // for each regular row in the table, set the gridSpan for the word column to be the span of the word column to the column count
            for (int r = 0; r < rows.Count(); r++)
            {
                var currentRow = table.Elements<TableRow>().ElementAt(r);

                var rowCells = currentRow.Elements<TableCell>();
                int columns = table.Elements<TableGrid>().ElementAt(0).Elements<GridColumn>().Count();

                TableCell questionCell;

                if (rowCells.Count() == wordCol + 1)
                {
                    questionCell = rowCells.ElementAt(wordCol);
                    questionCell.Append(new TableCellProperties(new GridSpan() { Val = columns - wordCol }));

                }
                else if (rowCells.Count() > 1)
                {
                    questionCell = rowCells.ElementAt(wordCol);
                    questionCell.Append(new TableCellProperties(new GridSpan() { Val = (columns - wordCol) - (rowCells.Count() - wordCol + 1) }));
                }
            }
        }
        
        private string[] GetRespNums (string wording, int roStart, int roEnd)
        {
            Regex rx = new Regex("[0-9]* ");
            MatchCollection m;
            string[] result;
            string[] respArray;
            string resps = wording.Substring(roStart, roEnd - roStart + 1);
            resps = Utilities.TrimString(resps, "\r\n");

            resps = resps.Replace("[indent3]", "");
            resps = resps.Replace("[/indent3]", "");
            resps = resps.Replace("[TBLROS]", "");
            resps = resps.Replace("[TBLROE]", "");
            resps = Utilities.TrimString(resps, "\r\n");
            resps = resps.Substring(0, resps.Length - 1);

            // break apart options
            if (resps.Contains("<br>"))
                respArray = resps.Split(new string[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries);
            else
                respArray = resps.Split(new string[] { "\r" }, StringSplitOptions.RemoveEmptyEntries);


            result = new string[respArray.Length];

            for (int i = 0; i < respArray.Length;i++)
            {
                m = rx.Matches(respArray[i]);
                if (m.Count > 0)
                    result[i] = m[0].Value;
            }

            return result;
        }

        
        private bool EndsWithSpecial (string input)
        {
            Regex rx = new Regex("[0-9A-Z]");
            return rx.IsMatch(input.Substring(input.Length-1,1)) || input.EndsWith("]") || input.EndsWith(")") || input.EndsWith (">") || input.EndsWith("_");
        }

        public override string ToString()
        {
            PropertyInfo[] _PropertyInfos = null;
            if (_PropertyInfos == null)
                _PropertyInfos = this.GetType().GetProperties();

            var sb = new StringBuilder();

            foreach (var info in _PropertyInfos)
            {
                var value = info.GetValue(this, null) ?? "(null)";
                sb.AppendLine(info.Name + ": " + value.ToString());
            }

            return sb.ToString();
        }

//	    private static void ddd()
//	    {
//	        var img = new BitmapImage(new Uri("", UriKind.RelativeOrAbsolute));
//	        var widthPx = img.PixelWidth;
//	        var heightPx = img.PixelHeight;
//	        var horzRezDpi = img.DpiX;
//	        var vertRezDpi = img.DpiY;
//	        const int emusPerInch = 914400;
//	        const int emusPerCm = 360000;
//	        var widthEmus = (long) (widthPx/horzRezDpi*emusPerInch);
//	        var heightEmus = (long) (heightPx/vertRezDpi*emusPerInch);
//	        var maxWidthEmus = (long) (maxWidthCm*emusPerCm);
//	        if (widthEmus > maxWidthEmus)
//	        {
//	            var ratio = (heightEmus*1.0m)/widthEmus;
//	            widthEmus = maxWidthEmus;
//	            heightEmus = (long) (widthEmus*ratio);
//	        }
//	    }
//        public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
//{
//	System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);
//
//	// Prevent using images internal thumbnail
//	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
//	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
//
//	if (OnlyResizeIfWider)
//	{
//		if (FullsizeImage.Width <= NewWidth)
//		{
//			NewWidth = FullsizeImage.Width;
//		}
//	}
//
//	int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
//	if (NewHeight > MaxHeight)
//	{
//		// Resize with height instead
//		NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
//		NewHeight = MaxHeight;
//	}
//
//	System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
//
//	// Clear handle to original file so that we can overwrite it if necessary
//	FullsizeImage.Dispose();
//
//	// Save resized picture
//	NewImage.Save(NewFile);
//}
//
		// Creates an Paragraph instance and adds its children.
		public TableRow GenerateTableRow(IndividualInfo ii, string iid)
		{
			TableRow tableRow1 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00442AD3" };

			TableRowProperties tableRowProperties1 = new TableRowProperties();
			CantSplit cantSplit1 = new CantSplit();

			tableRowProperties1.Append(cantSplit1);

			TableCell tableCell1 = new TableCell();

			TableCellProperties tableCellProperties1 = new TableCellProperties();
			TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };

			tableCellProperties1.Append(tableCellWidth1);

			Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run1 = new Run();
			Break break1 = new Break();

			run1.Append(break1);

			Run run2 = new Run();

			RunProperties runProperties1 = new RunProperties();
			NoProof noProof1 = new NoProof();

			runProperties1.Append(noProof1);
			Text text1 = new Text();
			text1.Text = ii.FirstName;

			run2.Append(runProperties1);
			run2.Append(text1);

			Run run3 = new Run();
			Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text2.Text = " ";

			run3.Append(text2);

			Run run4 = new Run();

			RunProperties runProperties2 = new RunProperties();
			NoProof noProof2 = new NoProof();

			runProperties2.Append(noProof2);
			Text text3 = new Text();
			text3.Text = ii.LastName;

			run4.Append(runProperties2);
			run4.Append(text3);

			paragraph1.Append(run1);
			paragraph1.Append(run2);
			paragraph1.Append(run3);
			paragraph1.Append(run4);

			Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run5 = new Run();

			RunProperties runProperties3 = new RunProperties();
			NoProof noProof3 = new NoProof();

			runProperties3.Append(noProof3);
			Text text4 = new Text();
			text4.Text = ii.Address;

			run5.Append(runProperties3);
			run5.Append(text4);

			paragraph2.Append(run5);


			Paragraph paragraph2a = null;
			if (ii.Address2.HasValue())
			{
				paragraph2a = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };
				Run r = new Run();

				RunProperties rp = new RunProperties();
				NoProof np = new NoProof();

				rp.Append(np);
				Text tt = new Text();
				tt.Text = ii.Address;

				r.Append(rp);
				r.Append(tt);

				paragraph2a.Append(r);
			}


			Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run6 = new Run();

			RunProperties runProperties4 = new RunProperties();
			NoProof noProof4 = new NoProof();

			runProperties4.Append(noProof4);
			Text text5 = new Text();
			text5.Text = ii.CityStateZip;
			run6.Append(runProperties4);
			run6.Append(text5);

			paragraph3.Append(run6);

			Paragraph paragraph4 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Table table1 = new Table();

			TableProperties tableProperties1 = new TableProperties();
			TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" };
			TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };

			TableBorders tableBorders1 = new TableBorders();
			TopBorder topBorder1 = new TopBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			LeftBorder leftBorder1 = new LeftBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			BottomBorder bottomBorder1 = new BottomBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			RightBorder rightBorder1 = new RightBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };

			tableBorders1.Append(topBorder1);
			tableBorders1.Append(leftBorder1);
			tableBorders1.Append(bottomBorder1);
			tableBorders1.Append(rightBorder1);
			tableBorders1.Append(insideHorizontalBorder1);
			tableBorders1.Append(insideVerticalBorder1);
			TableLook tableLook1 = new TableLook() { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };

			tableProperties1.Append(tableStyle1);
			tableProperties1.Append(tableWidth1);
			tableProperties1.Append(tableBorders1);
			tableProperties1.Append(tableLook1);

			TableGrid tableGrid1 = new TableGrid();
			GridColumn gridColumn1 = new GridColumn() { Width = "1435" };
			GridColumn gridColumn2 = new GridColumn() { Width = "3122" };

			tableGrid1.Append(gridColumn1);
			tableGrid1.Append(gridColumn2);

			TableRow tableRow2 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell2 = new TableCell();

			TableCellProperties tableCellProperties2 = new TableCellProperties();
			TableCellWidth tableCellWidth2 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties2.Append(tableCellWidth2);

			Paragraph paragraph5 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run11 = new Run();
			Text text10 = new Text();
			text10.Text = "Email";

			run11.Append(text10);

			paragraph5.Append(run11);

			tableCell2.Append(tableCellProperties2);
			tableCell2.Append(paragraph5);

			TableCell tableCell3 = new TableCell();

			TableCellProperties tableCellProperties3 = new TableCellProperties();
			TableCellWidth tableCellWidth3 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties3.Append(tableCellWidth3);
			Paragraph paragraph6 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			paragraph6.Append(new Run(new Text(ii.Email)));

			tableCell3.Append(tableCellProperties3);
			tableCell3.Append(paragraph6);

			tableRow2.Append(tableCell2);
			tableRow2.Append(tableCell3);

			TableRow tableRow3 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell4 = new TableCell();

			TableCellProperties tableCellProperties4 = new TableCellProperties();
			TableCellWidth tableCellWidth4 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties4.Append(tableCellWidth4);

			Paragraph paragraph7 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run12 = new Run();
			Text text11 = new Text();
			text11.Text = "Home Phone";

			run12.Append(text11);

			paragraph7.Append(run12);

			tableCell4.Append(tableCellProperties4);
			tableCell4.Append(paragraph7);

			TableCell tableCell5 = new TableCell();

			TableCellProperties tableCellProperties5 = new TableCellProperties();
			TableCellWidth tableCellWidth5 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties5.Append(tableCellWidth5);

			Paragraph paragraph8 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			Run run13 = new Run();

			RunProperties runProperties7 = new RunProperties();
			NoProof noProof7 = new NoProof();

			runProperties7.Append(noProof7);
			Text text12 = new Text();
			text12.Text = ii.HomePhone.FmtFone();

			run13.Append(runProperties7);
			run13.Append(text12);

			Run run14 = new Run();
			Text text13 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text13.Text = " ";

			run14.Append(text13);

			paragraph8.Append(run13);
			paragraph8.Append(run14);

			tableCell5.Append(tableCellProperties5);
			tableCell5.Append(paragraph8);

			tableRow3.Append(tableCell4);
			tableRow3.Append(tableCell5);

			TableRow tableRow4 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell6 = new TableCell();

			TableCellProperties tableCellProperties6 = new TableCellProperties();
			TableCellWidth tableCellWidth6 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties6.Append(tableCellWidth6);

			Paragraph paragraph9 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run15 = new Run();
			Text text14 = new Text();
			text14.Text = "Cell Phone";

			run15.Append(text14);

			paragraph9.Append(run15);

			tableCell6.Append(tableCellProperties6);
			tableCell6.Append(paragraph9);

			TableCell tableCell7 = new TableCell();

			TableCellProperties tableCellProperties7 = new TableCellProperties();
			TableCellWidth tableCellWidth7 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties7.Append(tableCellWidth7);

			Paragraph paragraph10 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run16 = new Run();

			RunProperties runProperties8 = new RunProperties();
			NoProof noProof8 = new NoProof();

			runProperties8.Append(noProof8);
			Text text15 = new Text();
			text15.Text = ii.CellPhone.FmtFone();

			run16.Append(runProperties8);
			run16.Append(text15);

			paragraph10.Append(run16);

			tableCell7.Append(tableCellProperties7);
			tableCell7.Append(paragraph10);

			tableRow4.Append(tableCell6);
			tableRow4.Append(tableCell7);

			TableRow tableRow5 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell8 = new TableCell();

			TableCellProperties tableCellProperties8 = new TableCellProperties();
			TableCellWidth tableCellWidth8 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties8.Append(tableCellWidth8);

			Paragraph paragraph11 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run17 = new Run();
			Text text16 = new Text();
			text16.Text = "Work Phone";

			run17.Append(text16);

			paragraph11.Append(run17);

			tableCell8.Append(tableCellProperties8);
			tableCell8.Append(paragraph11);

			TableCell tableCell9 = new TableCell();

			TableCellProperties tableCellProperties9 = new TableCellProperties();
			TableCellWidth tableCellWidth9 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties9.Append(tableCellWidth9);

			Paragraph paragraph12 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run18 = new Run();

			RunProperties runProperties9 = new RunProperties();
			NoProof noProof9 = new NoProof();

			runProperties9.Append(noProof9);
			Text text17 = new Text();
			text17.Text = ii.WorkPhone.FmtFone();

			run18.Append(runProperties9);
			run18.Append(text17);

			paragraph12.Append(run18);

			tableCell9.Append(tableCellProperties9);
			tableCell9.Append(paragraph12);

			tableRow5.Append(tableCell8);
			tableRow5.Append(tableCell9);

			TableRow tableRow6 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell10 = new TableCell();

			TableCellProperties tableCellProperties10 = new TableCellProperties();
			TableCellWidth tableCellWidth10 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties10.Append(tableCellWidth10);

			Paragraph paragraph13 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run19 = new Run();
			Text text18 = new Text();
			text18.Text = "Birthday";

			run19.Append(text18);

			paragraph13.Append(run19);

			tableCell10.Append(tableCellProperties10);
			tableCell10.Append(paragraph13);

			TableCell tableCell11 = new TableCell();

			TableCellProperties tableCellProperties11 = new TableCellProperties();
			TableCellWidth tableCellWidth11 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties11.Append(tableCellWidth11);

			Paragraph paragraph14 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00BC57A3", RsidRunAdditionDefault = "00FB1F22" };

			Run run20 = new Run();

			RunProperties runProperties10 = new RunProperties();
			NoProof noProof10 = new NoProof();

			runProperties10.Append(noProof10);
			Text text19 = new Text();
			text19.Text = ii.BirthDay;

			run20.Append(runProperties10);
			run20.Append(text19);

			paragraph14.Append(run20);

			tableCell11.Append(tableCellProperties11);
			tableCell11.Append(paragraph14);

			tableRow6.Append(tableCell10);
			tableRow6.Append(tableCell11);

			TableRow tableRow7 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell12 = new TableCell();

			TableCellProperties tableCellProperties12 = new TableCellProperties();
			TableCellWidth tableCellWidth12 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties12.Append(tableCellWidth12);

			Paragraph paragraph15 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "006D0F9D", RsidRunAdditionDefault = "00FB1F22" };

			Run run21 = new Run();
			Text text20 = new Text();
			text20.Text = "Anniversary";

			run21.Append(text20);

			paragraph15.Append(run21);

			tableCell12.Append(tableCellProperties12);
			tableCell12.Append(paragraph15);

			TableCell tableCell13 = new TableCell();

			TableCellProperties tableCellProperties13 = new TableCellProperties();
			TableCellWidth tableCellWidth13 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties13.Append(tableCellWidth13);
			Paragraph paragraph16 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			paragraph16.Append(new Run(new Text(ii.Anniversary)));

			tableCell13.Append(tableCellProperties13);
			tableCell13.Append(paragraph16);

			tableRow7.Append(tableCell12);
			tableRow7.Append(tableCell13);

			TableRow tableRow8 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell14 = new TableCell();

			TableCellProperties tableCellProperties14 = new TableCellProperties();
			TableCellWidth tableCellWidth14 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties14.Append(tableCellWidth14);

			Paragraph paragraph17 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run22 = new Run();
			Text text21 = new Text();
			text21.Text = "Spouse";

			run22.Append(text21);

			paragraph17.Append(run22);

			tableCell14.Append(tableCellProperties14);
			tableCell14.Append(paragraph17);

			TableCell tableCell15 = new TableCell();

			TableCellProperties tableCellProperties15 = new TableCellProperties();
			TableCellWidth tableCellWidth15 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties15.Append(tableCellWidth15);

			Paragraph paragraph18 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			ParagraphProperties paragraphProperties1 = new ParagraphProperties();

			ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
			NoProof noProof11 = new NoProof();

			paragraphMarkRunProperties1.Append(noProof11);

			paragraphProperties1.Append(paragraphMarkRunProperties1);

			Run run23 = new Run();

			RunProperties runProperties11 = new RunProperties();
			NoProof noProof12 = new NoProof();

			runProperties11.Append(noProof12);
			Text text22 = new Text();
			text22.Text = ii.Spouse;

			run23.Append(runProperties11);
			run23.Append(text22);

			paragraph18.Append(paragraphProperties1);
			paragraph18.Append(run23);

			tableCell15.Append(tableCellProperties15);
			tableCell15.Append(paragraph18);

			tableRow8.Append(tableCell14);
			tableRow8.Append(tableCell15);

			table1.Append(tableProperties1);
			table1.Append(tableGrid1);
			table1.Append(tableRow2);
			table1.Append(tableRow3);
			table1.Append(tableRow4);
			table1.Append(tableRow5);
			table1.Append(tableRow6);
			table1.Append(tableRow7);
			table1.Append(tableRow8);
			Paragraph paragraph19 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			tableCell1.Append(tableCellProperties1);
			tableCell1.Append(paragraph1);
			tableCell1.Append(paragraph2);
			if (paragraph2a != null)
				tableCell1.Append(paragraph2a);
			tableCell1.Append(paragraph3);
			tableCell1.Append(paragraph4);
			tableCell1.Append(table1);
			tableCell1.Append(paragraph19);

			TableCell tableCell16 = new TableCell();

			TableCellProperties tableCellProperties16 = new TableCellProperties();
			TableCellWidth tableCellWidth16 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };
			TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };

			tableCellProperties16.Append(tableCellWidth16);
			tableCellProperties16.Append(tableCellVerticalAlignment1);
			tableCell16.Append(tableCellProperties16);

			Paragraph paragraph20 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00960953", RsidRunAdditionDefault = "00FB1F22" };
			ParagraphProperties paragraphProperties2 = new ParagraphProperties();
			Justification justification1 = new Justification() { Val = JustificationValues.Center };

			paragraphProperties2.Append(justification1);
			paragraph20.Append(paragraphProperties2);

			if (iid.HasValue())
			{
				Run run24 = new Run();

				RunProperties runProperties12 = new RunProperties();
				NoProof noProof13 = new NoProof();

				runProperties12.Append(noProof13);

				Drawing drawing1 = new Drawing();

				Wp.Inline inline1 = new Wp.Inline()
									{
										DistanceFromTop = (UInt32Value)0U,
										DistanceFromBottom = (UInt32Value)0U,
										DistanceFromLeft = (UInt32Value)0U,
										DistanceFromRight = (UInt32Value)0U
									};
				Wp.Extent extent1 = new Wp.Extent() { Cx = 1428750L, Cy = 1905000L };
				Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L };
				Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)1U, Name = "Picture 1", Description = "D:\\Pictures\\ttt.jpg" };

				Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 =
					new Wp.NonVisualGraphicFrameDrawingProperties();

				A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoChangeAspect = true };
				graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);

				A.Graphic graphic1 = new A.Graphic();
				graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };

				Pic.Picture picture1 = new Pic.Picture();
				picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");

				Pic.NonVisualPictureProperties nonVisualPictureProperties1 = new Pic.NonVisualPictureProperties();
				Pic.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Pic.NonVisualDrawingProperties()
																			 {
																				 Id = (UInt32Value)0U,
																				 Name = "Picture 459",
																				 Description = "D:\\Pictures\\ttt.jpg"
																			 };

				Pic.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 =
					new Pic.NonVisualPictureDrawingProperties();
				A.PictureLocks pictureLocks1 = new A.PictureLocks() { NoChangeAspect = false, NoChangeArrowheads = true };

				nonVisualPictureDrawingProperties1.Append(pictureLocks1);

				nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
				nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);

				Pic.BlipFill blipFill1 = new Pic.BlipFill();

				A.Blip blip1 = new A.Blip() { Embed = iid };

				A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

				A.BlipExtension blipExtension1 = new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

				A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi() { Val = false };
				useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

				blipExtension1.Append(useLocalDpi1);

				blipExtensionList1.Append(blipExtension1);

				blip1.Append(blipExtensionList1);
				A.SourceRectangle sourceRectangle1 = new A.SourceRectangle();

				A.Stretch stretch1 = new A.Stretch();
				A.FillRectangle fillRectangle1 = new A.FillRectangle();

				stretch1.Append(fillRectangle1);

				blipFill1.Append(blip1);
				blipFill1.Append(sourceRectangle1);
				blipFill1.Append(stretch1);

				Pic.ShapeProperties shapeProperties1 = new Pic.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };

				A.Transform2D transform2D1 = new A.Transform2D();
				A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
				A.Extents extents1 = new A.Extents() { Cx = 1428750L, Cy = 1905000L };

				transform2D1.Append(offset1);
				transform2D1.Append(extents1);

				A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
				A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

				presetGeometry1.Append(adjustValueList1);
				A.NoFill noFill1 = new A.NoFill();

				A.Outline outline1 = new A.Outline();
				A.NoFill noFill2 = new A.NoFill();

				outline1.Append(noFill2);

				shapeProperties1.Append(transform2D1);
				shapeProperties1.Append(presetGeometry1);
				shapeProperties1.Append(noFill1);
				shapeProperties1.Append(outline1);

				picture1.Append(nonVisualPictureProperties1);
				picture1.Append(blipFill1);
				picture1.Append(shapeProperties1);

				graphicData1.Append(picture1);

				graphic1.Append(graphicData1);

				inline1.Append(extent1);
				inline1.Append(effectExtent1);
				inline1.Append(docProperties1);
				inline1.Append(nonVisualGraphicFrameDrawingProperties1);
				inline1.Append(graphic1);

				drawing1.Append(inline1);

				run24.Append(runProperties12);
				run24.Append(drawing1);

				paragraph20.Append(run24);
			}
			tableCell16.Append(paragraph20);

			BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
			BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };

			tableRow1.Append(tableRowProperties1);
			tableRow1.Append(tableCell1);
			tableRow1.Append(tableCell16);
			tableRow1.Append(bookmarkStart1);
			tableRow1.Append(bookmarkEnd1);
			return tableRow1;
		}


        
        //|||||||||||||||||||||||||||||||
        //||----CONTACT UPLOAD--------|||
        //|||||||||||||||||||||||||||||||

        public void InsightUpload()
        {            
            Read readtowrite = new Read();
            readtowrite.NameFile = readFile;
            if (fileType == "Word")
            {
                int rownum = perfectArray.GetUpperBound(0) + 1;
                StreamWriter outputFile;
                outputFile = File.AppendText(saveFile);
                outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "firstName", "middleName", "lastName", "title", "phone", "email", "userGroups");
                for (int i = 0; i < rownum; i++)
                {
                    outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6}", perfectArray[i, 0], perfectArray[i, 1], perfectArray[i, 2], perfectArray[i, 3], perfectArray[i, 4], perfectArray[i, 5], perfectArray[i, 6]);
                }
                outputFile.Close();
            }

            else if (fileType == "Excel")
            {
                int rownum = perfectArray.GetUpperBound(0) + 1;
                StreamWriter outputFile;
                outputFile = File.AppendText(saveFile);
                outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6}", "firstName", "middleName", "lastName", "title", "phone", "email", "userGroups");
                for (int i = 0; i < rownum; i++)
                {
                    outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6}", perfectArray[i, 0], perfectArray[i, 1], perfectArray[i, 2], perfectArray[i, 3], perfectArray[i, 4], perfectArray[i, 5], perfectArray[i, 6]);
                }
                outputFile.Close();
            }
            
        }
        public void ResellerUpload()
        {
            if (fileType == "Word")
            {
                Read readtowrite = new Read();
                readtowrite.NameFile = readFile;
                int rownum = perfectArray.GetUpperBound(0) + 1;
                StreamWriter outputFile;
                outputFile = File.AppendText(saveFile);
                outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", "Email", "First Name", "Last Name", "Phone Number", "Extension", "Group", "Location", "Division", "Manager Name", "Manager Email", "Employee Number", "Job Title", "Password", "Mobile", "AD Managed");
                for (int i = 0; i < rownum; i++)
                {
                    outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", perfectArray[i, 0], perfectArray[i, 1], perfectArray[i, 2], perfectArray[i, 3], perfectArray[i, 4], perfectArray[i, 5], perfectArray[i, 6], perfectArray[i, 7], perfectArray[i, 8], perfectArray[i, 9], perfectArray[i, 10], perfectArray[i, 11], perfectArray[i, 12], perfectArray[i, 13], perfectArray[i, 14]);
                }
                outputFile.Close();
            }

            else if (fileType == "Excel")
            {
                Read readtowrite = new Read();
                readtowrite.NameFile = readFile;
                int rownum = perfectArray.GetUpperBound(0) + 1;
                StreamWriter outputFile;
                outputFile = File.AppendText(saveFile);
                outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", "Email", "First Name", "Last Name", "Phone Number", "Extension", "Group", "Location", "Division", "Manager Name", "Manager Email", "Employee Number", "Job Title", "Password", "Mobile", "AD Managed");
                for (int i = 0; i < rownum; i++)
                {
                    outputFile.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}", perfectArray[i, 0], perfectArray[i, 1], perfectArray[i, 2], perfectArray[i, 3], perfectArray[i, 4], perfectArray[i, 5], perfectArray[i, 6], perfectArray[i, 7], perfectArray[i, 8], perfectArray[i, 9], perfectArray[i, 10], perfectArray[i, 11], perfectArray[i, 12], perfectArray[i, 13], perfectArray[i, 14]);
                }
                outputFile.Close();
            }
                   
        }
        




        //|||||||||||||||||||||||||||||||
        //||||---GENERATE REPORT---||||||
        //|||||||||||||||||||||||||||||||
        public TableGrid Columns()
        {
            TableGrid tGrid = new TableGrid();
            GridColumn resColumn = new GridColumn() { Width = "1780" };
            GridColumn nameColumn = new GridColumn() { Width = "6230" };
            GridColumn phoneColumn = new GridColumn() { Width = "1590" };
            GridColumn extColumn = new GridColumn() { Width = "1320" };
            tGrid.Append(resColumn);
            tGrid.Append(nameColumn);
            tGrid.Append(phoneColumn);
            tGrid.Append(extColumn);
            return tGrid;
        }
        public TableRow HeaderRow()
        {
            TableCellProperties headerProps1 = new TableCellProperties();
            TableCellWidth headWidth1 = new TableCellWidth() { Width = "1780", Type = TableWidthUnitValues.Dxa };
            Shading headShade1 = new Shading() { Val = ShadingPatternValues.Clear, Color = "000000", Fill = "D9D9D9" };
            headerProps1.Append(headWidth1);
            headerProps1.Append(headShade1);
            TableCellProperties headerProps2 = new TableCellProperties();
            TableCellWidth headWidth2 = new TableCellWidth() { Width = "6230", Type = TableWidthUnitValues.Dxa };
            Shading headShade2 = new Shading() { Val = ShadingPatternValues.Clear, Color = "000000", Fill = "D9D9D9" };
            headerProps2.Append(headWidth2);
            headerProps2.Append(headShade2);
            TableCellProperties headerProps3 = new TableCellProperties();
            TableCellWidth headWidth3 = new TableCellWidth() { Width = "1590", Type = TableWidthUnitValues.Dxa };
            Shading headShade3 = new Shading() { Val = ShadingPatternValues.Clear, Color = "000000", Fill = "D9D9D9" };
            headerProps3.Append(headWidth3);
            headerProps3.Append(headShade3);
            TableCellProperties headerProps4 = new TableCellProperties();
            TableCellWidth headWidth4 = new TableCellWidth() { Width = "1320", Type = TableWidthUnitValues.Dxa };
            Shading headShade4 = new Shading() { Val = ShadingPatternValues.Clear, Color = "000000", Fill = "D9D9D9" };
            headerProps4.Append(headWidth4);
            headerProps4.Append(headShade4);

            var hr = new TableRow();
            var hc1 = new TableCell();
            hc1.Append(headerProps1);
            hc1.Append(new Paragraph(new Run(new Text("Final Result"))));
            var hc2 = new TableCell();
            hc2.Append(headerProps2);
            hc2.Append(new Paragraph(new Run(new Text("Name"))));
            var hc3 = new TableCell();
            hc3.Append(headerProps3);
            hc3.Append(new Paragraph(new Run(new Text("Phone"))));
            var hc4 = new TableCell();
            hc4.Append(headerProps4);
            hc4.Append(new Paragraph(new Run(new Text("Ext."))));
            hr.Append(hc1);
            hr.Append(hc2);
            hr.Append(hc3);
            hr.Append(hc4);
            return hr;
        }
        public TableRow DatesRow()
        {
            // DATES ROW FORMATTING PROPERTIES
            TableCellProperties infoProps1 = new TableCellProperties();
            GridSpan infoSpan1 = new GridSpan() { Val = 4 };
            infoProps1.Append(infoSpan1);

            // DATES ROW
            var dater = new TableRow();
            var hc1 = new TableCell();
            hc1.Append(infoProps1);
            hc1.Append(new Paragraph(new Run(new Text("Dates:"))));
            dater.Append(hc1);

            return dater;
        }
        public TableRow DescriptionRow()
        {
            // DESCRIPTION ROW FORMATTING PROPERTIES
            TableCellProperties infoProps2 = new TableCellProperties();
            GridSpan infoSpan2 = new GridSpan() { Val = 4 };
            infoProps2.Append(infoSpan2);

            // DESCRIPTION ROW
            var descr = new TableRow();
            var dc1 = new TableCell();
            dc1.Append(infoProps2);
            dc1.Append(new Paragraph(new Run(new Text("Description:"))));
            descr.Append(dc1);

            return descr;
        }

DocumentFormat.OpenXml.Wordprocessing.TableCellProperties : IEnumerable

Constructors :

public TableCellProperties()
public TableCellProperties(IEnumerable<OpenXmlElement> childElements = )
public TableCellProperties(OpenXmlElement[] childElements = )
public TableCellProperties(String outerXml = )

Methods :

public ConditionalFormatStyle get_ConditionalFormatStyle()
public Void set_ConditionalFormatStyle(ConditionalFormatStyle value = )
public TableCellWidth get_TableCellWidth()
public Void set_TableCellWidth(TableCellWidth value = )
public GridSpan get_GridSpan()
public Void set_GridSpan(GridSpan value = )
public HorizontalMerge get_HorizontalMerge()
public Void set_HorizontalMerge(HorizontalMerge value = )
public VerticalMerge get_VerticalMerge()
public Void set_VerticalMerge(VerticalMerge value = )
public TableCellBorders get_TableCellBorders()
public Void set_TableCellBorders(TableCellBorders value = )
public Shading get_Shading()
public Void set_Shading(Shading value = )
public NoWrap get_NoWrap()
public Void set_NoWrap(NoWrap value = )
public TableCellMargin get_TableCellMargin()
public Void set_TableCellMargin(TableCellMargin value = )
public TextDirection get_TextDirection()
public Void set_TextDirection(TextDirection value = )
public TableCellFitText get_TableCellFitText()
public Void set_TableCellFitText(TableCellFitText value = )
public TableCellVerticalAlignment get_TableCellVerticalAlignment()
public Void set_TableCellVerticalAlignment(TableCellVerticalAlignment value = )
public HideMark get_HideMark()
public Void set_HideMark(HideMark value = )
public OpenXmlElement CloneNode(Boolean deep = )
public OpenXmlElement get_FirstChild()
public OpenXmlElement get_LastChild()
public Boolean get_HasChildren()
public String get_InnerText()
public Void set_InnerXml(String value = )
public Boolean AddChild(OpenXmlElement newChild = , Boolean throwOnError = True)
public T AppendChild(T newChild = )
public T InsertAfter(T newChild = , OpenXmlElement referenceChild = )
public T InsertBefore(T newChild = , OpenXmlElement referenceChild = )
public T InsertAt(T newChild = , Int32 index = )
public T PrependChild(T newChild = )
public T RemoveChild(T child = )
public Void RemoveAllChildren()
public T ReplaceChild(OpenXmlElement newChild = , T oldChild = )
public Void RemoveAllChildren()
public Void Remove()
public Boolean IsAfter(OpenXmlElement element = )
public Boolean IsBefore(OpenXmlElement element = )
public Void AddAnnotation(Object annotation = )
public T Annotation()
public Object Annotation(Type type = )
public IEnumerable<T> Annotations()
public IEnumerable<Object> Annotations(Type type = )
public Void RemoveAnnotations()
public Void RemoveAnnotations(Type type = )
public IEnumerator<OpenXmlElement> GetEnumerator()
public Object Clone()
public MarkupCompatibilityAttributes get_MCAttributes()
public Void set_MCAttributes(MarkupCompatibilityAttributes value = )
public String LookupNamespace(String prefix = )
public String LookupPrefix(String namespaceUri = )
public IFeatureCollection get_Features()
public OpenXmlElementContext get_OpenXmlElementContext()
public Boolean get_HasAttributes()
public IEnumerable<OpenXmlAttribute> get_ExtendedAttributes()
public OpenXmlElementList get_ChildElements()
public OpenXmlElement get_Parent()
public String get_NamespaceUri()
public String get_LocalName()
public String get_Prefix()
public IEnumerable<KeyValuePair<StringString>> get_NamespaceDeclarations()
public XmlQualifiedName get_XmlQualifiedName()
public XName get_XName()
public String get_InnerXml()
public String get_OuterXml()
public OpenXmlAttribute GetAttribute(String localName = , String namespaceUri = )
public IList<OpenXmlAttribute> GetAttributes()
public Void SetAttribute(OpenXmlAttribute openXmlAttribute = )
public Void RemoveAttribute(String localName = , String namespaceUri = )
public Void SetAttributes(IEnumerable<OpenXmlAttribute> openXmlAttributes = )
public Void ClearAllAttributes()
public Void AddNamespaceDeclaration(String prefix = , String uri = )
public Void RemoveNamespaceDeclaration(String prefix = )
public T GetFirstChild()
public OpenXmlElement PreviousSibling()
public T PreviousSibling()
public OpenXmlElement NextSibling()
public T NextSibling()
public IEnumerable<OpenXmlElement> Ancestors()
public IEnumerable<T> Ancestors()
public IEnumerable<T> Elements()
public IEnumerable<OpenXmlElement> Elements()
public IEnumerable<T> Descendants()
public IEnumerable<OpenXmlElement> Descendants()
public IEnumerable<OpenXmlElement> ElementsBefore()
public IEnumerable<OpenXmlElement> ElementsAfter()
public Void WriteTo(XmlWriter xmlWriter = )
public Void Append(IEnumerable<OpenXmlElement> newChildren = )
public Void Append(OpenXmlElement[] newChildren = )
public T InsertAfterSelf(T newElement = )
public T InsertBeforeSelf(T newElement = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()

TableCellProperties

We found 10 examples in language CSharp for this search. You will see 36 fragments of code.
        // Creates an TableCellProperties instance and adds its children.
        public TableCellProperties Create(params OpenXmlElement[] newChildren)
        {
            TableCellProperties tableCellProperties = new TableCellProperties();
            tableCellProperties.Append(newChildren);
            return tableCellProperties;
        }


        public IDocumentTableSchemeBuilder Column(string columnName, float widthInPercents)
        {
            var width = Convert.ToInt32((widthInPercents*100)/15);
            var tableCellProperties = new TableCellProperties(new TableCellWidth { Type = TableWidthUnitValues.Pct, Width = width.ToString() });
            AddCell(headerRow, AddText(columnName), tableCellProperties);

            return this;
        }

        private void AddCell(OpenXmlCompositeElement row, Action<ICellContextBuilder> options)
        {
            var tableCellProperties = new TableCellProperties(new TableCellWidth { Type = TableWidthUnitValues.Auto });
            AddCell(row, options, tableCellProperties);
        }

        private void AddCell(OpenXmlCompositeElement row, Action<ICellContextBuilder> options, TableCellProperties cellProperties)
		{
			var builder = new DocxDocumentCellContextBuilder(Document, cellProperties);

			options(builder);
			row.AppendChild(builder.ToElement());
		}

//	    private static void ddd()
//	    {
//	        var img = new BitmapImage(new Uri("", UriKind.RelativeOrAbsolute));
//	        var widthPx = img.PixelWidth;
//	        var heightPx = img.PixelHeight;
//	        var horzRezDpi = img.DpiX;
//	        var vertRezDpi = img.DpiY;
//	        const int emusPerInch = 914400;
//	        const int emusPerCm = 360000;
//	        var widthEmus = (long) (widthPx/horzRezDpi*emusPerInch);
//	        var heightEmus = (long) (heightPx/vertRezDpi*emusPerInch);
//	        var maxWidthEmus = (long) (maxWidthCm*emusPerCm);
//	        if (widthEmus > maxWidthEmus)
//	        {
//	            var ratio = (heightEmus*1.0m)/widthEmus;
//	            widthEmus = maxWidthEmus;
//	            heightEmus = (long) (widthEmus*ratio);
//	        }
//	    }
//        public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
//{
//	System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);
//
//	// Prevent using images internal thumbnail
//	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
//	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
//
//	if (OnlyResizeIfWider)
//	{
//		if (FullsizeImage.Width <= NewWidth)
//		{
//			NewWidth = FullsizeImage.Width;
//		}
//	}
//
//	int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
//	if (NewHeight > MaxHeight)
//	{
//		// Resize with height instead
//		NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
//		NewHeight = MaxHeight;
//	}
//
//	System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
//
//	// Clear handle to original file so that we can overwrite it if necessary
//	FullsizeImage.Dispose();
//
//	// Save resized picture
//	NewImage.Save(NewFile);
//}
//
		// Creates an Paragraph instance and adds its children.
		public TableRow GenerateTableRow(IndividualInfo ii, string iid)
		{
			TableRow tableRow1 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00442AD3" };

			TableRowProperties tableRowProperties1 = new TableRowProperties();
			CantSplit cantSplit1 = new CantSplit();

			tableRowProperties1.Append(cantSplit1);

			TableCell tableCell1 = new TableCell();

			TableCellProperties tableCellProperties1 = new TableCellProperties();
			TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };

			tableCellProperties1.Append(tableCellWidth1);

			Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run1 = new Run();
			Break break1 = new Break();

			run1.Append(break1);

			Run run2 = new Run();

			RunProperties runProperties1 = new RunProperties();
			NoProof noProof1 = new NoProof();

			runProperties1.Append(noProof1);
			Text text1 = new Text();
			text1.Text = ii.FirstName;

			run2.Append(runProperties1);
			run2.Append(text1);

			Run run3 = new Run();
			Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text2.Text = " ";

			run3.Append(text2);

			Run run4 = new Run();

			RunProperties runProperties2 = new RunProperties();
			NoProof noProof2 = new NoProof();

			runProperties2.Append(noProof2);
			Text text3 = new Text();
			text3.Text = ii.LastName;

			run4.Append(runProperties2);
			run4.Append(text3);

			paragraph1.Append(run1);
			paragraph1.Append(run2);
			paragraph1.Append(run3);
			paragraph1.Append(run4);

			Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run5 = new Run();

			RunProperties runProperties3 = new RunProperties();
			NoProof noProof3 = new NoProof();

			runProperties3.Append(noProof3);
			Text text4 = new Text();
			text4.Text = ii.Address;

			run5.Append(runProperties3);
			run5.Append(text4);

			paragraph2.Append(run5);


			Paragraph paragraph2a = null;
			if (ii.Address2.HasValue())
			{
				paragraph2a = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };
				Run r = new Run();

				RunProperties rp = new RunProperties();
				NoProof np = new NoProof();

				rp.Append(np);
				Text tt = new Text();
				tt.Text = ii.Address;

				r.Append(rp);
				r.Append(tt);

				paragraph2a.Append(r);
			}


			Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run6 = new Run();

			RunProperties runProperties4 = new RunProperties();
			NoProof noProof4 = new NoProof();

			runProperties4.Append(noProof4);
			Text text5 = new Text();
			text5.Text = ii.CityStateZip;
			run6.Append(runProperties4);
			run6.Append(text5);

			paragraph3.Append(run6);

			Paragraph paragraph4 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Table table1 = new Table();

			TableProperties tableProperties1 = new TableProperties();
			TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" };
			TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };

			TableBorders tableBorders1 = new TableBorders();
			TopBorder topBorder1 = new TopBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			LeftBorder leftBorder1 = new LeftBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			BottomBorder bottomBorder1 = new BottomBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			RightBorder rightBorder1 = new RightBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };

			tableBorders1.Append(topBorder1);
			tableBorders1.Append(leftBorder1);
			tableBorders1.Append(bottomBorder1);
			tableBorders1.Append(rightBorder1);
			tableBorders1.Append(insideHorizontalBorder1);
			tableBorders1.Append(insideVerticalBorder1);
			TableLook tableLook1 = new TableLook() { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };

			tableProperties1.Append(tableStyle1);
			tableProperties1.Append(tableWidth1);
			tableProperties1.Append(tableBorders1);
			tableProperties1.Append(tableLook1);

			TableGrid tableGrid1 = new TableGrid();
			GridColumn gridColumn1 = new GridColumn() { Width = "1435" };
			GridColumn gridColumn2 = new GridColumn() { Width = "3122" };

			tableGrid1.Append(gridColumn1);
			tableGrid1.Append(gridColumn2);

			TableRow tableRow2 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell2 = new TableCell();

			TableCellProperties tableCellProperties2 = new TableCellProperties();
			TableCellWidth tableCellWidth2 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties2.Append(tableCellWidth2);

			Paragraph paragraph5 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run11 = new Run();
			Text text10 = new Text();
			text10.Text = "Email";

			run11.Append(text10);

			paragraph5.Append(run11);

			tableCell2.Append(tableCellProperties2);
			tableCell2.Append(paragraph5);

			TableCell tableCell3 = new TableCell();

			TableCellProperties tableCellProperties3 = new TableCellProperties();
			TableCellWidth tableCellWidth3 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties3.Append(tableCellWidth3);
			Paragraph paragraph6 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			paragraph6.Append(new Run(new Text(ii.Email)));

			tableCell3.Append(tableCellProperties3);
			tableCell3.Append(paragraph6);

			tableRow2.Append(tableCell2);
			tableRow2.Append(tableCell3);

			TableRow tableRow3 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell4 = new TableCell();

			TableCellProperties tableCellProperties4 = new TableCellProperties();
			TableCellWidth tableCellWidth4 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties4.Append(tableCellWidth4);

			Paragraph paragraph7 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run12 = new Run();
			Text text11 = new Text();
			text11.Text = "Home Phone";

			run12.Append(text11);

			paragraph7.Append(run12);

			tableCell4.Append(tableCellProperties4);
			tableCell4.Append(paragraph7);

			TableCell tableCell5 = new TableCell();

			TableCellProperties tableCellProperties5 = new TableCellProperties();
			TableCellWidth tableCellWidth5 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties5.Append(tableCellWidth5);

			Paragraph paragraph8 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			Run run13 = new Run();

			RunProperties runProperties7 = new RunProperties();
			NoProof noProof7 = new NoProof();

			runProperties7.Append(noProof7);
			Text text12 = new Text();
			text12.Text = ii.HomePhone.FmtFone();

			run13.Append(runProperties7);
			run13.Append(text12);

			Run run14 = new Run();
			Text text13 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text13.Text = " ";

			run14.Append(text13);

			paragraph8.Append(run13);
			paragraph8.Append(run14);

			tableCell5.Append(tableCellProperties5);
			tableCell5.Append(paragraph8);

			tableRow3.Append(tableCell4);
			tableRow3.Append(tableCell5);

			TableRow tableRow4 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell6 = new TableCell();

			TableCellProperties tableCellProperties6 = new TableCellProperties();
			TableCellWidth tableCellWidth6 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties6.Append(tableCellWidth6);

			Paragraph paragraph9 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run15 = new Run();
			Text text14 = new Text();
			text14.Text = "Cell Phone";

			run15.Append(text14);

			paragraph9.Append(run15);

			tableCell6.Append(tableCellProperties6);
			tableCell6.Append(paragraph9);

			TableCell tableCell7 = new TableCell();

			TableCellProperties tableCellProperties7 = new TableCellProperties();
			TableCellWidth tableCellWidth7 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties7.Append(tableCellWidth7);

			Paragraph paragraph10 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run16 = new Run();

			RunProperties runProperties8 = new RunProperties();
			NoProof noProof8 = new NoProof();

			runProperties8.Append(noProof8);
			Text text15 = new Text();
			text15.Text = ii.CellPhone.FmtFone();

			run16.Append(runProperties8);
			run16.Append(text15);

			paragraph10.Append(run16);

			tableCell7.Append(tableCellProperties7);
			tableCell7.Append(paragraph10);

			tableRow4.Append(tableCell6);
			tableRow4.Append(tableCell7);

			TableRow tableRow5 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell8 = new TableCell();

			TableCellProperties tableCellProperties8 = new TableCellProperties();
			TableCellWidth tableCellWidth8 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties8.Append(tableCellWidth8);

			Paragraph paragraph11 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run17 = new Run();
			Text text16 = new Text();
			text16.Text = "Work Phone";

			run17.Append(text16);

			paragraph11.Append(run17);

			tableCell8.Append(tableCellProperties8);
			tableCell8.Append(paragraph11);

			TableCell tableCell9 = new TableCell();

			TableCellProperties tableCellProperties9 = new TableCellProperties();
			TableCellWidth tableCellWidth9 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties9.Append(tableCellWidth9);

			Paragraph paragraph12 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run18 = new Run();

			RunProperties runProperties9 = new RunProperties();
			NoProof noProof9 = new NoProof();

			runProperties9.Append(noProof9);
			Text text17 = new Text();
			text17.Text = ii.WorkPhone.FmtFone();

			run18.Append(runProperties9);
			run18.Append(text17);

			paragraph12.Append(run18);

			tableCell9.Append(tableCellProperties9);
			tableCell9.Append(paragraph12);

			tableRow5.Append(tableCell8);
			tableRow5.Append(tableCell9);

			TableRow tableRow6 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell10 = new TableCell();

			TableCellProperties tableCellProperties10 = new TableCellProperties();
			TableCellWidth tableCellWidth10 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties10.Append(tableCellWidth10);

			Paragraph paragraph13 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run19 = new Run();
			Text text18 = new Text();
			text18.Text = "Birthday";

			run19.Append(text18);

			paragraph13.Append(run19);

			tableCell10.Append(tableCellProperties10);
			tableCell10.Append(paragraph13);

			TableCell tableCell11 = new TableCell();

			TableCellProperties tableCellProperties11 = new TableCellProperties();
			TableCellWidth tableCellWidth11 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties11.Append(tableCellWidth11);

			Paragraph paragraph14 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00BC57A3", RsidRunAdditionDefault = "00FB1F22" };

			Run run20 = new Run();

			RunProperties runProperties10 = new RunProperties();
			NoProof noProof10 = new NoProof();

			runProperties10.Append(noProof10);
			Text text19 = new Text();
			text19.Text = ii.BirthDay;

			run20.Append(runProperties10);
			run20.Append(text19);

			paragraph14.Append(run20);

			tableCell11.Append(tableCellProperties11);
			tableCell11.Append(paragraph14);

			tableRow6.Append(tableCell10);
			tableRow6.Append(tableCell11);

			TableRow tableRow7 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell12 = new TableCell();

			TableCellProperties tableCellProperties12 = new TableCellProperties();
			TableCellWidth tableCellWidth12 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties12.Append(tableCellWidth12);

			Paragraph paragraph15 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "006D0F9D", RsidRunAdditionDefault = "00FB1F22" };

			Run run21 = new Run();
			Text text20 = new Text();
			text20.Text = "Anniversary";

			run21.Append(text20);

			paragraph15.Append(run21);

			tableCell12.Append(tableCellProperties12);
			tableCell12.Append(paragraph15);

			TableCell tableCell13 = new TableCell();

			TableCellProperties tableCellProperties13 = new TableCellProperties();
			TableCellWidth tableCellWidth13 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties13.Append(tableCellWidth13);
			Paragraph paragraph16 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			paragraph16.Append(new Run(new Text(ii.Anniversary)));

			tableCell13.Append(tableCellProperties13);
			tableCell13.Append(paragraph16);

			tableRow7.Append(tableCell12);
			tableRow7.Append(tableCell13);

			TableRow tableRow8 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell14 = new TableCell();

			TableCellProperties tableCellProperties14 = new TableCellProperties();
			TableCellWidth tableCellWidth14 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties14.Append(tableCellWidth14);

			Paragraph paragraph17 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run22 = new Run();
			Text text21 = new Text();
			text21.Text = "Spouse";

			run22.Append(text21);

			paragraph17.Append(run22);

			tableCell14.Append(tableCellProperties14);
			tableCell14.Append(paragraph17);

			TableCell tableCell15 = new TableCell();

			TableCellProperties tableCellProperties15 = new TableCellProperties();
			TableCellWidth tableCellWidth15 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties15.Append(tableCellWidth15);

			Paragraph paragraph18 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			ParagraphProperties paragraphProperties1 = new ParagraphProperties();

			ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
			NoProof noProof11 = new NoProof();

			paragraphMarkRunProperties1.Append(noProof11);

			paragraphProperties1.Append(paragraphMarkRunProperties1);

			Run run23 = new Run();

			RunProperties runProperties11 = new RunProperties();
			NoProof noProof12 = new NoProof();

			runProperties11.Append(noProof12);
			Text text22 = new Text();
			text22.Text = ii.Spouse;

			run23.Append(runProperties11);
			run23.Append(text22);

			paragraph18.Append(paragraphProperties1);
			paragraph18.Append(run23);

			tableCell15.Append(tableCellProperties15);
			tableCell15.Append(paragraph18);

			tableRow8.Append(tableCell14);
			tableRow8.Append(tableCell15);

			table1.Append(tableProperties1);
			table1.Append(tableGrid1);
			table1.Append(tableRow2);
			table1.Append(tableRow3);
			table1.Append(tableRow4);
			table1.Append(tableRow5);
			table1.Append(tableRow6);
			table1.Append(tableRow7);
			table1.Append(tableRow8);
			Paragraph paragraph19 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			tableCell1.Append(tableCellProperties1);
			tableCell1.Append(paragraph1);
			tableCell1.Append(paragraph2);
			if (paragraph2a != null)
				tableCell1.Append(paragraph2a);
			tableCell1.Append(paragraph3);
			tableCell1.Append(paragraph4);
			tableCell1.Append(table1);
			tableCell1.Append(paragraph19);

			TableCell tableCell16 = new TableCell();

			TableCellProperties tableCellProperties16 = new TableCellProperties();
			TableCellWidth tableCellWidth16 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };
			TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };

			tableCellProperties16.Append(tableCellWidth16);
			tableCellProperties16.Append(tableCellVerticalAlignment1);
			tableCell16.Append(tableCellProperties16);

			Paragraph paragraph20 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00960953", RsidRunAdditionDefault = "00FB1F22" };
			ParagraphProperties paragraphProperties2 = new ParagraphProperties();
			Justification justification1 = new Justification() { Val = JustificationValues.Center };

			paragraphProperties2.Append(justification1);
			paragraph20.Append(paragraphProperties2);

			if (iid.HasValue())
			{
				Run run24 = new Run();

				RunProperties runProperties12 = new RunProperties();
				NoProof noProof13 = new NoProof();

				runProperties12.Append(noProof13);

				Drawing drawing1 = new Drawing();

				Wp.Inline inline1 = new Wp.Inline()
									{
										DistanceFromTop = (UInt32Value)0U,
										DistanceFromBottom = (UInt32Value)0U,
										DistanceFromLeft = (UInt32Value)0U,
										DistanceFromRight = (UInt32Value)0U
									};
				Wp.Extent extent1 = new Wp.Extent() { Cx = 1428750L, Cy = 1905000L };
				Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L };
				Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)1U, Name = "Picture 1", Description = "D:\\Pictures\\ttt.jpg" };

				Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 =
					new Wp.NonVisualGraphicFrameDrawingProperties();

				A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoChangeAspect = true };
				graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);

				A.Graphic graphic1 = new A.Graphic();
				graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };

				Pic.Picture picture1 = new Pic.Picture();
				picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");

				Pic.NonVisualPictureProperties nonVisualPictureProperties1 = new Pic.NonVisualPictureProperties();
				Pic.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Pic.NonVisualDrawingProperties()
																			 {
																				 Id = (UInt32Value)0U,
																				 Name = "Picture 459",
																				 Description = "D:\\Pictures\\ttt.jpg"
																			 };

				Pic.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 =
					new Pic.NonVisualPictureDrawingProperties();
				A.PictureLocks pictureLocks1 = new A.PictureLocks() { NoChangeAspect = false, NoChangeArrowheads = true };

				nonVisualPictureDrawingProperties1.Append(pictureLocks1);

				nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
				nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);

				Pic.BlipFill blipFill1 = new Pic.BlipFill();

				A.Blip blip1 = new A.Blip() { Embed = iid };

				A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

				A.BlipExtension blipExtension1 = new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

				A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi() { Val = false };
				useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

				blipExtension1.Append(useLocalDpi1);

				blipExtensionList1.Append(blipExtension1);

				blip1.Append(blipExtensionList1);
				A.SourceRectangle sourceRectangle1 = new A.SourceRectangle();

				A.Stretch stretch1 = new A.Stretch();
				A.FillRectangle fillRectangle1 = new A.FillRectangle();

				stretch1.Append(fillRectangle1);

				blipFill1.Append(blip1);
				blipFill1.Append(sourceRectangle1);
				blipFill1.Append(stretch1);

				Pic.ShapeProperties shapeProperties1 = new Pic.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };

				A.Transform2D transform2D1 = new A.Transform2D();
				A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
				A.Extents extents1 = new A.Extents() { Cx = 1428750L, Cy = 1905000L };

				transform2D1.Append(offset1);
				transform2D1.Append(extents1);

				A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
				A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

				presetGeometry1.Append(adjustValueList1);
				A.NoFill noFill1 = new A.NoFill();

				A.Outline outline1 = new A.Outline();
				A.NoFill noFill2 = new A.NoFill();

				outline1.Append(noFill2);

				shapeProperties1.Append(transform2D1);
				shapeProperties1.Append(presetGeometry1);
				shapeProperties1.Append(noFill1);
				shapeProperties1.Append(outline1);

				picture1.Append(nonVisualPictureProperties1);
				picture1.Append(blipFill1);
				picture1.Append(shapeProperties1);

				graphicData1.Append(picture1);

				graphic1.Append(graphicData1);

				inline1.Append(extent1);
				inline1.Append(effectExtent1);
				inline1.Append(docProperties1);
				inline1.Append(nonVisualGraphicFrameDrawingProperties1);
				inline1.Append(graphic1);

				drawing1.Append(inline1);

				run24.Append(runProperties12);
				run24.Append(drawing1);

				paragraph20.Append(run24);
			}
			tableCell16.Append(paragraph20);

			BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
			BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };

			tableRow1.Append(tableRowProperties1);
			tableRow1.Append(tableCell1);
			tableRow1.Append(tableCell16);
			tableRow1.Append(bookmarkStart1);
			tableRow1.Append(bookmarkEnd1);
			return tableRow1;
		}


        public async Task<byte[]> GetReportAsync(StudyReportInfo reportInfo)
        {
            var templatePath = Path.Combine(Directory.GetCurrentDirectory(), configuration.Path);
            var hash = CryptographyHelper.GetRandomMD5Hash();
            var extension = configuration.Path.Split(".").Last();
            var tempPath = Path.Combine(Path.GetTempPath(), $"{hash}.{extension}");

            var sourceFile = Path.GetFullPath(templatePath);
            var tempFile = Path.GetFullPath(tempPath);
            File.Copy(sourceFile, tempFile);

            using var document = WordprocessingDocument.Open(tempFile, true);
            document.ChangeDocumentType(WordprocessingDocumentType.Document);

            MainDocumentPart mainPart = document.MainDocumentPart;
            var mergeFields = mainPart.RootElement.Descendants<FieldCode>();

            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Date, reportInfo.Date);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.FullName, reportInfo.Fullname);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.PhoneNumber, reportInfo.PhoneNumber);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Age, reportInfo.Age);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Doctor, reportInfo.DoctorShortName);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Doctor, reportInfo.DoctorShortName);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Weight, reportInfo.Weight);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Height, reportInfo.Height);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Diagnosis, reportInfo.Diagnosis);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.Complaints, reportInfo.Complaints);
            OpenXmlWordHelper.ReplaceMergeFieldWithText(mergeFields, ReportVariables.StudyType, reportInfo.StudyTypeName);

            var lastTable = mainPart.Document.Body.Descendants<Table>().LastOrDefault();

            if (lastTable != null)
            {
                var spacing = new SpacingBetweenLines() { Line = "240", LineRule = LineSpacingRuleValues.Auto, Before = "0", After = "0" };
                var justification = new Justification { Val = JustificationValues.Center };

                var paragraphProperties = new ParagraphProperties();
                paragraphProperties.Append(spacing);
                paragraphProperties.Append(justification);

                var tableCellProperties = new TableCellProperties
                {
                    TableCellVerticalAlignment = new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Center }
                };

                foreach (var studyDetails in reportInfo.StudyDetails)
                {
                    var paragraph1 = new Paragraph(new Run(new Text(studyDetails.StudySubtypeName)))
                    {
                        ParagraphProperties = new ParagraphProperties(spacing.CloneNode(true) as SpacingBetweenLines)
                    };

                    var tableCell1 = new TableCell(paragraph1)
                    {
                        TableCellProperties = tableCellProperties.CloneNode(true) as TableCellProperties
                    };

                    var paragraph2 = new Paragraph(new Run(new Text(studyDetails.AvgClockwiseDegrees.ToString())))
                    {
                        ParagraphProperties = paragraphProperties.CloneNode(true) as ParagraphProperties
                    };

                    var tableCell2 = new TableCell(paragraph2)
                    {
                        TableCellProperties = tableCellProperties.CloneNode(true) as TableCellProperties
                    };

                    var paragraph3 = new Paragraph(new Run(new Text(studyDetails.AvgCounterClockwiseDegrees.ToString())))
                    {
                        ParagraphProperties = paragraphProperties.CloneNode(true) as ParagraphProperties
                    };

                    var tableCell3 = new TableCell(paragraph3)
                    {
                        TableCellProperties = tableCellProperties.CloneNode(true) as TableCellProperties
                    };

                    lastTable.Append(new TableRow(tableCell1, tableCell2, tableCell3));
                }
            }

            document.Save();
            document.Close();

            var content = await File.ReadAllBytesAsync(tempFile);
            File.Delete(tempFile);

            return content;
        }


        #region Utilst

        private static void DocumentHeaderRegistration(Document doc)
        {
            var titleProp = new RunProperties().SetFont().SetFontSize().Bold();
            doc.AppendChild(new Paragraph(new ParagraphProperties(new Justification {Val = JustificationValues.Center},
                    new SpacingBetweenLines {After = SpacingBetweenLinesAfter, Line = SpacingBetweenLinesLine}),
                new Run(titleProp.CloneNode(true), new Text("ДЕПАРТАМЕНТ КУЛЬТУРЫ ГОРОДА МОСКВЫ"))));
            doc.AppendChild(new Paragraph(new ParagraphProperties(new Justification {Val = JustificationValues.Center},
                    new SpacingBetweenLines {After = SpacingBetweenLinesAfter, Line = SpacingBetweenLinesLine}),
                new Run(titleProp.CloneNode(true),
                    new Text("Государственное автономное учреждение культуры города Москвы"))));
            doc.AppendChild(new Paragraph(new ParagraphProperties(new Justification {Val = JustificationValues.Center},
                    new SpacingBetweenLines {After = SpacingBetweenLinesAfter, Line = SpacingBetweenLinesLine}),
                new Run(titleProp.CloneNode(true), new Text("\"Московское агентство организации отдыха и туризма\""))));
            var pp = new ParagraphProperties(new Justification {Val = JustificationValues.Center},
                new SpacingBetweenLines {After = SpacingBetweenLinesAfter, Line = SpacingBetweenLinesLine});
            pp.AppendChild(new ParagraphBorders().BottomBorder("000000", 3));
            doc.AppendChild(new Paragraph(pp, new Run(titleProp.CloneNode(true), new Text("(ГАУК \"МОСГОРТУР\")") ,new Break())));
        }

        /// <summary>
        ///     Формирование таблицы перечня документов
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="Docs"></param>
        private static void AddTableDocsList(Document doc, IEnumerable<string> Docs)
        {
            const string _rowonewight = "1000";
            const string _rowtwowight = "9266";

            var tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new LeftBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new RightBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new InsideHorizontalBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new InsideVerticalBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)}));
            var captionRunProperties = new RunProperties
            {
                RunFonts = new RunFonts
                {
                    Ascii = "Times New Roman",
                    HighAnsi = "Times New Roman",
                    ComplexScript = "Times New Roman"
                },
                FontSize = new FontSize {Val = "20"},
                Italic = new Italic()
            };

            var table = new Table();
            table.AppendChild(tblProp.CloneNode(true));

            var _pgf = new List<string>();

            foreach (var _doc in Docs)
            {
                if (_doc.StartsWith("#"))
                {
                    _pgf.Add(_doc.Substring(1));

                    continue;
                }

                if (_doc.StartsWith("$"))
                {
                    _pgf.Add(_doc.Substring(1));
                }
                else
                {
                    if (_pgf.Any())
                    {
                        var _row = new TableRow();
                        var _cell_one = new TableCell();
                        _cell_one.Append(
                            new TableCellProperties(
                                new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowonewight}),
                            new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                        _cell_one.AppendChild(new Paragraph(
                            new ParagraphProperties(
                                new Justification {Val = JustificationValues.Left}),
                            new Run(captionRunProperties.CloneNode(true),
                                new Text("  "))));
                        _row.AppendChild(_cell_one);

                        var _cell_two = new TableCell();
                        _cell_two.Append(
                            new TableCellProperties(
                                new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowtwowight},
                                new VerticalMerge {Val = MergedCellValues.Restart}
                            ),
                            new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                        foreach (var _p in _pgf)
                        {
                            _cell_two.Append(new Paragraph(
                                new ParagraphProperties(
                                    new Justification {Val = JustificationValues.Left}),
                                new Run(captionRunProperties.CloneNode(true),
                                    new Text(_p))));
                        }

                        _row.AppendChild(_cell_two);
                        table.AppendChild(_row);

                        for (var i = _pgf.Count() > 1 ? 2 : 3; i < _pgf.Count(); i++)
                        {
                            var __row = new TableRow();
                            var __cell_one = new TableCell();
                            __cell_one.Append(
                                new TableCellProperties(
                                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowonewight}),
                                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                            __cell_one.AppendChild(new Paragraph(
                                new ParagraphProperties(
                                    new Justification {Val = JustificationValues.Left}),
                                new Run(captionRunProperties.CloneNode(true),
                                    new Text("  "))));
                            __row.AppendChild(__cell_one);

                            var __cell_two = new TableCell();
                            __cell_two.Append(
                                new TableCellProperties(
                                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowtwowight},
                                    new VerticalMerge {Val = MergedCellValues.Continue}
                                ),
                                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                            __cell_two.Append(new Paragraph(
                                new ParagraphProperties(
                                    new Justification {Val = JustificationValues.Left}),
                                new Run(captionRunProperties.CloneNode(true),
                                    new Text("  "))));

                            __row.AppendChild(__cell_two);
                            table.AppendChild(__row);
                        }

                        _pgf.Clear();
                    }

                    var row = new TableRow();
                    var cell_one = new TableCell();
                    cell_one.Append(
                        new TableCellProperties(
                            new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowonewight}),
                        new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                    cell_one.AppendChild(new Paragraph(
                        new ParagraphProperties(
                            new Justification {Val = JustificationValues.Left}),
                        new Run(captionRunProperties.CloneNode(true),
                            new Text("  "))));
                    row.AppendChild(cell_one);

                    var cell_two = new TableCell();
                    cell_two.Append(
                        new TableCellProperties(
                            new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = _rowtwowight}),
                        new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                    cell_two.AppendChild(new Paragraph(
                        new ParagraphProperties(
                            new Justification {Val = JustificationValues.Left}),
                        new Run(captionRunProperties.CloneNode(true),
                            new Text(_doc))));
                    row.AppendChild(cell_two);
                    table.AppendChild(row);
                }
            }

            doc.AppendChild(table);
        }

        /// <summary>
        ///     Формирование таблицы об услугах, оказанных ребенку\детям в течение последних 3-х лет
        /// </summary>
        private static void AddTableChildTours(Document doc, IEnumerable<Request> requests, IEnumerable<int>years)
        {
            var titleRequestRunProperties = new RunProperties();
            titleRequestRunProperties.AppendChild(new RunFonts
            {
                Ascii = "Times New Roman",
                HighAnsi = "Times New Roman",
                ComplexScript = "Times New Roman"
            });
            titleRequestRunProperties.AppendChild(new FontSize {Val = Size22});

            var titleRequestRunPropertiesBold = titleRequestRunProperties.CloneNode(true);
            titleRequestRunPropertiesBold.AppendChild(new Bold());

            var tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new LeftBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new RightBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new InsideHorizontalBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)},
                    new InsideVerticalBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)}));

            var table = new Table();
            table.AppendChild(tblProp.CloneNode(true));

            //первая строка (шапка)
            var row = new TableRow();
            var cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Left}),
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Год кампании"))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()},
                    new TableCellBorders(new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Left}),
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Вид услуги (путевка, сертификат, компенсация)"))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth
                    {
                        Type = TableWidthUnitValues.Dxa,
                        Width = (ThirdColumn + FourthColumn + FifthColumn /*+ SixthColumn*/).ToString()
                    }),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Организация отдыха и оздоровления (в случае предоставления путевки для отдыха и оздоровления), даты заезда"))));
            row.AppendChild(cell);
            table.AppendChild(row);

            var moneyTypes = new[]
            {
                (long?) TypeOfRestEnum.MoneyOn18, (long?) TypeOfRestEnum.MoneyOn3To7,
                (long?) TypeOfRestEnum.MoneyOn7To15, (long?) TypeOfRestEnum.MoneyOnInvalidOn4To17
            };

            //данные о предоставленных услугах

            foreach (var year in years)
            {

                Request request = requests.FirstOrDefault(req => req.YearOfRest.Year == year);

                //string year = request?.YearOfRest?.Name;
                //if (request != null)
                //{
                //    if (request.ParentRequestId.HasValue && request.YearOfRest?.Year - 1 == request?.ParentRequest.YearOfRest?.Year)
                //    {
                //        year = $"{request.ParentRequest.YearOfRest?.Name} (дополнительная кампания)";
                //    }
                //}
                //else if (request == null)
                //{
                //    year = $"{request.ParentRequest.YearOfRest?.Name} (дополнительная кампания)";
                //}

                row = new TableRow();
                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Left}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(year.ToString()))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Left}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(request?.TypeOfRest?.Name))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth
                        {
                            Type = TableWidthUnitValues.Dxa,
                            Width = (ThirdColumn + FourthColumn + FifthColumn + SixthColumn).ToString()
                        }),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(request == null? Space:
                            request.TourId.HasValue
                            ? $"{request.Tour.Hotels?.Name}, c {request.Tour.DateIncome.FormatEx(string.Empty)} по {request.Tour.DateOutcome.FormatEx(string.Empty)}"
                            : (request.RequestOnMoney && !moneyTypes.Contains(request.TypeOfRestId)
                                ? "Осуществлен выбор сертификата на втором этапе заявочной кампании"
                                : Space)))));
                row.AppendChild(cell);
                table.AppendChild(row);
            }

            doc.AppendChild(table);
        }

        /// <summary>
        ///     Формирование статической таблицы об услугах, оказанных ребенку\детям в течение последних 3-х лет
        /// </summary>
        private static void AddStaticTableChildTours(Document doc, IEnumerable<Request> requests, IEnumerable<long> yearIds)
        {

            var titleRequestRunProperties = new RunProperties();
            titleRequestRunProperties.AppendChild(new RunFonts
            {
                Ascii = "Times New Roman",
                HighAnsi = "Times New Roman",
                ComplexScript = "Times New Roman"
            });
            titleRequestRunProperties.AppendChild(new FontSize { Val = Size22 });

            var titleRequestRunPropertiesBold = titleRequestRunProperties.CloneNode(true);
            titleRequestRunPropertiesBold.AppendChild(new Bold());

            var tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) },
                    new BottomBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) },
                    new LeftBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) },
                    new RightBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) },
                    new InsideHorizontalBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) },
                    new InsideVerticalBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) }));

            var table = new Table();
            table.AppendChild(tblProp.CloneNode(true));

            //первая строка (шапка)
            var row = new TableRow();
            var cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString() }),
                new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification { Val = JustificationValues.Left }),
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Год кампании"))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString() },
                    new TableCellBorders(new BottomBorder { Val = new EnumValue<BorderValues>(BorderValues.Single) })),
                new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification { Val = JustificationValues.Left }),
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Вид услуги (путевка, сертификат, компенсация)"))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth
                    {
                        Type = TableWidthUnitValues.Dxa,
                        Width = (ThirdColumn + FourthColumn + FifthColumn + SixthColumn).ToString()
                    }),
                new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
            cell.AppendChild(new Paragraph(
                new Run(titleRequestRunPropertiesBold.CloneNode(true),
                    new Text("Организация отдыха и оздоровления (в случае предоставления путевки для отдыха и оздоровления), даты заезда"))));
            row.AppendChild(cell);
            table.AppendChild(row);

            var moneyTypes = new[]
            {
                (long?) TypeOfRestEnum.MoneyOn18, (long?) TypeOfRestEnum.MoneyOn3To7,
                (long?) TypeOfRestEnum.MoneyOn7To15, (long?) TypeOfRestEnum.MoneyOnInvalidOn4To17
            };

            //данные о предоставленных льготах
            foreach (var request in requests)
            {
                var year = request.YearOfRest?.Name;
                if (request.ParentRequestId.HasValue &&
                    request.YearOfRest?.Year - 1 == request.ParentRequest.YearOfRest?.Year)
                {
                    year = $"{request.ParentRequest.YearOfRest?.Name} (дополнительная кампания)";
                }

                row = new TableRow();
                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString() }),
                    new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification { Val = JustificationValues.Left }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(year))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth { Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString() },
                        new TableCellBorders(new BottomBorder
                        { Val = new EnumValue<BorderValues>(BorderValues.Single) })),
                    new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification { Val = JustificationValues.Left }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(request.TypeOfRest?.Name))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth
                        {
                            Type = TableWidthUnitValues.Dxa,
                            Width = (ThirdColumn + FourthColumn + FifthColumn + SixthColumn).ToString()
                        }),
                    new TableCellVerticalAlignment { Val = TableVerticalAlignmentValues.Bottom });
                cell.AppendChild(new Paragraph(
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(request.TourId.HasValue
                            ? $"{request.Tour.Hotels?.Name}, c {request.Tour.DateIncome.FormatEx(string.Empty)} по {request.Tour.DateOutcome.FormatEx(string.Empty)}"
                            : (request.RequestOnMoney && !moneyTypes.Contains(request.TypeOfRestId)
                                ? "Осуществлен выбор сертификата на втором этапе заявочной кампании"
                                : Space)))));
                row.AppendChild(cell);
                table.AppendChild(row);
            }

            doc.AppendChild(table);
        }


        /// <summary>
        ///     Блок подписией для ЛОК 2019
        /// </summary>
        private static void SignBlockNotification2019(Document doc, Account account, string signText = null)
        {
            if (string.IsNullOrWhiteSpace(signText))
            {
                signText =
                    "Подпись заявителя, подтверждающая получение уведомления о регистрации заявления на выплату компенсации за самостоятельно приобретенную родителями или иными законными представителями путевку для отдыха и оздоровления:";
            }

            SignWorkerBlock(doc, account);

            var titleRequestRunProperties = new RunProperties();
            titleRequestRunProperties.AppendChild(new RunFonts
            {
                Ascii = "Times New Roman",
                HighAnsi = "Times New Roman",
                ComplexScript = "Times New Roman"
            });
            titleRequestRunProperties.AppendChild(new FontSize {Val = "22"});

            var tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new LeftBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new RightBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new InsideHorizontalBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new InsideVerticalBorder {Val = new EnumValue<BorderValues>(BorderValues.None)}));
            var signRunProperties = new RunProperties().SetFont().SetFontSizeSupperscript();

            doc.AppendChild(
                new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Both},
                        new SpacingBetweenLines {After = Size20},
                        new Indentation {FirstLine = FirstLineIndentation600.ToString()}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(signText) {Space = SpaceProcessingModeValues.Preserve})
                ));

            var table = new Table();
            //---------------------------------------------------------------------------
            var row = new TableRow();

            table.AppendChild(tblProp.CloneNode(true));

            var cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "1731"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(titleRequestRunProperties.CloneNode(true),
                    new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "2731"},
                    new TableCellBorders(new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(titleRequestRunProperties.CloneNode(true),
                    new Text(Space))));
            row.AppendChild(cell);


            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "55"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(new Run(new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "3931"},
                    new TableCellBorders(new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(new ParagraphProperties(new Justification {Val = JustificationValues.Left}),
                new Run(titleRequestRunProperties.CloneNode(true),
                    new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "55"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(new Run(new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "1804"},
                    new TableCellBorders(new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(titleRequestRunProperties.CloneNode(true),
                    new Text(DateTime.Now.Date.FormatEx()))));
            row.AppendChild(cell);

            table.AppendChild(row);

            // --------------------------------------------------------------------------------------
            row = new TableRow();

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "2731"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(titleRequestRunProperties.CloneNode(true),
                    new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "2731"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(signRunProperties.CloneNode(true), new Text("(подпись)"))));
            row.AppendChild(cell);


            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "55"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(new Run(new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "2931"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(signRunProperties.CloneNode(true), new Text("(Ф.И.О. заявителя, расшифровка подписи)"))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "55"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(new Run(new Text(Space))));
            row.AppendChild(cell);

            cell = new TableCell();
            cell.Append(new TableCellProperties(
                    new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = "1804"}),
                new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
            cell.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                new Run(signRunProperties.CloneNode(true), new Text("(дата)"))));
            row.AppendChild(cell);

            table.AppendChild(row);

            doc.AppendChild(table);
        }

        /// <summary>
        ///     Блок подписией для ЛОК 2020
        /// </summary>
        public static void SignBlockNotification2020(Document doc, Account account, string functionName = Space)
        {
            var titleRequestRunProperties = new RunProperties();
            titleRequestRunProperties.AppendChild(new RunFonts
            {
                Ascii = "Times New Roman",
                HighAnsi = "Times New Roman",
                ComplexScript = "Times New Roman"
            });
            titleRequestRunProperties.AppendChild(new FontSize {Val = Size22});

            var tblProp = new TableProperties(
                new TableBorders(
                    new TopBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new BottomBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new LeftBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new RightBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new InsideHorizontalBorder {Val = new EnumValue<BorderValues>(BorderValues.None)},
                    new InsideVerticalBorder {Val = new EnumValue<BorderValues>(BorderValues.None)}));
            var signRunProperties = new RunProperties().SetFont().SetFontSizeSupperscript();

            var table = new Table();
            table.AppendChild(tblProp.CloneNode(true));


            //отступ - нулевая строка
            {
                doc.AppendChild(new Paragraph(
                new ParagraphProperties(new Justification { Val = JustificationValues.Both },
                new SpacingBetweenLines { After = Size20 })));
            }
            //первая строка
            {
                var row = new TableRow();

                var cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After="1"}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = ThirdColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new ParagraphProperties( new SpacingBetweenLines { After = "1" }),new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FourthColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Left}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FifthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new ParagraphProperties( new SpacingBetweenLines { After = "1" }), new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SixthColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(DateTime.Now.Date.FormatEx()))));
                row.AppendChild(cell);

                table.AppendChild(row);
            }

            //вторая строка
            {
                var row = new TableRow();

                var cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text("(подпись заявителя)"))));
                row.AppendChild(cell);


                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = ThirdColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FourthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text("(ФИО заявителя, расшифровка подписи)"))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FifthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SixthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text("(дата)"))));
                row.AppendChild(cell);

                table.AppendChild(row);
            }

            //третья строка
            {
                var row = new TableRow();

                var cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(functionName))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(
                            $"{account.Name.FormatEx()}{(string.IsNullOrWhiteSpace(account.Position) ? string.Empty : $", {account.Position}")}"))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = ThirdColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines { After = "1" }), new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FourthColumn.ToString()},
                        new TableCellBorders(new BottomBorder
                            {Val = new EnumValue<BorderValues>(BorderValues.Single)})),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Left}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FifthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new ParagraphProperties(new SpacingBetweenLines { After = "1" }), new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SixthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}, new SpacingBetweenLines { After = "1" }),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                table.AppendChild(row);
            }

            //четвёртая строка
            {
                var row = new TableRow();

                var cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FirstColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(titleRequestRunProperties.CloneNode(true),
                        new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SecondColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text("(ФИО работника, должность)"))));
                row.AppendChild(cell);


                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = ThirdColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FourthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text("(подпись работника)"))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = FifthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(new Run(new Text(Space))));
                row.AppendChild(cell);

                cell = new TableCell();
                cell.Append(new TableCellProperties(
                        new TableCellWidth {Type = TableWidthUnitValues.Dxa, Width = SixthColumn.ToString()}),
                    new TableCellVerticalAlignment {Val = TableVerticalAlignmentValues.Bottom});
                cell.AppendChild(new Paragraph(
                    new ParagraphProperties(new Justification {Val = JustificationValues.Center}),
                    new Run(signRunProperties.CloneNode(true), new Text(Space))));
                row.AppendChild(cell);

                table.AppendChild(row);
            }

            doc.AppendChild(table);
        }


        //Wird in diesem Textbaustein nicht gebraucht.
        public Paragraph GetParagraph()
        {
            return null;
        }

        public TableCell GetZelle()
        {
            return this._zelle;
        }

        #region Kopierter Code aus altem TERoffice
        private TableCell CreateTextCell(string width, string content, bool bold = false, int? colspan = null, JustificationValues alignment = JustificationValues.Left, string shading = null, MergedCellValues? merge = null, TableCellBorders border = null, string fontSize = null)
        {
            TableCell tableCell = new TableCell();
            TableCellProperties tableCellProperties = new TableCellProperties();
            if (merge != null)
            {
                tableCellProperties.Append(new VerticalMerge() { Val = merge });
            }
            TableCellWidth tableCellWidth = new TableCellWidth() { Width = width, Type = TableWidthUnitValues.Dxa };

            if (shading != null)
            {
                tableCellProperties.Append(new Shading() { Val = ShadingPatternValues.Clear, Color = "auto", Fill = shading });
            }

            tableCellProperties.Append(tableCellWidth);
            if (border != null)
            {
                tableCellProperties.Append((TableCellBorders)border.Clone());
            }

            Paragraph paragraph = new Paragraph();
            ParagraphProperties paraprop = new ParagraphProperties();
            Justification justification = new Justification() { Val = alignment };
            Indentation indent = new Indentation() { Right = "0" };
            paraprop.Append(justification);
            paraprop.Append(indent);
            paragraph.Append(paraprop);


            Run run = new Run();
            Text text = new Text { Text = content };

            if (bold)
            {
                RunProperties runProperties = new RunProperties();
                runProperties.Append(new Bold());
                run.Append(runProperties);
            }

            if (fontSize != null)
            {
                if (run.RunProperties == null)
                {
                    run.RunProperties = new RunProperties();
                }

                run.RunProperties.FontSize = new FontSize() { Val = fontSize };
            }

            if (colspan != null)
            {
                GridSpan gridSpan = new GridSpan() { Val = colspan };
                tableCellProperties.Append(gridSpan);
            }

            run.Append(text);
            paragraph.Append(run);
            tableCell.Append(tableCellProperties);
            tableCell.Append(paragraph);
            return tableCell;
        }

        private TableCell CreateTextCell(List<Paragraph> content, string width, int? colspan = null, MergedCellValues? merge = null, TableCellBorders border = null)
        {
            if (content.Count == 0)
            {
                content.Add(new Paragraph(new Run(new Text())));
            }

            TableCell tableCell = new TableCell();
            TableCellProperties tableCellProperties = new TableCellProperties();
            TableCellWidth tableCellWidth = new TableCellWidth() { Width = width, Type = TableWidthUnitValues.Dxa };
            if (border != null)
            {
                tableCellProperties.AppendChild((TableCellBorders)border.Clone());
            }

            if (merge != null)
            {
                tableCellProperties.Append(new VerticalMerge() { Val = merge });
            }

            tableCellProperties.Append(tableCellWidth);
            if (colspan != null)
            {
                GridSpan gridSpan = new GridSpan() { Val = colspan };
                tableCellProperties.Append(gridSpan);
            }

            tableCell.Append(tableCellProperties);
            tableCell.Append(content);

            return tableCell;
        }

        private List<Paragraph> BuildRechteText(Dienstbarkeit dienstbarkeit, string rootKreis, bool showRangaenderung = true)
        {
            var result = new List<Paragraph>();

            if (dienstbarkeit.Beziehungen != null && dienstbarkeit.Beziehungen.Any(i => i.Status == "R"))
            {
                var nrText = false;
                Dictionary<string, List<List<Run>>> dicGS = new Dictionary<string, List<List<Run>>>();
                Dictionary<string, List<Paragraph>> dicPersons = new Dictionary<string, List<Paragraph>>();
                // z.G. oder z.L. nur einmal einfügen am Anfang
                bool grolTextSet = false;
                dienstbarkeit.Beziehungen.Where(i => i.Status == "R").ToList().ForEach(i =>
                {
                    var key = i.Grol;
                    if (!dicGS.ContainsKey(key)) dicGS.Add(key, new List<List<Run>>());
                    if (i.Grundstück.Grundbuchnummer != null)
                    {
                        nrText = true;
                        var value = String.Join(", ", GetGSNummer(i.Grundstück, rootKreis));
                        List<Run> textList = new List<Run>();
                        if (dicGS[key].Count == 0)
                        {
                            textList.Add(new Run(new Text(value)));
                            dicGS[key].Add(textList);
                        }
                        else
                        {
                            var text = dicGS[key][0];
                            text.Add(new Run(new Text(", " + value)));
                        }
                    }

                    if (i.Person.Status != null)
                    {


                        string einzugHaengend = "0";
                        string einzugErsteLinie = "0";
                        string einzug = "424";
                        var personText = GetPersonText(i.Person);
                        var runList = personText.Item1; // item1 = name
                runList.AddRange(personText.Item2); // item2 = adresseif (!dicPersons.ContainsKey(key)) 
                if (!dicPersons.ContainsKey(key)) dicPersons.Add(key, new List<Paragraph>());
                        if (!grolTextSet)
                        {
                            var text = new Text($"{GetGROLText(key)}" + " ")
                            { Space = SpaceProcessingModeValues.Preserve };
                            grolTextSet = true;
                            runList.Insert(0, new Run(text));
                            einzugErsteLinie = "424";
                            einzugHaengend = "424";
                        }

                        var para = new Paragraph(runList.ToArray());
                        var paraprop = new ParagraphProperties();
                        var indent = new Indentation() { Left = einzug, Hanging = einzugHaengend, FirstLine = einzugErsteLinie };
                        paraprop.Append(indent);
                        para.Append(paraprop);

                        dicPersons[key].Add(para);

                    }
                });

                foreach (var key in dicGS.Keys)
                {
                    string einzug = "424";
                    string prepend = $"{GetGROLText(key)}" + (nrText && !string.Join(", ", dicGS[key]).Contains("s.u.d") ? " Nr." : "");
                    if (prepend.Contains("Nr"))
                    {
                        einzug = "707";
                        if (prepend.Contains("+")) einzug = "1274";
                    }
                    else if (prepend.Contains("+")) einzug = "951";

                    foreach (var y in dicGS[key])
                    {
                        y.Insert(0, new Run(new Text(prepend + " ") { Space = SpaceProcessingModeValues.Preserve }));
                        var p = new Paragraph(y.ToArray());
                        var indent = new Indentation() { Left = einzug };
                        var paraprop = new ParagraphProperties();
                        paraprop.Append(indent);
                        if (!String.IsNullOrEmpty(prepend)) indent.Hanging = einzug;
                        result.Add(p);
                        prepend = " ";
                    }
                    if (dicPersons.ContainsKey(key)) // wenn es dazu Personen hat, anzeigen
                    {
                        result.AddRange(dicPersons[key]);
                    }
                }
            }
            return result;
        }

        private Tuple<List<Run>, List<Run>> GetPersonText(Person person)
        {
            switch (person.Typ)
            {
                default:
                case "N":
                    {
                        //ledigername immer
                        var ledigerName = person.LedigName;
                        if (!string.IsNullOrEmpty(ledigerName))
                        {
                            ledigerName = $"-{ledigerName}";
                        }
                        List<Run> namenList = new List<Run>();

                        var vornamen = person.Vorname.Split(' ');
                        var rufnamen = person.Rufname.Split(' ');

                        namenList.Add(new Run(new Text($"{person.Name}{ledigerName}") { Space = SpaceProcessingModeValues.Preserve }));
                        Text t = new Text();
                        foreach (var vorname in vornamen)
                        {
                            var runBlank = new Run(new Text(" ") { Space = SpaceProcessingModeValues.Preserve }); // das Blank separat machen, da es sonst auch unterstrichen wird
                            namenList.Add(runBlank);
                            bool underline = rufnamen.Contains(vorname);
                            var run = new Run(new Text(vorname));
                            namenList.Add(run);
                        }
                        var name = $"{person.Name}{ledigerName} {person.Vorname}";

                        var ort = "";
                        if (!String.IsNullOrEmpty(person.Geburtsort)) ort += $", von {person.Geburtsort}";
                        if (!String.IsNullOrEmpty(person.Nationalitaet)) ort += $", Staatsangehörigkeit: { person.Nationalitaet }";

                        var plz = person.Plz;
                        var land = "";
                        if (!String.IsNullOrEmpty(person.Land) && person.Land != "CH" && person.Land != "Schweiz")
                        {
                            //vor plz ländercode
                            plz = person.Land + "-" + plz;
                            //land in klammern am schluss N CH
                            land = $" ({person.Laenderkürzel})";
                        }

                        if (!String.IsNullOrEmpty(plz)) plz += " ";

                        //N: wohnhaft in eigentümer -> land egal
                        var strasse = ", " + person.Strasse;
                        var text = "";
                        text = $", geb. {person.Geburtsdatum}{ort}{strasse}, {plz}{person.Ort}{land}";
                        List<Run> adressListe = new List<Run>
                        {
                            new Run(new Text(text))
                        };
                        return new Tuple<List<Run>, List<Run>>(namenList, adressListe);
                    }
                case "G":
                    {
                        var name = new Run(new Text(person.Name));
                        var rform = "";
                        rform = person.Rechtsform;

                        var detail = ", " + String.Join(", ", new List<string> { rform, person.Strasse, person.Plz + " " + person.Ort }.Where(i => !String.IsNullOrWhiteSpace(i)));
                        if (detail == ", ")
                        {
                            detail = "";
                        }

                        Run detailRun = new Run(new Text(detail));

                        return new Tuple<List<Run>, List<Run>>(new List<Run>() { name }, new List<Run>() { detailRun });
                    }
                case "J":
                    {
                        var name = new Run(new Text(person.Name));
                        var sitz = "";
                        var rechtsForm = "";

                        sitz = $"mit Sitz in { person.Sitz}";
                        rechtsForm = $"{person.Rechtsform}";


                        var detailText = ", " + String.Join(", ", new List<string> { sitz, rechtsForm, person.Strasse, person.Plz + " " + person.Ort }.Where(i => !String.IsNullOrWhiteSpace(i)));
                        if (detailText == ", ")
                        {
                            detailText = "";
                        }

                        var detailRun = new Run(new Text(detailText));
                        return new Tuple<List<Run>, List<Run>>(new List<Run>() { name }, new List<Run>() { detailRun });
                    }
            }
        }

		private static Drawing PictureElement(string relationshipId)
		{
			// Define the reference of the image.
			var element =
				 new Drawing(
					 new Inline(
						 new Extent() { Cx = 990000L, Cy = 792000L },
						 new EffectExtent()
						 {
							 LeftEdge = 0L,
							 TopEdge = 0L,
							 RightEdge = 0L,
							 BottomEdge = 0L
						 },
						 new DocProperties()
						 {
							 Id = (UInt32Value)1U,
							 Name = "Picture 1"
						 },
						 new NonVisualGraphicFrameDrawingProperties(
							 new A.GraphicFrameLocks() { NoChangeAspect = true }),
						 new A.Graphic(
							 new A.GraphicData(
								 new PIC.Picture(
									 new PIC.NonVisualPictureProperties(
										 new PIC.NonVisualDrawingProperties()
										 {
											 Id = (UInt32Value)0U,
											 Name = "New Bitmap Image.jpg"
										 },
										 new PIC.NonVisualPictureDrawingProperties()),
									 new PIC.BlipFill(
										 new A.Blip(
											 new A.BlipExtensionList(
												 new A.BlipExtension()
												 {
													 Uri =
													   "{28A0092B-C50C-407E-A947-70E740481C1C}"
												 })
										 )
										 {
											 Embed = relationshipId,
											 CompressionState =
											 A.BlipCompressionValues.Print
										 },
										 new A.Stretch(
											 new A.FillRectangle())),
									 new PIC.ShapeProperties(
										 new A.Transform2D(
											 new A.Offset() { X = 0L, Y = 0L },
											 new A.Extents() { Cx = 990000L, Cy = 792000L }),
										 new A.PresetGeometry(
											 new A.AdjustValueList()
										 ) { Preset = A.ShapeTypeValues.Rectangle }))
							 ) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" })
					 )
					 {
						 DistanceFromTop = (UInt32Value)0U,
						 DistanceFromBottom = (UInt32Value)0U,
						 DistanceFromLeft = (UInt32Value)0U,
						 DistanceFromRight = (UInt32Value)0U,
						 EditId = "50D07946"
					 });
			return element;
		}
		// Creates an Paragraph instance and adds its children.
		public TableRow GenerateTableRow(IndividualInfo ii, string iid)
		{
			TableRow tableRow1 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00442AD3" };

			TableRowProperties tableRowProperties1 = new TableRowProperties();
			CantSplit cantSplit1 = new CantSplit();

			tableRowProperties1.Append(cantSplit1);

			TableCell tableCell1 = new TableCell();

			TableCellProperties tableCellProperties1 = new TableCellProperties();
			TableCellWidth tableCellWidth1 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };

			tableCellProperties1.Append(tableCellWidth1);

			Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run1 = new Run();
			Break break1 = new Break();

			run1.Append(break1);

			Run run2 = new Run();

			RunProperties runProperties1 = new RunProperties();
			NoProof noProof1 = new NoProof();

			runProperties1.Append(noProof1);
			Text text1 = new Text();
			text1.Text = ii.FirstName;

			run2.Append(runProperties1);
			run2.Append(text1);

			Run run3 = new Run();
			Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text2.Text = " ";

			run3.Append(text2);

			Run run4 = new Run();

			RunProperties runProperties2 = new RunProperties();
			NoProof noProof2 = new NoProof();

			runProperties2.Append(noProof2);
			Text text3 = new Text();
			text3.Text = ii.LastName;

			run4.Append(runProperties2);
			run4.Append(text3);

			paragraph1.Append(run1);
			paragraph1.Append(run2);
			paragraph1.Append(run3);
			paragraph1.Append(run4);

			Paragraph paragraph2 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run5 = new Run();

			RunProperties runProperties3 = new RunProperties();
			NoProof noProof3 = new NoProof();

			runProperties3.Append(noProof3);
			Text text4 = new Text();
			text4.Text = ii.Address;

			run5.Append(runProperties3);
			run5.Append(text4);

			paragraph2.Append(run5);


			Paragraph paragraph2a = null;
			if (ii.Address2.HasValue())
			{
				paragraph2a = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };
				Run r = new Run();

				RunProperties rp = new RunProperties();
				NoProof np = new NoProof();

				rp.Append(np);
				Text tt = new Text();
				tt.Text = ii.Address;

				r.Append(rp);
				r.Append(tt);

				paragraph2a.Append(r);
			}


			Paragraph paragraph3 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00731A43", RsidRunAdditionDefault = "00FB1F22" };

			Run run6 = new Run();

			RunProperties runProperties4 = new RunProperties();
			NoProof noProof4 = new NoProof();

			runProperties4.Append(noProof4);
			Text text5 = new Text();
			text5.Text = ii.CityStateZip;
			run6.Append(runProperties4);
			run6.Append(text5);

			paragraph3.Append(run6);

			Paragraph paragraph4 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Table table1 = new Table();

			TableProperties tableProperties1 = new TableProperties();
			TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" };
			TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto };

			TableBorders tableBorders1 = new TableBorders();
			TopBorder topBorder1 = new TopBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			LeftBorder leftBorder1 = new LeftBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			BottomBorder bottomBorder1 = new BottomBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			RightBorder rightBorder1 = new RightBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideHorizontalBorder insideHorizontalBorder1 = new InsideHorizontalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };
			InsideVerticalBorder insideVerticalBorder1 = new InsideVerticalBorder() { Val = BorderValues.None, Color = "auto", Size = (UInt32Value)0U, Space = (UInt32Value)0U };

			tableBorders1.Append(topBorder1);
			tableBorders1.Append(leftBorder1);
			tableBorders1.Append(bottomBorder1);
			tableBorders1.Append(rightBorder1);
			tableBorders1.Append(insideHorizontalBorder1);
			tableBorders1.Append(insideVerticalBorder1);
			TableLook tableLook1 = new TableLook() { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };

			tableProperties1.Append(tableStyle1);
			tableProperties1.Append(tableWidth1);
			tableProperties1.Append(tableBorders1);
			tableProperties1.Append(tableLook1);

			TableGrid tableGrid1 = new TableGrid();
			GridColumn gridColumn1 = new GridColumn() { Width = "1435" };
			GridColumn gridColumn2 = new GridColumn() { Width = "3122" };

			tableGrid1.Append(gridColumn1);
			tableGrid1.Append(gridColumn2);

			TableRow tableRow2 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell2 = new TableCell();

			TableCellProperties tableCellProperties2 = new TableCellProperties();
			TableCellWidth tableCellWidth2 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties2.Append(tableCellWidth2);

			Paragraph paragraph5 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run11 = new Run();
			Text text10 = new Text();
			text10.Text = "Email";

			run11.Append(text10);

			paragraph5.Append(run11);

			tableCell2.Append(tableCellProperties2);
			tableCell2.Append(paragraph5);

			TableCell tableCell3 = new TableCell();

			TableCellProperties tableCellProperties3 = new TableCellProperties();
			TableCellWidth tableCellWidth3 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties3.Append(tableCellWidth3);
			Paragraph paragraph6 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			paragraph6.Append(new Run(new Text(ii.Email)));

			tableCell3.Append(tableCellProperties3);
			tableCell3.Append(paragraph6);

			tableRow2.Append(tableCell2);
			tableRow2.Append(tableCell3);

			TableRow tableRow3 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell4 = new TableCell();

			TableCellProperties tableCellProperties4 = new TableCellProperties();
			TableCellWidth tableCellWidth4 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties4.Append(tableCellWidth4);

			Paragraph paragraph7 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run12 = new Run();
			Text text11 = new Text();
			text11.Text = "Home Phone";

			run12.Append(text11);

			paragraph7.Append(run12);

			tableCell4.Append(tableCellProperties4);
			tableCell4.Append(paragraph7);

			TableCell tableCell5 = new TableCell();

			TableCellProperties tableCellProperties5 = new TableCellProperties();
			TableCellWidth tableCellWidth5 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties5.Append(tableCellWidth5);

			Paragraph paragraph8 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			Run run13 = new Run();

			RunProperties runProperties7 = new RunProperties();
			NoProof noProof7 = new NoProof();

			runProperties7.Append(noProof7);
			Text text12 = new Text();
			text12.Text = ii.HomePhone.FmtFone();

			run13.Append(runProperties7);
			run13.Append(text12);

			Run run14 = new Run();
			Text text13 = new Text() { Space = SpaceProcessingModeValues.Preserve };
			text13.Text = " ";

			run14.Append(text13);

			paragraph8.Append(run13);
			paragraph8.Append(run14);

			tableCell5.Append(tableCellProperties5);
			tableCell5.Append(paragraph8);

			tableRow3.Append(tableCell4);
			tableRow3.Append(tableCell5);

			TableRow tableRow4 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell6 = new TableCell();

			TableCellProperties tableCellProperties6 = new TableCellProperties();
			TableCellWidth tableCellWidth6 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties6.Append(tableCellWidth6);

			Paragraph paragraph9 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run15 = new Run();
			Text text14 = new Text();
			text14.Text = "Cell Phone";

			run15.Append(text14);

			paragraph9.Append(run15);

			tableCell6.Append(tableCellProperties6);
			tableCell6.Append(paragraph9);

			TableCell tableCell7 = new TableCell();

			TableCellProperties tableCellProperties7 = new TableCellProperties();
			TableCellWidth tableCellWidth7 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties7.Append(tableCellWidth7);

			Paragraph paragraph10 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run16 = new Run();

			RunProperties runProperties8 = new RunProperties();
			NoProof noProof8 = new NoProof();

			runProperties8.Append(noProof8);
			Text text15 = new Text();
			text15.Text = ii.CellPhone.FmtFone();

			run16.Append(runProperties8);
			run16.Append(text15);

			paragraph10.Append(run16);

			tableCell7.Append(tableCellProperties7);
			tableCell7.Append(paragraph10);

			tableRow4.Append(tableCell6);
			tableRow4.Append(tableCell7);

			TableRow tableRow5 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell8 = new TableCell();

			TableCellProperties tableCellProperties8 = new TableCellProperties();
			TableCellWidth tableCellWidth8 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties8.Append(tableCellWidth8);

			Paragraph paragraph11 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run17 = new Run();
			Text text16 = new Text();
			text16.Text = "Work Phone";

			run17.Append(text16);

			paragraph11.Append(run17);

			tableCell8.Append(tableCellProperties8);
			tableCell8.Append(paragraph11);

			TableCell tableCell9 = new TableCell();

			TableCellProperties tableCellProperties9 = new TableCellProperties();
			TableCellWidth tableCellWidth9 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties9.Append(tableCellWidth9);

			Paragraph paragraph12 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run18 = new Run();

			RunProperties runProperties9 = new RunProperties();
			NoProof noProof9 = new NoProof();

			runProperties9.Append(noProof9);
			Text text17 = new Text();
			text17.Text = ii.WorkPhone.FmtFone();

			run18.Append(runProperties9);
			run18.Append(text17);

			paragraph12.Append(run18);

			tableCell9.Append(tableCellProperties9);
			tableCell9.Append(paragraph12);

			tableRow5.Append(tableCell8);
			tableRow5.Append(tableCell9);

			TableRow tableRow6 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell10 = new TableCell();

			TableCellProperties tableCellProperties10 = new TableCellProperties();
			TableCellWidth tableCellWidth10 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties10.Append(tableCellWidth10);

			Paragraph paragraph13 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run19 = new Run();
			Text text18 = new Text();
			text18.Text = "Birthday";

			run19.Append(text18);

			paragraph13.Append(run19);

			tableCell10.Append(tableCellProperties10);
			tableCell10.Append(paragraph13);

			TableCell tableCell11 = new TableCell();

			TableCellProperties tableCellProperties11 = new TableCellProperties();
			TableCellWidth tableCellWidth11 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties11.Append(tableCellWidth11);

			Paragraph paragraph14 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00BC57A3", RsidRunAdditionDefault = "00FB1F22" };

			Run run20 = new Run();

			RunProperties runProperties10 = new RunProperties();
			NoProof noProof10 = new NoProof();

			runProperties10.Append(noProof10);
			Text text19 = new Text();
			text19.Text = ii.BirthDay;

			run20.Append(runProperties10);
			run20.Append(text19);

			paragraph14.Append(run20);

			tableCell11.Append(tableCellProperties11);
			tableCell11.Append(paragraph14);

			tableRow6.Append(tableCell10);
			tableRow6.Append(tableCell11);

			TableRow tableRow7 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell12 = new TableCell();

			TableCellProperties tableCellProperties12 = new TableCellProperties();
			TableCellWidth tableCellWidth12 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties12.Append(tableCellWidth12);

			Paragraph paragraph15 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "006D0F9D", RsidRunAdditionDefault = "00FB1F22" };

			Run run21 = new Run();
			Text text20 = new Text();
			text20.Text = "Anniversary";

			run21.Append(text20);

			paragraph15.Append(run21);

			tableCell12.Append(tableCellProperties12);
			tableCell12.Append(paragraph15);

			TableCell tableCell13 = new TableCell();

			TableCellProperties tableCellProperties13 = new TableCellProperties();
			TableCellWidth tableCellWidth13 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties13.Append(tableCellWidth13);
			Paragraph paragraph16 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			paragraph16.Append(new Run(new Text(ii.Anniversary)));

			tableCell13.Append(tableCellProperties13);
			tableCell13.Append(paragraph16);

			tableRow7.Append(tableCell12);
			tableRow7.Append(tableCell13);

			TableRow tableRow8 = new TableRow() { RsidTableRowAddition = "00FB1F22", RsidTableRowProperties = "00731A43" };

			TableCell tableCell14 = new TableCell();

			TableCellProperties tableCellProperties14 = new TableCellProperties();
			TableCellWidth tableCellWidth14 = new TableCellWidth() { Width = "1435", Type = TableWidthUnitValues.Dxa };

			tableCellProperties14.Append(tableCellWidth14);

			Paragraph paragraph17 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			Run run22 = new Run();
			Text text21 = new Text();
			text21.Text = "Spouse";

			run22.Append(text21);

			paragraph17.Append(run22);

			tableCell14.Append(tableCellProperties14);
			tableCell14.Append(paragraph17);

			TableCell tableCell15 = new TableCell();

			TableCellProperties tableCellProperties15 = new TableCellProperties();
			TableCellWidth tableCellWidth15 = new TableCellWidth() { Width = "3122", Type = TableWidthUnitValues.Dxa };

			tableCellProperties15.Append(tableCellWidth15);

			Paragraph paragraph18 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00F06304", RsidRunAdditionDefault = "00FB1F22" };

			ParagraphProperties paragraphProperties1 = new ParagraphProperties();

			ParagraphMarkRunProperties paragraphMarkRunProperties1 = new ParagraphMarkRunProperties();
			NoProof noProof11 = new NoProof();

			paragraphMarkRunProperties1.Append(noProof11);

			paragraphProperties1.Append(paragraphMarkRunProperties1);

			Run run23 = new Run();

			RunProperties runProperties11 = new RunProperties();
			NoProof noProof12 = new NoProof();

			runProperties11.Append(noProof12);
			Text text22 = new Text();
			text22.Text = ii.Spouse;

			run23.Append(runProperties11);
			run23.Append(text22);

			paragraph18.Append(paragraphProperties1);
			paragraph18.Append(run23);

			tableCell15.Append(tableCellProperties15);
			tableCell15.Append(paragraph18);

			tableRow8.Append(tableCell14);
			tableRow8.Append(tableCell15);

			table1.Append(tableProperties1);
			table1.Append(tableGrid1);
			table1.Append(tableRow2);
			table1.Append(tableRow3);
			table1.Append(tableRow4);
			table1.Append(tableRow5);
			table1.Append(tableRow6);
			table1.Append(tableRow7);
			table1.Append(tableRow8);
			Paragraph paragraph19 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00485B24", RsidRunAdditionDefault = "00FB1F22" };

			tableCell1.Append(tableCellProperties1);
			tableCell1.Append(paragraph1);
			tableCell1.Append(paragraph2);
			if (paragraph2a != null)
				tableCell1.Append(paragraph2a);
			tableCell1.Append(paragraph3);
			tableCell1.Append(paragraph4);
			tableCell1.Append(table1);
			tableCell1.Append(paragraph19);

			TableCell tableCell16 = new TableCell();

			TableCellProperties tableCellProperties16 = new TableCellProperties();
			TableCellWidth tableCellWidth16 = new TableCellWidth() { Width = "4788", Type = TableWidthUnitValues.Dxa };
			TableCellVerticalAlignment tableCellVerticalAlignment1 = new TableCellVerticalAlignment() { Val = TableVerticalAlignmentValues.Center };

			tableCellProperties16.Append(tableCellWidth16);
			tableCellProperties16.Append(tableCellVerticalAlignment1);
			tableCell16.Append(tableCellProperties16);

			Paragraph paragraph20 = new Paragraph() { RsidParagraphAddition = "00FB1F22", RsidParagraphProperties = "00960953", RsidRunAdditionDefault = "00FB1F22" };
			ParagraphProperties paragraphProperties2 = new ParagraphProperties();
			Justification justification1 = new Justification() { Val = JustificationValues.Center };

			paragraphProperties2.Append(justification1);
			paragraph20.Append(paragraphProperties2);

			if (iid.HasValue())
			{
				Run run24 = new Run();

				RunProperties runProperties12 = new RunProperties();
				NoProof noProof13 = new NoProof();

				runProperties12.Append(noProof13);

				Drawing drawing1 = new Drawing();

				Wp.Inline inline1 = new Wp.Inline()
									{
										DistanceFromTop = (UInt32Value)0U,
										DistanceFromBottom = (UInt32Value)0U,
										DistanceFromLeft = (UInt32Value)0U,
										DistanceFromRight = (UInt32Value)0U
									};
				Wp.Extent extent1 = new Wp.Extent() { Cx = 1428750L, Cy = 1905000L };
				Wp.EffectExtent effectExtent1 = new Wp.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L };
				Wp.DocProperties docProperties1 = new Wp.DocProperties() { Id = (UInt32Value)1U, Name = "Picture 1", Description = "D:\\Pictures\\ttt.jpg" };

				Wp.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties1 =
					new Wp.NonVisualGraphicFrameDrawingProperties();

				A.GraphicFrameLocks graphicFrameLocks1 = new A.GraphicFrameLocks() { NoChangeAspect = true };
				graphicFrameLocks1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				nonVisualGraphicFrameDrawingProperties1.Append(graphicFrameLocks1);

				A.Graphic graphic1 = new A.Graphic();
				graphic1.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main");

				A.GraphicData graphicData1 = new A.GraphicData() { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" };

				Pic.Picture picture1 = new Pic.Picture();
				picture1.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture");

				Pic.NonVisualPictureProperties nonVisualPictureProperties1 = new Pic.NonVisualPictureProperties();
				Pic.NonVisualDrawingProperties nonVisualDrawingProperties1 = new Pic.NonVisualDrawingProperties()
																			 {
																				 Id = (UInt32Value)0U,
																				 Name = "Picture 459",
																				 Description = "D:\\Pictures\\ttt.jpg"
																			 };

				Pic.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties1 =
					new Pic.NonVisualPictureDrawingProperties();
				A.PictureLocks pictureLocks1 = new A.PictureLocks() { NoChangeAspect = false, NoChangeArrowheads = true };

				nonVisualPictureDrawingProperties1.Append(pictureLocks1);

				nonVisualPictureProperties1.Append(nonVisualDrawingProperties1);
				nonVisualPictureProperties1.Append(nonVisualPictureDrawingProperties1);

				Pic.BlipFill blipFill1 = new Pic.BlipFill();

				A.Blip blip1 = new A.Blip() { Embed = iid };

				A.BlipExtensionList blipExtensionList1 = new A.BlipExtensionList();

				A.BlipExtension blipExtension1 = new A.BlipExtension() { Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}" };

				A14.UseLocalDpi useLocalDpi1 = new A14.UseLocalDpi() { Val = false };
				useLocalDpi1.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");

				blipExtension1.Append(useLocalDpi1);

				blipExtensionList1.Append(blipExtension1);

				blip1.Append(blipExtensionList1);
				A.SourceRectangle sourceRectangle1 = new A.SourceRectangle();

				A.Stretch stretch1 = new A.Stretch();
				A.FillRectangle fillRectangle1 = new A.FillRectangle();

				stretch1.Append(fillRectangle1);

				blipFill1.Append(blip1);
				blipFill1.Append(sourceRectangle1);
				blipFill1.Append(stretch1);

				Pic.ShapeProperties shapeProperties1 = new Pic.ShapeProperties() { BlackWhiteMode = A.BlackWhiteModeValues.Auto };

				A.Transform2D transform2D1 = new A.Transform2D();
				A.Offset offset1 = new A.Offset() { X = 0L, Y = 0L };
				A.Extents extents1 = new A.Extents() { Cx = 1428750L, Cy = 1905000L };

				transform2D1.Append(offset1);
				transform2D1.Append(extents1);

				A.PresetGeometry presetGeometry1 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
				A.AdjustValueList adjustValueList1 = new A.AdjustValueList();

				presetGeometry1.Append(adjustValueList1);
				A.NoFill noFill1 = new A.NoFill();

				A.Outline outline1 = new A.Outline();
				A.NoFill noFill2 = new A.NoFill();

				outline1.Append(noFill2);

				shapeProperties1.Append(transform2D1);
				shapeProperties1.Append(presetGeometry1);
				shapeProperties1.Append(noFill1);
				shapeProperties1.Append(outline1);

				picture1.Append(nonVisualPictureProperties1);
				picture1.Append(blipFill1);
				picture1.Append(shapeProperties1);

				graphicData1.Append(picture1);

				graphic1.Append(graphicData1);

				inline1.Append(extent1);
				inline1.Append(effectExtent1);
				inline1.Append(docProperties1);
				inline1.Append(nonVisualGraphicFrameDrawingProperties1);
				inline1.Append(graphic1);

				drawing1.Append(inline1);

				run24.Append(runProperties12);
				run24.Append(drawing1);

				paragraph20.Append(run24);
			}
			tableCell16.Append(paragraph20);

			BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
			BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };

			tableRow1.Append(tableRowProperties1);
			tableRow1.Append(tableCell1);
			tableRow1.Append(tableCell16);
			tableRow1.Append(bookmarkStart1);
			tableRow1.Append(bookmarkEnd1);
			return tableRow1;
		}


        public  static MemoryStream GetTemplate(int id, string path, out string code,string _userID)
        {
            double Totalcost = 0;
            var memoryStream = new MemoryStream();
            BidPlanInfo item = BidPlanService.GetInstance().getBidPlan(id,_userID);


            SearchAuditInfo audit = AuditService.GetInstance().GetAuditWordByQuoteID(item.QuoteID); 
            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read))
                fileStream.CopyTo(memoryStream);
            code = item.BidPlanCode;
            using (var document = WordprocessingDocument.Open(memoryStream, true))
            {
                document.ChangeDocumentType(WordprocessingDocumentType.Document); // change from template to document
                DateTime date = DateTime.Now;
                string currentDate = "Ngày " + date.ToString("dd/MM/yyyy");
                var body = document.MainDocumentPart.Document.Body;
                var paras = body.Elements<Paragraph>();

                List<string> headers = new List<string>();
                List<List<string>> items = new List<List<string>>();
                headers.Add("STT");
                headers.Add("Tên gói thầu");
                headers.Add("Giá gói thầu");
                headers.Add("Nguồn vốn");
                headers.Add("Hình thức phương thức lựa chọn nhà thầu");
                headers.Add("Thời gian tổ chức lựa chọn nhà thầu");
                headers.Add("Loại hợp đồng");
                headers.Add("Thời gian thực hiện hợp đồng");

                foreach (ItemInfo record in item.Items)
                {
                    Totalcost += record.ItemPrice * record.Amount;

                }
                if (item.IsVAT)
                {
                    Totalcost = Totalcost * (item.VATNumber + 100) / 100;
                }
                string auditCodeEmpty = "         /BB-BKG";
                if (audit.AuditCode== null || audit.AuditCode=="") audit.AuditCode = auditCodeEmpty;
                List<string> row = new List<string>();
                row.Add("1");
                row.Add(item.BidName);

                row.Add(string.Format("{0:0,0}", Totalcost).Replace(",", ".") + " VNĐ");

                row.Add(WordUtils.checkNull(item.CapitalName));
                row.Add((HardData.bidMethod[item.BidMethod - 1]));
                row.Add(item.BidTime);
                row.Add(item.BidType);
                row.Add(item.BidExpirated + " " + item.BidExpiratedUnit);
                items.Add(row);

                Table tableData1 = CreateBidplan1(headers, items, string.Format("{0:0,0}", Totalcost).Replace(",", ".") + " VNĐ");
                Table tableData2 = CreateBidplan2(item , Totalcost);

                string dateInStr = "";
                string auditDateInStr = "";
                dateInStr = "ngày " + item.DateIn.Day + " tháng " + item.DateIn.Month + " năm " + item.DateIn.Year;
                auditDateInStr = "ngày " + audit.InTime.Day + " tháng " + audit.InTime.Month + " năm " + audit.InTime.Year;
                foreach (var text in body.Descendants<Text>())
                {
                    text.Text = text.Text.Replace("#", "");
                    text.Text = text.Text.Replace("bidcompany", WordUtils.checkNull(item.Bid));
                    text.Text = text.Text.Replace("bidplandatein", WordUtils.checkNull(dateInStr));
                    text.Text = text.Text.Replace("currentYear ", DateTime.Now.Year.ToString());
                    text.Text = text.Text.Replace("bidname", WordUtils.checkNull(item.BidName));
                    text.Text = text.Text.Replace("costnumber", " " + string.Format("{0:0,0}", Totalcost).Replace(",", "."));
                    text.Text = text.Text.Replace("coststring", WordUtils.checkNull(Utils.NumberToTextVN((decimal)Totalcost)));
                    text.Text = text.Text.Replace("bidtime", WordUtils.checkNull(item.BidTime));
                    text.Text = text.Text.Replace("capname", WordUtils.checkNull(item.CapitalName));
                    text.Text = text.Text.Replace("bidcontracttype", WordUtils.checkNull(item.BidType));
                    text.Text = text.Text.Replace("bidExpirated", WordUtils.checkNull(item.BidExpirated + " " + item.BidExpiratedUnit));
                    text.Text = text.Text.Replace("bidmethod", WordUtils.checkNull(HardData.bidMethod[item.BidMethod - 1]));
                    text.Text = text.Text.Replace("auditdate", auditDateInStr);
                    text.Text = text.Text.Replace("auditcode", audit.AuditCode + "/BB-BKG");
                    text.Text = text.Text.Replace("location", WordUtils.checkNull(HardData.location[Int32.Parse(item.BidLocation) - 1]));
                    if (text.Text == "table1")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData1, textP2);
                        textP1.Remove();
                    }
                    if (text.Text == "table2")
                    {
                        DocumentFormat.OpenXml.OpenXmlElement textP1 = text.Parent;
                        DocumentFormat.OpenXml.OpenXmlElement textP2 = textP1.Parent;
                        body.InsertAfter(tableData2, textP2);
                        textP1.Remove();
                    }
                }

                document.Save();
                document.Close();
            }
            return memoryStream;
        }

        private static RunProperties Bold()
        {
            RunProperties runProperties = new RunProperties();

            Bold bold = new Bold();

            bold.Val = OnOffValue.FromBoolean(true);
            return runProperties;

        }
        private static Table CreateBidplan1(List<string> headers, List<List<string>> items, string Cost)
        {
            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties tblProperties = new TableProperties();
            TableJustification just = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder topBorder = new TopBorder();
            topBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();
            bottomBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();
            rightBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();
            leftBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();
            insideHBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();
            insideVBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            TableCellProperties cellOneProperties = new TableCellProperties();
            List<TableCell> headerCells = new List<TableCell>();
            int index = 0;
            int[] widths = { 1400, 1800, 1600, 1300, 1300, 1300, 1300, 1300 };
            foreach (string itemHeaders in headers)
            {
                TableCell tcName12 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(Bold(), new Text(itemHeaders))));
                tcName12.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[index].ToString() }));
                headerCells.Add(tcName12);
                index++;
            }
            //// Create a new row
            TableRow tr = new TableRow();
            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List<TableCell> dataCells = new List<TableCell>();
            TableCell tcName1;
            foreach (List<string> rowItems in items)
            {
                index = 0;
                dataCells = new List<TableCell>();
                foreach (string data in rowItems)
                {
                    tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(Bold(), new Text( data))));
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[index].ToString() }));
                    dataCells.Add(tcName1);
                    index++;
                }
                tr = new TableRow();
                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);
            }

            // total row
            tr = new TableRow();
            dataCells = new List<TableCell>();

            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(Bold(), new Text("Tổng Giá"))));
            tcName1.Append(new TableCellProperties(
            new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1400" }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);

            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(Bold(), new Text())));
            tcName1.Append(new TableCellProperties(
            new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "2200" }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Continue
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);


            tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Center }), new Run(Bold(), new Text(Cost))));
            tcName1.Append(new TableCellProperties(
            new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1800" }));
            cellOneProperties = new TableCellProperties();
            cellOneProperties.Append(new HorizontalMerge()
            {
                Val = MergedCellValues.Restart
            });
            tcName1.Append(cellOneProperties);
            dataCells.Add(tcName1);


            for (int loopindex = 3; loopindex < widths.Length; loopindex++)
            {
                tcName1 = new TableCell(new Paragraph(new Run(new Text(Cost))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString() }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Continue
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);
            }
            tr.Append(dataCells.ToArray());
            tbl.AppendChild(tr);

            return tbl;
        }

        private static Table CreateBidplan2(BidPlanInfo item, double Totalcost)
        {
            //prepare ITEMs
            List<string> headers = new List<string>();
            List<List<string>> items = new List<List<string>>();
            headers.Add("STT");
            headers.Add("Tên và mô tả thiết bị");
            headers.Add("Đơn vị tính");
            headers.Add("Số lượng");
           
            headers.Add("Đơn giá(VNĐ)");
            headers.Add("Thành tiền (VNĐ)");

            int[] widths = { 1000, 3000, 1600, 1600, 2100, 2100 };


            int index = 1;
          
            foreach (ItemInfo record in item.Items)
            {
                List<string> row = new List<string>();
                row.Add(index.ToString());
                row.Add(record.ItemName);
                row.Add(record.ItemUnit);
                row.Add(record.Amount.ToString());         
                row.Add(string.Format("{0:0,0}", record.ItemPrice).Replace(",", "."));
                row.Add(string.Format("{0:0,0}", record.ItemPrice * record.Amount).Replace(",", "."));
                items.Add(row);
                index++;
            }



            //// Create a new table
            Table tbl = new Table();

            //// Create the table properties
            TableProperties tblProperties = new TableProperties();
            TableJustification just = new TableJustification();

            just.Val = TableRowAlignmentValues.Center;
            //// Create Table Borders
            TableBorders tblBorders = new TableBorders();
            TopBorder topBorder = new TopBorder();
            topBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            topBorder.Color = "000000";
            tblBorders.AppendChild(topBorder);
            BottomBorder bottomBorder = new BottomBorder();
            bottomBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            bottomBorder.Color = "000000";
            tblBorders.AppendChild(bottomBorder);
            RightBorder rightBorder = new RightBorder();
            rightBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            rightBorder.Color = "000000";
            tblBorders.AppendChild(rightBorder);
            LeftBorder leftBorder = new LeftBorder();
            leftBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            leftBorder.Color = "000000";
            tblBorders.AppendChild(leftBorder);
            InsideHorizontalBorder insideHBorder = new InsideHorizontalBorder();
            insideHBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            insideHBorder.Color = "000000";
            tblBorders.AppendChild(insideHBorder);
            InsideVerticalBorder insideVBorder = new InsideVerticalBorder();
            insideVBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
            insideVBorder.Color = "000000";
            tblBorders.AppendChild(insideVBorder);
            //// Add the table borders to the properties
            tblProperties.AppendChild(tblBorders);
            tblProperties.AppendChild(just);
            //// Add the table properties to the table
            tbl.AppendChild(tblProperties);
            //// Add a cell to each column in the row
            ///
            List<TableCell> headerCells = new List<TableCell>();
            TableCell tcName1;
            foreach (string itemHeaders in headers)
            {
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(Bold(), new Text(itemHeaders))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "3000" }));
                headerCells.Add(tcName1);
            }
            //// Create a new row
            TableRow tr = new TableRow();
            tr.Append(headerCells.ToArray());
            tbl.AppendChild(tr);
            List<TableCell> dataCells = new List<TableCell>();
            foreach (List<string> rowItems in items)
            {
                dataCells = new List<TableCell>();
                foreach (string data in rowItems)
                {
                    tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(Bold(), new Text(data))));
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "3000" }));
                    dataCells.Add(tcName1);
                }
                TableRow tr1 = new TableRow();
                tr1.Append(dataCells.ToArray());
                tbl.AppendChild(tr1);
            }
            TableCellProperties cellOneProperties = new TableCellProperties();
            //if VAT
            if (item.IsVAT)
            {
                // total row
                tr = new TableRow();
                dataCells = new List<TableCell>();
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text("Tổng công (chưa bao gồm VAT)"))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1000" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString() }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }
                double totalCostWithoutVAT = 0;
                totalCostWithoutVAT = Totalcost / ((item.VATNumber + 100 ) / 100);
                var totalCostWithoutVATstr =  string.Format("{0:0,0}", totalCostWithoutVAT).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text(totalCostWithoutVATstr))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1900" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);
                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);

                // total row
                tr = new TableRow();
                dataCells = new List<TableCell>();
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text("Thuế VAT " + item.VATNumber.ToString() + "%"))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "200" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString() }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }
                double vatCost = 0;
                vatCost = (Totalcost * item.VATNumber ) / 100;
                var vatCoststr = string.Format("{0:0,0}", vatCost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text(vatCoststr))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1900" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);

                // total row
                tr = new TableRow();
                dataCells = new List<TableCell>();
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text("TỔNG CỘNG (đã bao gồm VAT)"))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "200" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString() }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }
              
                var TotalCost = string.Format("{0:0,0}", Totalcost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text(TotalCost))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1900" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);

            }
            else
            {
                // total row
                tr = new TableRow();
                dataCells = new List<TableCell>();
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text("TỔNG CỘNG "))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "200" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                for (int loopindex = 1; loopindex < widths.Length - 1; loopindex++)
                {
                    tcName1 = new TableCell(new Paragraph());
                    tcName1.Append(new TableCellProperties(
                    new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = widths[loopindex].ToString() }));
                    cellOneProperties = new TableCellProperties();
                    cellOneProperties.Append(new HorizontalMerge()
                    {
                        Val = MergedCellValues.Continue
                    });
                    tcName1.Append(cellOneProperties);
                    dataCells.Add(tcName1);
                }

                var TotalCost = string.Format("{0:0,0}", Totalcost).Replace(",", ".");
                tcName1 = new TableCell(new Paragraph(new ParagraphProperties(new Justification() { Val = JustificationValues.Right }), new Run(new Text(TotalCost))));
                tcName1.Append(new TableCellProperties(
                new TableCellWidth() { Type = TableWidthUnitValues.Dxa, Width = "1900" }));
                cellOneProperties = new TableCellProperties();
                cellOneProperties.Append(new HorizontalMerge()
                {
                    Val = MergedCellValues.Restart
                });
                tcName1.Append(cellOneProperties);
                dataCells.Add(tcName1);

                tr.Append(dataCells.ToArray());
                tbl.AppendChild(tr);
            }
            return tbl;
        }


        public Celula Append(string text, RunProperties rPr = null)
        {
            Run run = new();

            if (rPr != null)
                run.AppendChild(rPr);

            switch (TipoDeCelula)
            {
                case TipoDeCelula.HEADER:
                    if (!run.Elements<RunProperties>().Any())
                        run.Append(new RunProperties());
                    run.Elements<RunProperties>().First().Append(new Bold());
                    break;

                case TipoDeCelula.RESUME:
                    if (!run.Elements<RunProperties>().Any())
                        run.Append(new RunProperties());
                    run.Elements<RunProperties>().First().Append(new Italic() { Val = OnOffValue.FromBoolean(true) });
                    run.Elements<RunProperties>().First().Append(new Bold() { Val = OnOffValue.FromBoolean(true) });
                    break;
            }

            run.AppendChild(new Text { Space = SpaceProcessingModeValues.Preserve, Text = text });

            _runList.Add(run);

            return this;
        }

        public void StartComment(string commentId)
        {
            Run run = new();

            AnnotationReferenceMark annotationReferenceMark = new();
            run.Append(annotationReferenceMark);

            _runList.Add(run);

            CommentRangeStart commentRangeStart = new() { Id = commentId };
            _runList.Add(commentRangeStart);
        }

        public void EndComment(string commentId)
        {
            CommentRangeEnd commentRangeEnd = new() { Id = commentId };
            _runList.Add(commentRangeEnd);

            Run commentRun = new();

            CommentReference commentReference = new() { Id = commentId };
            commentRun.Append(commentReference);

            _runList.Add(commentRun);
        }

        public TableCell ToTableCell()
        {
            TableCell tableCell = new();

            TableCellProperties tableCellProperties = new();

            // Specify the width property of the table cell.  
            TableCellWidth tableCellWidth 
                = new() { Width = Width.ToString(), Type = TableWidthUnitValues.Dxa };
            tableCellProperties.Append(tableCellWidth);

            switch (TipoDeCelula)
            {
                case TipoDeCelula.HEADER:
                    tableCellProperties.Append(
                        new Shading() { Val = ShadingPatternValues.Percent10, Color = "000000", Fill = "auto" }
                        );
                    break;
                case TipoDeCelula.RESUME:
                    tableCellProperties.Append(
                        new Shading() { Val = ShadingPatternValues.Percent10, Color = "000000", Fill = "auto" }
                        );
                    break;
                default: // TipoDeCelula.NORMAL
                    break;
            }

            TableCellMargin tableCellMargin = new();
            LeftMargin leftMargin = new() { Width = "100", Type = TableWidthUnitValues.Dxa };
            RightMargin rightMargin = new() { Width = "100", Type = TableWidthUnitValues.Dxa };
            tableCellMargin.Append(leftMargin);
            tableCellMargin.Append(rightMargin);
            tableCellProperties.Append(tableCellMargin);

            TableCellVerticalAlignment tableCellVerticalAlignment = 
                new() { Val = TableVerticalAlignmentValues.Center };
            tableCellProperties.Append(tableCellVerticalAlignment);

            switch (Merge)
            {
                case TipoDeMerge.RESTART:
                    tableCellProperties.Append(
                        new HorizontalMerge() { Val = MergedCellValues.Restart }
                        );
                    break;
                case TipoDeMerge.CONTINUE:
                    tableCellProperties.Append(
                        new HorizontalMerge() { Val = MergedCellValues.Continue }
                        );
                    break;
                default: // TipoDeMerge.NENHUM
                    break;
            }

            tableCell.Append(tableCellProperties);

            Paragraph paragraph = new();
            ParagraphProperties paragraphProperties = new();

            switch (Alinhamento)
            {
                case TipoDeAlinhamento.ESQUERDO:
                    paragraphProperties.Append(new ParagraphStyleId() { Val = "LeftTextTable" });
                    break;
                case TipoDeAlinhamento.CENTRO:
                    paragraphProperties.Append(new ParagraphStyleId() { Val = "CenteredTextTable" });
                    break;
                case TipoDeAlinhamento.DIREITO:
                    paragraphProperties.Append(new ParagraphStyleId() { Val = "RightTextTable" });
                    break;
                default:  //TipoDeAlinhamento.NENHUM:
                    paragraphProperties.Append(new ParagraphStyleId() { Val = "NormalTextTable" });
                    break;
            }

            paragraph.AppendChild(paragraphProperties);

            foreach (OpenXmlElement run in _runList)
                paragraph.Append(run);

            // Write some text in the cell.
            tableCell.Append(paragraph);

            return tableCell;
        }

        public TableRow ToTableRow()
        {
            // Create a row and a cell.  
            TableRow tableRow = new();

            TablePropertyExceptions tablePropertyExceptions = new();

            TableCellMarginDefault tableCellMarginDefault = new();
            TopMargin topMargin = new() { Width = "0", Type = TableWidthUnitValues.Dxa };
            BottomMargin bottomMargin = new() { Width = "0", Type = TableWidthUnitValues.Dxa };

            tableCellMarginDefault.Append(topMargin);
            tableCellMarginDefault.Append(bottomMargin);

            tablePropertyExceptions.Append(tableCellMarginDefault);

            if (TipoDeCelula == TipoDeCelula.RESUME)
            {
                TableRowHeight tableRowHeight = new() { Val = (UInt32Value)600U };
                TableRowProperties tableRowProperties = new();

                tableRowProperties.Append(tableRowHeight);
                tableRow.Append(tableRowProperties);
            }

            tableRow.Append(tablePropertyExceptions);

            // Append the cell to the row.  
            for (int col = 0; col < _celulas.Length; col++)
                tableRow.Append(_celulas[col].ToTableCell());

            return tableRow;
        }

        public override void ToWord(WordprocessingDocument document)
        {
            TableProperties tableProperties = new();

            // TableOverlap
            TableOverlap tableOverlap = new() { Val = TableOverlapValues.Never };
            tableProperties.Append(tableOverlap);

            // Make the table width 100% of the page width (50 * 100).
            TableWidth tableWidth = new() { Width = _width.ToString(), Type = TableWidthUnitValues.Pct };
            tableProperties.Append(tableWidth);

            TableJustification tableJustification = new() { Val = TableRowAlignmentValues.Center };
            tableProperties.Append(tableJustification);

            // Create a TableProperties object and specify its border information.  
            tableProperties.Append(
                new TableBorders(
                    new TopBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.Double), Size = 1 
                    },
                    new BottomBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.Double), Size = 1 
                    },
                    new LeftBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.Double), Size = 1 
                    },
                    new RightBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.Double), Size = 1 
                    },
                    new InsideHorizontalBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 1 
                    },
                    new InsideVerticalBorder() { 
                        Val = new EnumValue<BorderValues>(BorderValues.BasicThinLines), Size = 1 
                    }
                    )
                );

            // TableCellMarginDefault
            TableCellMarginDefault tableCellMarginDefault = new();
            TableCellLeftMargin tableCellLeftMargin = new() { Width = 10, Type = TableWidthValues.Dxa };
            TableCellRightMargin tableCellRightMargin = new() { Width = 10, Type = TableWidthValues.Dxa };

            tableCellMarginDefault.Append(tableCellLeftMargin);
            tableCellMarginDefault.Append(tableCellRightMargin);

            tableProperties.Append(tableCellMarginDefault);

            // TableLook
            TableLook tableLook = new() { Val = "04A0", FirstRow = true, LastRow = false, FirstColumn = true, LastColumn = false, NoHorizontalBand = false, NoVerticalBand = true };
            tableProperties.Append(tableLook);

            TableCaption tableCaption = new() { Val = "Caption Table" };
            tableProperties.Append(tableCaption);

            // Create an empty table.  
            Table table = new();

            // Append the TableProperties object to the empty table.  
            table.AppendChild(tableProperties);

            // Create a row and a cell.  
            for (int row = 0; row < _linhas.Length; row++)
                table.Append(_linhas[row].ToTableRow());

            document.MainDocumentPart.Document.Body.AppendChild(table);

            document.MainDocumentPart.Document.Body.AppendChild(Titulo.ToParagraph());
        }


        private static string CreateEmptyString(int spaceLength)
        {
            StringBuilder buf = new StringBuilder();
            for (int i = 0; i < spaceLength; i++)
            {
                buf.Append(Resources.Space);
            }
            return buf.ToString();
        }

        private static int GetRealColumnCount(int? columnCount)
        {
            //Underline otherwise
            int minColumnCount = 1;
            //use the larger when the maximum number of characters is greater than the default length in the free answer method
            int realColumnCount = minColumnCount;
            if (columnCount.HasValue && columnCount > minColumnCount)
            {
                realColumnCount = (int)columnCount;
            }
            return realColumnCount;
        }

        private static int GetRealRowCount(int? rowCount)
        {
            //Underline otherwise
            int minRowCount = 1;
            //use the larger when the maximum number of characters is greater than the default length in the free answer method
            int realRowCount = minRowCount;
            if (rowCount.HasValue && rowCount > minRowCount)
            {
                realRowCount = (int)rowCount;
            }
            return realRowCount;
        }

        private static int CalcBoxCellWidth(int columnCount)
        {
            return BOX_CELL_WIDTH * columnCount;
        }

        private static int CalcHalfBoxCellWidth(int columnCount)
        {
            return HALF_BOX_CELL_WIDTH * columnCount;
        }

        private static string ToPx(double val)
        {
            return val + "pt";
        }

DocumentFormat.OpenXml.Drawing.TableCellProperties : IEnumerable

Constructors :

public TableCellProperties()
public TableCellProperties(IEnumerable<OpenXmlElement> childElements = )
public TableCellProperties(OpenXmlElement[] childElements = )
public TableCellProperties(String outerXml = )

Methods :

public Int32Value get_LeftMargin()
public Void set_LeftMargin(Int32Value value = )
public Int32Value get_RightMargin()
public Void set_RightMargin(Int32Value value = )
public Int32Value get_TopMargin()
public Void set_TopMargin(Int32Value value = )
public Int32Value get_BottomMargin()
public Void set_BottomMargin(Int32Value value = )
public EnumValue<TextVerticalValues> get_Vertical()
public Void set_Vertical(EnumValue<TextVerticalValues> value = )
public EnumValue<TextAnchoringTypeValues> get_Anchor()
public Void set_Anchor(EnumValue<TextAnchoringTypeValues> value = )
public BooleanValue get_AnchorCenter()
public Void set_AnchorCenter(BooleanValue value = )
public EnumValue<TextHorizontalOverflowValues> get_HorizontalOverflow()
public Void set_HorizontalOverflow(EnumValue<TextHorizontalOverflowValues> value = )
public LeftBorderLineProperties get_LeftBorderLineProperties()
public Void set_LeftBorderLineProperties(LeftBorderLineProperties value = )
public RightBorderLineProperties get_RightBorderLineProperties()
public Void set_RightBorderLineProperties(RightBorderLineProperties value = )
public TopBorderLineProperties get_TopBorderLineProperties()
public Void set_TopBorderLineProperties(TopBorderLineProperties value = )
public BottomBorderLineProperties get_BottomBorderLineProperties()
public Void set_BottomBorderLineProperties(BottomBorderLineProperties value = )
public TopLeftToBottomRightBorderLineProperties get_TopLeftToBottomRightBorderLineProperties()
public Void set_TopLeftToBottomRightBorderLineProperties(TopLeftToBottomRightBorderLineProperties value = )
public BottomLeftToTopRightBorderLineProperties get_BottomLeftToTopRightBorderLineProperties()
public Void set_BottomLeftToTopRightBorderLineProperties(BottomLeftToTopRightBorderLineProperties value = )
public Cell3DProperties get_Cell3DProperties()
public Void set_Cell3DProperties(Cell3DProperties value = )
public OpenXmlElement CloneNode(Boolean deep = )
public OpenXmlElement get_FirstChild()
public OpenXmlElement get_LastChild()
public Boolean get_HasChildren()
public String get_InnerText()
public Void set_InnerXml(String value = )
public Boolean AddChild(OpenXmlElement newChild = , Boolean throwOnError = True)
public T AppendChild(T newChild = )
public T InsertAfter(T newChild = , OpenXmlElement referenceChild = )
public T InsertBefore(T newChild = , OpenXmlElement referenceChild = )
public T InsertAt(T newChild = , Int32 index = )
public T PrependChild(T newChild = )
public T RemoveChild(T child = )
public Void RemoveAllChildren()
public T ReplaceChild(OpenXmlElement newChild = , T oldChild = )
public Void RemoveAllChildren()
public Void Remove()
public Boolean IsAfter(OpenXmlElement element = )
public Boolean IsBefore(OpenXmlElement element = )
public Void AddAnnotation(Object annotation = )
public T Annotation()
public Object Annotation(Type type = )
public IEnumerable<T> Annotations()
public IEnumerable<Object> Annotations(Type type = )
public Void RemoveAnnotations()
public Void RemoveAnnotations(Type type = )
public IEnumerator<OpenXmlElement> GetEnumerator()
public Object Clone()
public MarkupCompatibilityAttributes get_MCAttributes()
public Void set_MCAttributes(MarkupCompatibilityAttributes value = )
public String LookupNamespace(String prefix = )
public String LookupPrefix(String namespaceUri = )
public IFeatureCollection get_Features()
public OpenXmlElementContext get_OpenXmlElementContext()
public Boolean get_HasAttributes()
public IEnumerable<OpenXmlAttribute> get_ExtendedAttributes()
public OpenXmlElementList get_ChildElements()
public OpenXmlElement get_Parent()
public String get_NamespaceUri()
public String get_LocalName()
public String get_Prefix()
public IEnumerable<KeyValuePair<StringString>> get_NamespaceDeclarations()
public XmlQualifiedName get_XmlQualifiedName()
public XName get_XName()
public String get_InnerXml()
public String get_OuterXml()
public OpenXmlAttribute GetAttribute(String localName = , String namespaceUri = )
public IList<OpenXmlAttribute> GetAttributes()
public Void SetAttribute(OpenXmlAttribute openXmlAttribute = )
public Void RemoveAttribute(String localName = , String namespaceUri = )
public Void SetAttributes(IEnumerable<OpenXmlAttribute> openXmlAttributes = )
public Void ClearAllAttributes()
public Void AddNamespaceDeclaration(String prefix = , String uri = )
public Void RemoveNamespaceDeclaration(String prefix = )
public T GetFirstChild()
public OpenXmlElement PreviousSibling()
public T PreviousSibling()
public OpenXmlElement NextSibling()
public T NextSibling()
public IEnumerable<OpenXmlElement> Ancestors()
public IEnumerable<T> Ancestors()
public IEnumerable<T> Elements()
public IEnumerable<OpenXmlElement> Elements()
public IEnumerable<T> Descendants()
public IEnumerable<OpenXmlElement> Descendants()
public IEnumerable<OpenXmlElement> ElementsBefore()
public IEnumerable<OpenXmlElement> ElementsAfter()
public Void WriteTo(XmlWriter xmlWriter = )
public Void Append(IEnumerable<OpenXmlElement> newChildren = )
public Void Append(OpenXmlElement[] newChildren = )
public T InsertAfterSelf(T newElement = )
public T InsertBeforeSelf(T newElement = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()