private static void UpdatePowerPointBlock(ReportData client, OpenXmlPartContainer container, OpenXmlElement block, TableDefinition content, Dictionary <string, string> options) { if (null != content && block is OXP.GraphicFrame) { OXD.Table initTable = (OXD.Table)block.Descendants <OXD.Table>().FirstOrDefault(); if (null != initTable) { try { OXD.Table table = initTable.CloneNode(true) as OXD.Table; OXD.TableRow headerRowTemplate = table.Descendants <OXD.TableRow>().First().CloneNode(true) as OXD.TableRow; OXD.TableRow contentRowTemplate = table.Descendants <OXD.TableRow>().Skip(1).First().CloneNode(true) as OXD.TableRow; ModifyPowerPointRowTextContent(headerRowTemplate, string.Empty); ModifyPowerPointRowTextContent(contentRowTemplate, string.Empty); #region Column Number Management List <OXD.GridColumn> columns = table.TableGrid.Descendants <OXD.GridColumn>().ToList(); if (columns.Count < content.NbColumns) { int nbNewColumn = content.NbColumns - columns.Count; for (int i = 0, lim = nbNewColumn; i < lim; i++) { AddNewGridColumn(table.TableGrid, headerRowTemplate, contentRowTemplate); } } else if (columns.Count > content.NbColumns) { for (int i = content.NbColumns, lim = columns.Count; i < lim; i++) { RemoveLastGridColumn(table.TableGrid); } } #endregion Column Number Management int idx = 0; int nbrow = 0; List <OXD.TableCell> headerCells = headerRowTemplate.Descendants <OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList(); List <OXD.TableCell> contentCells = contentRowTemplate.Descendants <OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList(); headerRowTemplate.RemoveAllChildren <OXD.TableCell>(); OXD.TableRow row = headerRowTemplate; table.RemoveAllChildren <OXD.TableRow>(); foreach (var item in content.Data) { OXD.TableCell cell = null; if (content.HasColumnHeaders && 0 == nbrow) { cell = headerCells[idx].CloneNode(true) as OXD.TableCell; } else { cell = contentCells[idx].CloneNode(true) as OXD.TableCell; } ModifyPowerPointCellTextContent(cell, item); //row.Append(cell); => in office 2016, element <extLst> should absolutely be in the latest position in a row row.InsertBefore <OXD.TableCell>(cell, row.Descendants <OXD.ExtensionList>().FirstOrDefault()); idx = ++idx % content.NbColumns; if (0 == idx) { if (null != row) { table.Append(row); nbrow++; } row = contentRowTemplate.CloneNode(true) as OXD.TableRow; row.RemoveAllChildren <OXD.TableCell>(); } } initTable.Parent.ReplaceChild(table, initTable); } catch (Exception exception) { LogHelper.Instance.LogErrorFormat("An unhandled exception was thrown during table block content generation : '{0}'", exception.ToString()); if (null != initTable) { if (null != initTable.Descendants <OXD.TableRow>() && 1 > initTable.Descendants <OXD.TableRow>().Count()) { foreach (var row in initTable.Descendants <OXD.TableRow>().Skip(1)) { ModifyPowerPointRowTextContent(row, string.Empty); } } } } } } else { LogHelper.Instance.LogErrorFormat("Impossible to load data in table block with a block source of type \"{0}\"", null != block ? block.GetType().ToString() : "null"); } }
private List<customSection> getCriteria32Grid(DataTable dt) { //Set up TableProperties TableProperties tableProperties1 = new TableProperties(); TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" }; TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto }; TableIndentation tableIndentation1 = new TableIndentation() { Width = 0, Type = TableWidthUnitValues.Dxa }; 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(tableIndentation1); tableProperties1.Append(tableLook1); //Species header (need as separate grid b/c only one column) TableGrid gridHeader = new TableGrid(); gridHeader.Append(new GridColumn() { Width = "8725" }); //Body TableGrid gridBody = new TableGrid(); gridBody.Append(new GridColumn() { Width = "3325" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); //Title bar TableRow header = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; header.Append(getCell("Region / Method", clrBlueMid, "3325", clrBlueText, true)); header.Append(getCell("Strategy", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Research", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Advice", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Enforce", clrBlueMid, "1350", clrBlueText, true)); Table tableHeader = new Table(); Table tableBody = new Table(); List<customSection> tables = new List<customSection>(); //add 3.2 Header tableHeader = new Table(); TableGrid tmpGrid = (TableGrid)gridHeader.Clone(); TableRow headerRow = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; headerRow.Append(getCell("Factor 3.2: Management of fishing impacts on bycatch species", clrHeading, "8725", clrBlueText, true)); tmpGrid.Append(headerRow); tableHeader.Append(tableProperties1.CloneNode(true)); tableHeader.Append(tmpGrid); tables.Add(new customSection(tableHeader)); //Add column headers tableBody = new Table(); tableBody.Append(tableProperties1.CloneNode(true)); tableBody.Append(gridBody.CloneNode(true)); tableBody.Append(header.CloneNode(true)); //string commonName = ""; foreach (DataRow dr in dt.Rows) { TableRow row = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; string col = dr["Location"].ToString() + " " + dr["BodyOfWater"].ToString() + "\r\n" + dr["Method"].ToString(); row.Append(getCell(col, clrBlueLt, "1000", clrGreyText, true)); string col2 = dr["Factor2ScoreDescription"].ToString(); row.Append(getCell(col2, "FFFFFF", "1000")); string col3 = dr["Factor3ScoreDescription"].ToString(); row.Append(getCell(col3, "FFFFFF", "1000")); string col4 = dr["Factor4ScoreDescription"].ToString(); row.Append(getCell(col4, "FFFFFF", "1000")); string col5 = dr["Factor5ScoreDescription"].ToString(); row.Append(getCell(col5, "FFFFFF", "1000")); tableBody.Append(row); } tables.Add(new customSection(tableBody)); //store last table return tables; }
private List<customSection> getCriteria2Grids(DataTable dt) { //Set up TableProperties TableProperties tableProperties1 = new TableProperties(); TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" }; TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto }; TableIndentation tableIndentation1 = new TableIndentation() { Width = 0, Type = TableWidthUnitValues.Dxa }; 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(tableIndentation1); tableProperties1.Append(tableLook1); //Species header (need as separate grid b/c only one column) TableGrid gridHeader = new TableGrid(); gridHeader.Append(new GridColumn() { Width = "8725" }); //Body TableGrid gridBody = new TableGrid(); gridBody.Append(new GridColumn() { Width = "3325" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); //Title bar TableRow header = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; header.Append(getCell("Species", clrBlueMid, "3325", clrBlueText, true)); header.Append(getCell("Inherent \r\nVulnerability", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Stock Status", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Fishing Mortality", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Subscore", clrBlueMid, "1890", clrBlueText, true)); Table tableHeader = new Table(); Table tableBody = new Table(); List<customSection> tables = new List<customSection>(); string commonName = ""; foreach (DataRow dr in dt.Rows) { //Run once per species if (commonName != dr["LocationMethod"].ToString()) { //Store what you've already done (skip first pass), and reset variable if (commonName != "") tables.Add(new customSection(tableBody)); commonName = dr["LocationMethod"].ToString(); //add Species Header tableHeader = new Table(); TableGrid tmpGrid = (TableGrid)gridHeader.Clone(); TableRow headerRow = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; headerRow.Append(getCell(commonName, clrHeading, "8725", clrBlueText, true)); //add Scoring Header #region Scoring Header TableRow headerRow2 = new TableRow(@"<w:tr w:rsidR=""00B702EB"" w:rsidTr=""00284F47"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main""> <w:trPr> <w:cnfStyle w:val=""000000100000"" w:firstRow=""0"" w:lastRow=""0"" w:firstColumn=""0"" w:lastColumn=""0"" w:oddVBand=""0"" w:evenVBand=""0"" w:oddHBand=""1"" w:evenHBand=""0"" w:firstRowFirstColumn=""0"" w:firstRowLastColumn=""0"" w:lastRowFirstColumn=""0"" w:lastRowLastColumn=""0"" /> <w:trHeight w:val=""297"" /> </w:trPr> <w:tc> <w:tcPr> <w:cnfStyle w:val=""001000000000"" w:firstRow=""0"" w:lastRow=""0"" w:firstColumn=""1"" w:lastColumn=""0"" w:oddVBand=""0"" w:evenVBand=""0"" w:oddHBand=""0"" w:evenHBand=""0"" w:firstRowFirstColumn=""0"" w:firstRowLastColumn=""0"" w:lastRowFirstColumn=""0"" w:lastRowLastColumn=""0"" /> <w:tcW w:w=""9576"" w:type=""dxa"" /> <w:tcBorders> <w:top w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:left w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:bottom w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:right w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> </w:tcBorders> </w:tcPr> <w:tbl> <w:tblPr> <w:tblStyle w:val=""TableGrid"" /> <w:tblpPr w:leftFromText=""180"" w:rightFromText=""180"" w:vertAnchor=""text"" w:horzAnchor=""margin"" w:tblpX=""-90"" w:tblpY=""14"" /> <w:tblOverlap w:val=""never"" /> <w:tblW w:w=""0"" w:type=""auto"" /> <w:tblBorders> <w:top w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:left w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:bottom w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:right w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:insideH w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> <w:insideV w:val=""none"" w:color=""auto"" w:sz=""0"" w:space=""0"" /> </w:tblBorders> <w:tblLayout w:type=""fixed"" /> <w:tblLook w:val=""04A0"" w:firstRow=""1"" w:lastRow=""0"" w:firstColumn=""1"" w:lastColumn=""0"" w:noHBand=""0"" w:noVBand=""1"" /> </w:tblPr> <w:tblGrid> <w:gridCol w:w=""1170"" /> <w:gridCol w:w=""630"" /> <w:gridCol w:w=""720"" /> <w:gridCol w:w=""1440"" /> <w:gridCol w:w=""630"" /> <w:gridCol w:w=""720"" /> <w:gridCol w:w=""1080"" /> <w:gridCol w:w=""630"" /> </w:tblGrid> <w:tr w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidTr=""00284F47""> <w:tc> <w:tcPr> <w:tcW w:w=""1170"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""auto"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00284F47""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r w:rsidRPr=""00284F47""> <w:rPr> <w:b /> </w:rPr> <w:t>Subscore:</w:t> </w:r> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>:</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""630"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""DBE5F1"" w:themeFill=""accent1"" w:themeFillTint=""33"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00F56BE2""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>" + dr["HeaderSubScore"].ToString() + @"</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""720"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""auto"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00284F47""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""1440"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""auto"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00284F47"" w:rsidRDefault=""00284F47""> <w:pPr> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>Discard Rate:</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""630"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""DBE5F1"" w:themeFill=""accent1"" w:themeFillTint=""33"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00F56BE2""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>" + dr["HeaderDiscardRate"].ToString() + @"</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""720"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""auto"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00284F47""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""1080"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""auto"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00284F47""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>C2 Rate:</w:t> </w:r> </w:p> </w:tc> <w:tc> <w:tcPr> <w:tcW w:w=""630"" w:type=""dxa"" /> <w:shd w:val=""clear"" w:color=""auto"" w:fill=""DBE5F1"" w:themeFill=""accent1"" w:themeFillTint=""33"" /> </w:tcPr> <w:p w:rsidRPr=""00284F47"" w:rsidR=""00284F47"" w:rsidP=""00B702EB"" w:rsidRDefault=""00F56BE2""> <w:pPr> <w:jc w:val=""center"" /> <w:rPr> <w:b /> </w:rPr> </w:pPr> <w:r> <w:rPr> <w:b /> </w:rPr> <w:t>" + dr["HeaderScore"].ToString() + @"</w:t> </w:r> </w:p> </w:tc> </w:tr> </w:tbl> <w:p w:rsidR=""00284F47"" w:rsidP=""00284F47"" w:rsidRDefault=""00284F47"" /> </w:tc> </w:tr>"); #endregion //tmpGrid.Append(headerRow); //tmpGrid.Append(headerRow2); tableHeader.Append(tableProperties1.CloneNode(true)); tableHeader.Append(tmpGrid); tableHeader.Append(headerRow); tableHeader.Append(headerRow2); tables.Add(new customSection(tableHeader)); //Add "Region/Method" header tableBody = new Table(); tableBody.Append(tableProperties1.CloneNode(true)); tableBody.Append(gridBody.CloneNode(true)); tableBody.Append(header.CloneNode(true)); } TableRow row = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; string col = dr["CommonName"].ToString(); row.Append(getCell(col, clrBlueLt, "1000", clrGreyText, true)); string col1 = dr["Factor1Score"].ToString() + ":" + dr["Factor1ScoreDescription"].ToString(); row.Append(getCell(col1, "FFFFFF", "1000")); string col2 = dr["Factor2Score"].ToString() + ":" + dr["Factor2ScoreDescription"].ToString(); row.Append(getCell(col2, "FFFFFF", "1000")); string col3 = dr["Factor3Score"].ToString() + ":" + dr["Factor3ScoreDescription"].ToString(); row.Append(getCell(col3, "FFFFFF", "1000")); string col5 = dr["SubScore"].ToString(); row.Append(getCell(col5, "FFFFFF", "1000", true)); tableBody.Append(row); } tables.Add(new customSection(tableBody)); //store last table return tables; }
private List<customSection> getCriteria1Grids(DataTable dt) { //Set up TableProperties TableProperties tableProperties1 = new TableProperties(); TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" }; TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto }; TableIndentation tableIndentation1 = new TableIndentation() { Width = 0, Type = TableWidthUnitValues.Dxa }; 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(tableIndentation1); tableProperties1.Append(tableLook1); //Species header (need as separate grid b/c only one column) TableGrid gridHeader = new TableGrid(); gridHeader.Append(new GridColumn() { Width = "8725" }); //Body TableGrid gridBody = new TableGrid(); gridBody.Append(new GridColumn() { Width = "3325" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); //Title bar TableRow header = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; header.Append(getCell("Region / Method", clrBlueMid, "3325", clrBlueText, true)); header.Append(getCell("Inherent \r\nVulnerability", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Stock Status", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Fishing Mortality", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Subscore", clrBlueMid, "1890", clrBlueText, true)); Table tableHeader = new Table(); Table tableBody = new Table(); List<customSection> tables = new List<customSection>(); string commonName = ""; foreach (DataRow dr in dt.Rows) { //Run once per species if (commonName != dr["CommonName"].ToString()) { //Store what you've already done (skip first pass), and reset variable if (commonName != "") tables.Add(new customSection(tableBody)); commonName = dr["CommonName"].ToString(); //add Species Header tableHeader = new Table(); TableGrid tmpGrid = (TableGrid)gridHeader.Clone(); TableRow headerRow = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; headerRow.Append(getCell(commonName, clrHeading, "8725", clrBlueText, true)); tmpGrid.Append(headerRow); tableHeader.Append(tableProperties1.CloneNode(true)); tableHeader.Append(tmpGrid); tables.Add(new customSection(tableHeader)); //Add "Region/Method" header tableBody = new Table(); tableBody.Append(tableProperties1.CloneNode(true)); tableBody.Append(gridBody.CloneNode(true)); tableBody.Append(header.CloneNode(true)); } TableRow row = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; string col = dr["Location"].ToString() + " " + dr["BodyOfWater"].ToString() + "\r\n" + dr["Method"].ToString(); row.Append(getCell(col, clrBlueLt, "1000", clrGreyText, true)); string col1 = dr["Factor1Score"].ToString() + ":" + dr["Factor1ScoreDescription"].ToString(); row.Append(getCell(col1, "FFFFFF", "1000")); string col2 = dr["Factor2Score"].ToString() + ":" + dr["Factor2ScoreDescription"].ToString(); row.Append(getCell(col2, "FFFFFF", "1000")); string col3 = dr["Factor3Score"].ToString() + ":" + dr["Factor3ScoreDescription"].ToString(); row.Append(getCell(col3, "FFFFFF", "1000")); string col5 = dr["Color"].ToString() + " (" + dr["Score"].ToString() + ")"; row.Append(getCell(col5, getColor(dr["Color"].ToString()), "1000", true)); tableBody.Append(row); } tables.Add(new customSection(tableBody)); //store last table return tables; }
private List<customSection> getCriteria4Grid(DataTable dt) { //Set up TableProperties TableProperties tableProperties1 = new TableProperties(); TableStyle tableStyle1 = new TableStyle() { Val = "TableGrid" }; TableWidth tableWidth1 = new TableWidth() { Width = "0", Type = TableWidthUnitValues.Auto }; TableIndentation tableIndentation1 = new TableIndentation() { Width = 0, Type = TableWidthUnitValues.Dxa }; 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(tableIndentation1); tableProperties1.Append(tableLook1); //Species header (need as separate grid b/c only one column) TableGrid gridHeader = new TableGrid(); gridHeader.Append(new GridColumn() { Width = "8725" }); //Body TableGrid gridBody = new TableGrid(); gridBody.Append(new GridColumn() { Width = "3325" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); gridBody.Append(new GridColumn() { Width = "1350" }); //Title bar TableRow header = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; header.Append(getCell("Region / Method", clrBlueMid, "3325", clrBlueText, true)); header.Append(getCell("Gear Type and \r\nSubstrate", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("Mitigation of \r\nGear Impacts", clrBlueMid, "1350", clrBlueText, true)); header.Append(getCell("EBFM", clrBlueMid, "1350", clrBlueText,true)); header.Append(getCell("Overall Recomm.", clrBlueMid, "1890", clrBlueText, true)); Table tableHeader = new Table(); Table tableBody = new Table(); List<customSection> tables = new List<customSection>(); //Add "Region/Method" header tableBody = new Table(); tableBody.Append(tableProperties1.CloneNode(true)); tableBody.Append(gridBody.CloneNode(true)); tableBody.Append(header.CloneNode(true)); foreach (DataRow dr in dt.Rows) { TableRow row = new TableRow() { RsidTableRowAddition = "003C5001", RsidTableRowProperties = "003C5001" }; string col = dr["Location"].ToString() + " " + dr["BodyOfWater"].ToString() + "\r\n" + dr["Method"].ToString(); row.Append(getCell(col, clrBlueLt, "1000", clrGreyText, true)); string col1 = dr["Factor1Score"].ToString() + ":" + dr["Factor1ScoreDescription"].ToString(); row.Append(getCell(col1, "FFFFFF", "1000")); string col2 = dr["Factor2Score"].ToString() + ":" + dr["Factor2ScoreDescription"].ToString(); row.Append(getCell(col2, "FFFFFF", "1000")); string col3 = dr["Factor3Score"].ToString() + ":" + dr["Factor3ScoreDescription"].ToString(); row.Append(getCell(col3, "FFFFFF", "1000")); string col5 = dr["Color"].ToString() + " (" + dr["Score"].ToString() + ")"; row.Append(getCell(col5, getColor(dr["Color"].ToString()), "1000", true)); tableBody.Append(row); } tables.Add(new customSection(tableBody)); //store last table return tables; }
private static void UpdatePowerPointBlock(ReportData client, OpenXmlPartContainer container, OpenXmlElement block, TableDefinition content, Dictionary <string, string> options) { if (null != content && block is OXP.GraphicFrame) { var randomValue = new Random(); OXD.Table initTable = block.Descendants <OXD.Table>().FirstOrDefault(); if (null == initTable) { return; } try { OXD.Table table = initTable.CloneNode(true) as OXD.Table; OXD.TableRow headerRowTemplate = table?.Descendants <OXD.TableRow>().First().CloneNode(true) as OXD.TableRow; OXD.TableRow contentRowTemplate = table?.Descendants <OXD.TableRow>().Skip(1).First().CloneNode(true) as OXD.TableRow; ModifyPowerPointRowTextContent(headerRowTemplate, string.Empty); ModifyPowerPointRowTextContent(contentRowTemplate, string.Empty); #region Column Number Management List <OXD.GridColumn> columns = table?.TableGrid.Descendants <OXD.GridColumn>().ToList(); if (columns != null && columns.Count < content.NbColumns) { int nbNewColumn = content.NbColumns - columns.Count; for (int i = 0, lim = nbNewColumn; i < lim; i++) { AddNewGridColumn(table.TableGrid, headerRowTemplate, contentRowTemplate); } } else if (columns != null && columns.Count > content.NbColumns) { for (int i = content.NbColumns, lim = columns.Count; i < lim; i++) { RemoveLastGridColumn(table.TableGrid); } } #endregion Column Number Management int idx = 0; int nbrow = 0; List <OXD.TableCell> headerCells = headerRowTemplate?.Descendants <OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList(); List <OXD.TableCell> contentCells = contentRowTemplate?.Descendants <OXD.TableCell>().Select(_ => _.CloneNode(true) as OXD.TableCell).ToList(); headerRowTemplate?.RemoveAllChildren <OXD.TableCell>(); OXD.TableRow row = headerRowTemplate; table?.RemoveAllChildren <OXD.TableRow>(); for (int i = 0; i < content.Data.Count(); i++) { string item = content.Data.ToArray()[i]; OXD.TableCell cell; if (content.HasColumnHeaders && 0 == nbrow) { cell = headerCells?[idx].CloneNode(true) as OXD.TableCell; } else { cell = contentCells?[idx].CloneNode(true) as OXD.TableCell; } ModifyPowerPointCellTextContent(cell, item); if (content.HasCellsAttributes()) { CellAttributes attributes = content.CellsAttributes.FirstOrDefault(a => a.Index == i); if (attributes?.BackgroundColor != null) { Color myColor = attributes.BackgroundColor; OXD.RgbColorModelHex backColor = new OXD.RgbColorModelHex() { Val = $"{myColor.R:X2}{myColor.G:X2}{myColor.B:X2}" }; OXD.SolidFill solidFill = new OXD.SolidFill(); solidFill.Append(backColor); OXD.TableCellProperties props = cell?.Descendants <OXD.TableCellProperties>().FirstOrDefault(); OXD.TableCellProperties new_props = (props != null) ? props.CloneNode(true) as OXD.TableCellProperties : new OXD.TableCellProperties(); OXD.SolidFill oldFill = new_props?.Descendants <OXD.SolidFill>().FirstOrDefault(); oldFill?.Remove(); new_props?.InsertAfter(solidFill, new_props.LastChild); if (props != null) { cell.ReplaceChild(new_props, props); } else { cell?.AppendChild(new_props); } } } //row.Append(cell); => in office 2016, element <extLst> should absolutely be in the latest position in a row row?.InsertBefore(cell, row.Descendants <OXD.ExtensionList>().FirstOrDefault()); OXD.ExtensionList init_extlst = row?.Descendants <OXD.ExtensionList>().FirstOrDefault(); if (init_extlst != null) { OXD.Extension init_ext = init_extlst.Descendants <OXD.Extension>().FirstOrDefault(); OpenXmlUnknownElement init_rowId = init_ext?.GetFirstChild <OpenXmlUnknownElement>(); OpenXmlUnknownElement new_rowId = init_rowId?.CloneNode(true) as OpenXmlUnknownElement; if (new_rowId != null) { OpenXmlAttribute val = new_rowId.GetAttributes().FirstOrDefault(); val.Value = randomValue.Next().ToString(); new_rowId.SetAttribute(val); init_ext.ReplaceChild(new_rowId, init_rowId); } } idx = ++idx % content.NbColumns; if (0 != idx) { continue; } // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (null != row) { table.Append(row); nbrow++; } row = contentRowTemplate?.CloneNode(true) as OXD.TableRow; row?.RemoveAllChildren <OXD.TableCell>(); } initTable.Parent.ReplaceChild(table, initTable); } catch (Exception exception) { LogHelper.Instance.LogErrorFormat("An unhandled exception was thrown during table block content generation : '{0}'", exception.ToString()); if (initTable.Descendants <OXD.TableRow>() != null && !initTable.Descendants <OXD.TableRow>().Any()) { foreach (var row in initTable.Descendants <OXD.TableRow>().Skip(1)) { ModifyPowerPointRowTextContent(row, string.Empty); } } } } else { LogHelper.Instance.LogErrorFormat("Impossible to load data in table block with a block source of type \"{0}\"", block?.GetType().ToString() ?? "null"); } }