void AddAltChunk(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile filename)
        {
            string altChunkId = "AltChunkId" + id;
            id++;
            byte[] byteArray = filename.OpenBinary();

            AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(
            AlternativeFormatImportPartType.WordprocessingML, altChunkId);

            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);
                mem.Seek(0, SeekOrigin.Begin);
                chunk.FeedData(mem);
            }

            Word.AltChunk altChunk = new Word.AltChunk();
            altChunk.Id = altChunkId;

            // Replace content control with altChunk information.
            OpenXmlElement parent = sdt.Parent;
            parent.InsertAfter(altChunk, sdt);
            sdt.Remove();
        }
    private void insertComentariosGroup(wp.Paragraph par)
    {
        // descrição e nome dos custom groups
        List<ReportRow> rows = null;
        for (int i = 0; i < _projecto.GroupsDescription.Count(); i++)
        {
            rows = repCalcs.getComentarios(langCode, "G" + i.ToString());
            insertComentariosGroup(par, rows, _projecto.GroupsDescription[i]);
            // um parágrafo para separar os headers
            par.Append(new wp.Paragraph(new wp.Run(new wp.Text(""))));

        }
    }
        private void insertComentarios(wp.Paragraph par, List<ReportRow> rows)
        {
            wp.Table tableComents;
            wp.TableRow trComents;
            wp.TableRow trHeader;
            wp.TableRow trComentsSep;
            wp.Paragraph parComentsSeparator;

            // vai buscar o template para os comentários
            String templateDoc = _projecto.Template_Mnemonica;

            String filename = rootPath + "docTemplates\\" + templateDoc + "_COMENTS.docx";
            wp.TableRow tr;

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
            {

                tableComents = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                trHeader = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(0);
                trComents = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(1);
                trComentsSep = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(2);
                trComentsSep.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";

                tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();
                tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();
                tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();

                parComentsSeparator = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(0);
            }

            // produzir a secção de comentários

            if (rows == null)
            {
                par.Append((wp.Paragraph)parComentsSeparator.Clone());
            }
            else
            {
                foreach (ReportRow rr in rows)
                {
                    if (rr.dados[0] == "BREAK")
                        tr = trComentsSep.Clone() as wp.TableRow;
                    else if (rr.dados[0] != "")
                    {
                        tr = trHeader.Clone() as wp.TableRow;
                        tr.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[0];
                    }
                    else
                    {
                        tr = trComents.Clone() as wp.TableRow;
                        tr.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[1];
                    }
                    tableComents.Append(tr);
                }
                par.Append(tableComents);
            }

            // eliminar o texto do marcador
            par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";
        }
        private void insertAARank(wp.Paragraph par)
        {
            List<ReportRow> results;
            //MediasCompetencia medias;
            wp.Paragraph tempPar = new wp.Paragraph(); ;
            wp.TableRow tRow;
            setupAARankTable();
            wp.Table novaTabela = tempTable.Clone() as wp.Table;

            clearParagraphText(par);

            results = repCalcs.getRankingSELF();

            foreach (ReportRow rr in results)
            {
                tRow = tempRowImpar.Clone() as wp.TableRow;
                setText(rr.dados[0], tRow.Elements<wp.TableCell>().ElementAt(0));
                setText(rr.dados[2], tRow.Elements<wp.TableCell>().ElementAt(1));
                setText(rr.dados[1], tRow.Elements<wp.TableCell>().ElementAt(2));
                novaTabela.Append(tRow);
            }
            par.RemoveAllChildren<wp.Text>();
            par.Append(novaTabela);
        }
        private void insertAABehaveTables(Boolean auto, wp.Paragraph par)
        {
            List<ReportRow> results;
            MediasCompetencia medias;
            wp.Paragraph tempPar = new wp.Paragraph(); ;
            wp.TableRow tRow;
            setupAABehaveTableTemplate();
            int count;
            wp.Table novaTabela = tempTable.Clone() as wp.Table;

            clearParagraphText(par);

            // temos de lidar aqui com o bloco dos derailers
            foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
                foreach (Competencia comp in fam.Competencias.Values.Where(a => a.Type != "D"))
                {
                    results = repCalcs.getAvaliacaoComportamentosCriticosExtended(comp.CompetenciaID);
                    medias = repCalcs.getMediasCompetencia(comp.CompetenciaID);

                    tRow = tempRowHeader.Clone() as wp.TableRow;
                    setText(repCalcs.getCompetenciaText(comp.CompetenciaID), tRow.Elements<wp.TableCell>().ElementAt(0));

                    setText(medias.mS.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(1));
                    novaTabela.Append(tRow);

                    tRow = tempRowSeparador.Clone() as wp.TableRow; //separador
                    novaTabela.Append(tRow);

                    tRow = tempRowHeader2.Clone() as wp.TableRow; //segundo header
                    novaTabela.Append(tRow);

                    count = 1;
                    results.RemoveAt(0); // para retirara as legendas que aqui naão são utilizadas

                    foreach (ReportRow rr in results)
                    {
                        if (count % 2 == 0)
                        {
                            //par
                            tRow = tempRowPar.Clone() as wp.TableRow;
                        }
                        else
                        {
                            //impar
                            tRow = tempRowImpar.Clone() as wp.TableRow;
                        }

                        setText(rr.dados[0], tRow.Elements<wp.TableCell>().ElementAt(0));
                        if (rr.dados[1] == "0")
                            rr.dados[1] = "";
                        setText(rr.dados[1], tRow.Elements<wp.TableCell>().ElementAt(1));
                        if (rr.dados[6] == "-1.00")
                            rr.dados[6] = "-";
                        setText(rr.dados[6], tRow.Elements<wp.TableCell>().ElementAt(2));
                        novaTabela.Append(tRow);
                        count++;
                    }

                    // colocar um parágrafo

                    novaTabela.Append(tempParagraph.Clone() as wp.Paragraph);

                }

            par.RemoveAllChildren<wp.Text>();
            par.Append(novaTabela);
        }
 private void clearParagraphText(wp.Paragraph p)
 {
     foreach (wp.Run ru in p.Elements<wp.Run>())
     {
         foreach (wp.Text tx in ru.Elements<wp.Text>())
             tx.Text = "";
     }
 }
        private void setSelf(wp.Paragraph par)
        {
            wp.Paragraph insertPoint = par;
            String texto;

            texto = _avaliado.NomeProprio + " " + _avaliado.Apelido;

            wp.Paragraph p = insertPoint;
            wp.RunProperties rProps = p.Descendants<wp.RunProperties>().First().Clone() as wp.RunProperties;
            p.RemoveAllChildren<wp.Run>();
            wp.Run r = new wp.Run();
            r.RunProperties = rProps;
            r.Append(new wp.Text(texto));
            p.Append(r);
        }
        //private void insertTable_Ranking(wp.Paragraph par, List<ReportRow> rows, String tipo)
        //{
        //    if (!rankingTables)
        //    {
        //        setupRankingTables();
        //    }
        //    if (rows == null)
        //    {
        //        par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";
        //        return;
        //    }
        //    // Selecionar o template apropriado
        //    wp.TableRow theRow;
        //    wp.Table theTable = (wp.Table)tableRankS.Clone();
        //    wp.Paragraph theHeader = (wp.Paragraph)parHeadingParS.Clone();
        //    switch (tipo)
        //    {
        //        case "T":
        //            theTable = (wp.Table)tableRankT.Clone();
        //            theHeader = (wp.Paragraph)parHeadingParT.Clone();
        //            break;
        //        case "B":
        //            theTable = (wp.Table)tableRankB.Clone();
        //            theHeader = (wp.Paragraph)parHeadingParB.Clone();
        //            break;
        //        case "C":
        //            theTable = (wp.Table)tableRankC.Clone();
        //            theHeader = (wp.Paragraph)parHeadingParC.Clone();
        //            break;
        //        case "P":
        //            theTable = (wp.Table)tableRankP.Clone();
        //            theHeader = (wp.Paragraph)parHeadingParP.Clone();
        //            break;
        //        case "O":
        //            theTable = (wp.Table)tableRankO.Clone();
        //            theHeader = (wp.Paragraph)parHeadingParO.Clone();
        //            break;
        //    }
        //    // criar a tabela
        //    int count = 0;
        //    wp.Paragraph tempPar;
        //    foreach (ReportRow rr in rows)
        //    {
        //        if (count % 2 == 0)
        //            theRow = (wp.TableRow)trRankRowPar.Clone();
        //        else
        //            theRow = (wp.TableRow)trRankRowImpar.Clone();
        //        for (int i = 0; i < rr.dados.Length; i++)
        //        {
        //            tempPar = theRow.Elements<wp.TableCell>().ElementAt(i).Elements<wp.Paragraph>().First();
        //            tempPar.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[i];
        //        }
        //        theTable.Append(theRow);
        //        count++;
        //    }
        //    // INSERE O HEADER
        //    par.Append(theHeader);
        //    // INSERE A TABELA
        //    par.Append(theTable);
        //    // eliminar o texto do marcador
        //    clearParagraphText(par);
        //}
        private void insertTable_Gaps(wp.Paragraph par, List<ReportRow> rows, String tipo)
        {
            int index = 0;
            int counter = 0;

            if (!gapTables)
            {
                setupGapTables();
            }
            if (rows == null)
            {
                par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";
                return;
            }

            foreach (String s in _projecto.GroupsCodes)
            {
                if (s == tipo)
                {
                    index = counter;
                }
                counter++;
            }

            // Selecionar o template apropriado
            wp.TableRow theRow;
            wp.Table theTable = (wp.Table)tablesRank[index].Clone();
            wp.Paragraph theHeader = (wp.Paragraph)parsHeading[index].Clone();

            /*
            switch (tipo)
            {
                case "Co":
                    theTable = (wp.Table)tableRankB.Clone();
                    theHeader = (wp.Paragraph)parHeadingParB.Clone();
                    break;
                case "Me":
                    theTable = (wp.Table)tableRankC.Clone();
                    theHeader = (wp.Paragraph)parHeadingParC.Clone();
                    break;
                case "Mg":
                    theTable = (wp.Table)tableRankP.Clone();
                    theHeader = (wp.Paragraph)parHeadingParP.Clone();
                    break;
                case "Ve":
                    theTable = (wp.Table)tableRankO.Clone();
                    theHeader = (wp.Paragraph)parHeadingParO.Clone();
                    break;
                case "Pa":
                    theTable = (wp.Table)tableRankO.Clone();
                    theHeader = (wp.Paragraph)parHeadingParO.Clone();
                    break;
            }
            */

            // criar a tabela
            int count = 0;
            wp.Paragraph tempPar;

            foreach (ReportRow rr in rows)
            {
                if (count % 2 == 0)
                    theRow = (wp.TableRow)trRankRowPar.Clone();
                else
                    theRow = (wp.TableRow)trRankRowImpar.Clone();

                for (int i = 0; i < rr.dados.Length - 1; i++)
                {
                    tempPar = theRow.Elements<wp.TableCell>().ElementAt(i).Elements<wp.Paragraph>().First();
                    tempPar.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[i];
                }

                //tempPar = theRow.Elements<wp.TableCell>().ElementAt(rr.dados.Length - 1).Elements<wp.Paragraph>().First();
                // wp.Run rSymbol = tempPar.Elements<wp.Run>().First();
                // rSymbol.Elements<wp.SymbolChar>().First().Char = rr.dados[rr.dados.Length - 1];

                if (rr.dados[rr.dados.Length - 1] == "F0F1")
                    theRow.Elements<wp.TableCell>().ElementAt(rr.dados.Length - 1).Elements<wp.Paragraph>().First().Append((wp.Run)UpSign.Clone());
                else if (rr.dados[rr.dados.Length - 1] == "F0F2")
                    theRow.Elements<wp.TableCell>().ElementAt(rr.dados.Length - 1).Elements<wp.Paragraph>().First().Append((wp.Run)EqSign.Clone());
                else
                    theRow.Elements<wp.TableCell>().ElementAt(rr.dados.Length - 1).Elements<wp.Paragraph>().First().Append((wp.Run)LessSign.Clone());

                theTable.Append(theRow);
                count++;
            }

            // INSERE O HEADER
            par.Append(theHeader);

            // INSERE A TABELA
            par.Append(theTable);

            // eliminar o texto do marcador
            clearParagraphText(par);
        }
    private void insertSkillList(wp.Paragraph par)
    {
        String template = templatePath + "\\" + _projecto.Template_Mnemonica + "_SKILS_TABLE" + ".docx";

        wp.Paragraph templatePar;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(template, true))
        {
            wp.Run r;
            wp.Text t;
            wp.Paragraph p;

            templatePar = wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().First();
            foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
            {
                foreach (Competencia comp in fam.Competencias.Values)
                {
                    if (comp.Type == "C") continue;

                    p = (wp.Paragraph)templatePar.Clone();
                    r = p.Elements<wp.Run>().First();
                    t = r.Elements<wp.Text>().First();

                    t.Text = comp.PublicName;
                    par.Append(p);
                }
            }
        }

        // eliminar o texto do marcador
        clearParagraphText(par);
    }
Exemple #10
0
    private void insertOverviewSkill(wp.Paragraph par, MainDocumentPart mainPart)
    {
        // ir buscar o template
        // cria o documento final base com base no template
        String templateDoc = _projecto.Template_Mnemonica;

        String filename = templatePath + "\\" + templateDoc + "_OVERVIEW_SKILS_DETAILS.docx";

        wp.Paragraph parHeading = null;

        wp.Table tab1 = null;
        wp.TableRow rowTab1Par = null;
        wp.TableRow rowTab1Impar = null;
        wp.TableRow rowTab1Linha3 = null;

        wp.Run red = null;
        wp.Run yellow = null;
        wp.Run green = null;

        wp.Table legendaTab2 = null;
        wp.Paragraph quebraPagina = null;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
        {
            try
            {
                // o primeiro Parágrafo tem o nome do subcapítulo
                parHeading = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(0);

                // primeira tabela do template
                tab1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                rowTab1Impar = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(1).Clone();
                rowTab1Par = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(2).Clone();
                rowTab1Linha3 = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(3).Clone();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();

                // apanha os run + e - (mais e menos)
                green = (wp.Run)rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                red = (wp.Run)rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                yellow = (wp.Run)rowTab1Linha3.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();

                // eliminar o mais e o menos das linhas e o tracinho
                rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Linha3.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();

            }
            catch
            {

            }

            //parágrafo quebra de página
            quebraPagina = new wp.Paragraph(new wp.Run(new wp.Text("")));
            quebraPagina.ParagraphProperties = new wp.ParagraphProperties();
            quebraPagina.ParagraphProperties.PageBreakBefore = new wp.PageBreakBefore();
            quebraPagina.ParagraphProperties.PageBreakBefore.Val = DocumentFormat.OpenXml.OnOffValue.FromBoolean(true);

        }
        // fim da recolha dos elementos template.
        // passamos para a inserção destes elementos para cada competência

        // eliminar o texto do marcador
        par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";

        wp.Paragraph p = null;
        wp.Run r = null;
        wp.Text t = null;
        wp.Table tab1Temp = null;

        wp.TableRow tab1r = null;
        wp.TableCell tab1c = null;

        int count = 0;

        String pergunta;
        //String tempTexto;
        int contaPaginas = 1;

        String gap;

        foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
            foreach (Competencia comp in fam.Competencias.Values)
            {
                // são duas páginas de detalhes por cada competência
                // header da 1ªpágina

                if (comp.Type == "C") continue; // é uma competência comentário
                if (comp.Type == "D") continue; // é uma zona de derrailers

                // Nome da competência
                p = (wp.Paragraph)parHeading.Clone();
                r = p.Elements<wp.Run>().First();
                t = r.Elements<wp.Text>().First();
                t.Text = repCalcs.getCompetenciaText(comp.CompetenciaID);

                par.Append(p);

                // PREPARA A TABELA COM OS DETALHES
                tab1Temp = (wp.Table)tab1.Clone();
                tab1r = (wp.TableRow)tab1Temp.Elements<wp.TableRow>().ElementAt(0); // header da tabela
                tab1c = tab1r.Elements<wp.TableCell>().ElementAt(0); // c´clula com o local para o texto

                // os valores obtidos em cada comportamento
                // List<ReportRow> dataComportamentos = repCalcs.getAvaliacaoComportamentosCriticos(comp.CompetenciaID);
                List<ReportRow> dataComportamentosFracosFortes = repCalcs.getAvaliacaoComportamentosCriticos_FracosFortes_3Fatores(comp.CompetenciaID);
                count = 0;
                foreach (Pratica prat in comp.Praticas.Values)
                {
                    if (tab1c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text == "#TEXT_PRATICA#")
                    {
                        String plainText;
                        if (Utility.theServer != null)
                            plainText = Regex.Replace(Utility.theServer.HtmlDecode(prat.Description), "<[^>]+?>", "");
                        else
                            plainText = prat.Description;

                        plainText = DBHelper.ParseTextProprio(plainText, new Pessoa(), false);

                        tab1c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = plainText;

                    }
                    foreach (Pergunta perg in prat.Perguntas.Values)
                    {
                        pergunta = repCalcs.getPergunta(perg.PerguntaID);
                        if (count % 2 == 0)
                        {
                            // linha par
                            tab1r = (wp.TableRow)rowTab1Par.Clone();
                        }
                        else
                        {
                            // linha impar
                            tab1r = (wp.TableRow)rowTab1Impar.Clone();
                        }

                        //seleciona a célula do texto
                        tab1c = tab1r.Elements<wp.TableCell>().ElementAt(0);

                        // introduz o texto da pergunta
                        tab1c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentosFracosFortes[count].dados[0];

                        // as cores desta linha (prática)
                        tab1c = tab1r.Elements<wp.TableCell>().ElementAt(2);
                        switch (dataComportamentosFracosFortes[count].dados[1])
                        {
                            case "C":
                                tab1c.Elements<wp.Paragraph>().First().Append((wp.Run)red.Clone());
                                break;
                            case "B":
                                tab1c.Elements<wp.Paragraph>().First().Append((wp.Run)yellow.Clone());
                                break;
                            case "A":
                                tab1c.Elements<wp.Paragraph>().First().Append((wp.Run)green.Clone());
                                break;
                        }

                        // junta às tabelas as linhas
                        tab1Temp.Append(tab1r);
                        count++;
                    }
                }

                // INSERE A TABELA
                par.Append(tab1Temp);
                par.Append((wp.Paragraph)quebraPagina.Clone());

                contaPaginas++;
            }
    }
Exemple #11
0
    private void insertHAAADerailers(wp.Paragraph par)
    {
        List<ReportRow> results;
        MediasCompetencia medias;
        wp.Paragraph tempPar = new wp.Paragraph(); ;
        wp.TableRow tRow;
        int count;
        wp.Run rSymbol;

        wp.SymbolChar simbolo;

        setupHAAADerailersTableTemplate();
        wp.Table novaTabela = tempTable.Clone() as wp.Table;

        String vh, va;

        clearParagraphText(par);

        foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
            foreach (Competencia comp in fam.Competencias.Values.Where(a => a.Type == "D"))
            {

                results = repCalcs.getAvaliacaoDerailersExtendedOne2One(comp.CompetenciaID);
                medias = repCalcs.getMediasDerailer(comp.CompetenciaID);

                tRow = tempRowHeader.Clone() as wp.TableRow;
                setText(repCalcs.getCompetenciaText(comp.CompetenciaID), tRow.Elements<wp.TableCell>().ElementAt(0));

                //setText(medias.mS.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(2));
                //setText(medias.mT.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(3));

                //tempPar = tRow.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First();
                //rSymbol = tempPar.Elements<wp.Run>().First();

                if (medias.mS > medias.mT)
                {

                }
                else if (medias.mS < medias.mT)
                {

                }
                else
                {

                }

                novaTabela.Append(tRow);

                tRow = tempRowSeparador as wp.TableRow; //separador
                novaTabela.Append(tRow);

                tRow = tempRowHeader2 as wp.TableRow; //Segundo Header
                novaTabela.Append(tRow);

                count = 1;
                results.RemoveAt(0); // para retirara as legendas que aqui naão são utilizadas

                foreach (ReportRow rr in results)
                {
                    vh = "";
                    va = "";

                    if (count % 2 == 0)
                    {
                        //par
                        tRow = tempRowPar.Clone() as wp.TableRow;
                    }
                    else
                    {
                        //impar
                        tRow = tempRowImpar.Clone() as wp.TableRow;
                    }

                    setText(rr.dados[0], tRow.Elements<wp.TableCell>().ElementAt(0));

                    tempPar = tRow.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First();
                    //rSymbol = tempPar.Elements<wp.Run>().First();

                    if (rr.dados[6] == "-1,00")
                        vh = "-";
                    else
                        vh = rr.dados[6];

                    if (rr.dados[7] == "-1,00")
                        va = "-";
                    else va = rr.dados[7];

                    setText(vh, tRow.Elements<wp.TableCell>().ElementAt(1));
                    setText(va, tRow.Elements<wp.TableCell>().ElementAt(2));

                    // o dados de 7 e o dados de 6 podem viR A nullo

                    if (va != "-" && vh != "-" && rr.dados[7] != null && rr.dados[6] != null)
                    {
                        if (float.Parse(rr.dados[6].Replace(",", ".")) != float.Parse(rr.dados[7].Replace(",", ".")))
                        {
                            simbolo = symbDelevop.Clone() as wp.SymbolChar;
                            CountUps++;
                        }
                        else if (float.Parse(rr.dados[6].Replace(",", ".")) == float.Parse(rr.dados[7].Replace(",", ".")))
                        {
                            simbolo = symbNeutral.Clone() as wp.SymbolChar;
                            CountDown++;
                        }
                        else
                        {
                            simbolo = symbNeutral.Clone() as wp.SymbolChar;
                            CountHoriz++;
                        }
                    }
                    else
                        simbolo = symbTarget.Clone() as wp.SymbolChar;

                    tRow.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().AppendChild<wp.SymbolChar>(simbolo);

                    novaTabela.Append(tRow);
                    count++;
                }

                // colocar um parágrafo
                novaTabela.Append(tempParagraph.Clone() as wp.Paragraph);
            }

        par.Append(novaTabela);
    }
Exemple #12
0
    private void insertGroupList(wp.Paragraph par)
    {
        String template = templatePath + "\\" + _projecto.Template_Mnemonica + "_SKILS_TABLE" + ".docx";

        wp.Paragraph templatePar;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(template, true))
        {
            wp.Run r;
            wp.Text t;
            wp.Paragraph p;

            templatePar = wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().First();

            foreach (String s in _projecto.GroupsDescription)
            {
                p = (wp.Paragraph)templatePar.Clone();
                r = p.Elements<wp.Run>().First();
                t = r.Elements<wp.Text>().First();

                t.Text = s;
                par.Append(p);
            }
        }

        // eliminar o texto do marcador
        clearParagraphText(par);
    }
Exemple #13
0
    private void insertEscalaDesc(wp.Paragraph par, String scaleType)
    {
        String template = templatePath + "\\" + _projecto.Template_Mnemonica + "_SKILS_TABLE" + ".docx";

        wp.Paragraph templatePar;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(template, true))
        {
            wp.Run r;
            wp.Text t;
            wp.Paragraph p;

            String[] Valores;
            String[] Descricoes;

            templatePar = wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().First();
            int count = 0;
            String StrEscala = _projecto.getCurrentConfig(scaleType);
            if (StrEscala == "")
            {
                if (scaleType == "SCALE")
                {
                    Valores = _Modelo.Scale.Split('|');
                    Descricoes = _Modelo.ScaleDesc.Split('|');
                }
                else
                {
                    try
                    {
                        Valores = _Modelo.Familias.First().Value.Competencias.First().Value.CriticalidadeScale.Split('|');
                        Descricoes = _Modelo.Familias.First().Value.Competencias.First().Value.CriticalidadeText.Split('|');
                    }
                    catch
                    {
                        Valores = new string[0];
                        Descricoes = new string[0];
                    }
                }
            }
            else
            {
                String[] Escalas = StrEscala.Split('«');
                Valores = Escalas[0].Split('|');
                Descricoes = Escalas[1].Split('|');
            }
            // o primeiro valor pode ser o NR, ou não
            foreach (String escValue in Valores)
            {
                p = (wp.Paragraph)templatePar.Clone();
                r = p.Elements<wp.Run>().First();
                t = r.Elements<wp.Text>().First();

                t.Text = Valores[count] + " - " + Descricoes[count];
                count++;
                par.Append(p);
            }
        }

        clearParagraphText(par);
    }
Exemple #14
0
    private void insertDetailsSkill(wp.Paragraph par, MainDocumentPart mainPart)
    {
        // na primira fase fazer sem os gráficos

        // ir buscar o template
        // cria o documento final base com base no template
        String templateDoc = _projecto.Template_Mnemonica;

        String filename = templatePath + "\\" + templateDoc + "_SKILS_DETAILS.docx";

        wp.Table tabTitulo1 = null;
        wp.Table tabTitulo2 = null;

        wp.Table tab1 = null;
        wp.TableRow rowTab1Par = null;
        wp.TableRow rowTab1Impar = null;

        wp.Table tab2 = null;
        wp.TableRow rowTab2Par = null;
        wp.TableRow rowTab2Impar = null;

        wp.Run plusSign = null;
        wp.Run minusSign = null;
        wp.Run naSign = null;
        wp.Run eqSign = null;

        wp.Run red = null;
        wp.Run orange = null;
        wp.Run yellow = null;
        wp.Run green = null;
        wp.Paragraph NRs = null;

        wp.Table legendaTab1 = null;
        wp.Table legendaTab2 = null;
        wp.Paragraph quebraPagina = null;

        Boolean inserirChart = true;
        Boolean Pagina1 = true;
        Boolean Pagina2 = true;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
        {
            try
            {
                // primeira tabela do template
                tabTitulo1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                // primeira tabela com comportamentos
                tab1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(1).Clone();
                rowTab1Impar = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(1).Clone();
                rowTab1Par = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(2).Clone();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();

                // apanha os run + e - (mais e menos)
                minusSign = (wp.Run)rowTab1Impar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                naSign = (wp.Run)rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                plusSign = (wp.Run)rowTab1Par.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                try
                {
                    eqSign = (wp.Run)rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                }
                catch
                {
                    eqSign = null;
                }
                // eliminar o mais e o menos das linhas e o tracinho
                rowTab1Impar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Par.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                if (eqSign != null) rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();

                // depois tenho algures aqui a legenda da tabela
                legendaTab1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(2).Clone();

                // o primeiro parágrafpo tem idiciação de ter ou não o chart
                try
                {
                    wp.Text chartPar = (wp.Text)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().FirstOrDefault().Elements<wp.Run>().FirstOrDefault().Elements<wp.Text>().FirstOrDefault();
                    if (chartPar.Text != "")
                        inserirChart = true;
                    else
                        inserirChart = false;

                }
                catch
                {
                    inserirChart = false;
                }
            }
            catch
            {
                Pagina1 = false;
            }

            //parágrafo quebra de página
            quebraPagina = new wp.Paragraph(new wp.Run(new wp.Text("")));
            quebraPagina.ParagraphProperties = new wp.ParagraphProperties();
            quebraPagina.ParagraphProperties.PageBreakBefore = new wp.PageBreakBefore();
            quebraPagina.ParagraphProperties.PageBreakBefore.Val = DocumentFormat.OpenXml.OnOffValue.FromBoolean(true);

            try
            {
                // segundo header, também uma tabela
                //terá de se analisar o seu interior
                tabTitulo2 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(3).Clone();

                // tsegunda tabela
                tab2 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(4).Clone();
                rowTab2Impar = (wp.TableRow)tab2.Elements<wp.TableRow>().ElementAt(1).Clone();
                rowTab2Par = (wp.TableRow)tab2.Elements<wp.TableRow>().ElementAt(2).Clone();
                tab2.Elements<wp.TableRow>().ElementAt(1).Remove();
                tab2.Elements<wp.TableRow>().ElementAt(1).Remove();

                // agora os paragrafos de cor
                red = (wp.Run)rowTab2Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                orange = (wp.Run)rowTab2Impar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                yellow = (wp.Run)rowTab2Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                green = (wp.Run)rowTab2Par.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                NRs = (wp.Paragraph)rowTab2Impar.Elements<wp.TableCell>().ElementAt(5).Elements<wp.Paragraph>().First().Clone();

                // eliminar os quadrados do template
                rowTab2Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab2Impar.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab2Impar.Elements<wp.TableCell>().ElementAt(5).Elements<wp.Paragraph>().First().Remove();

                rowTab2Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab2Par.Elements<wp.TableCell>().ElementAt(3).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab2Par.Elements<wp.TableCell>().ElementAt(5).Elements<wp.Paragraph>().First().Remove();

                // legenda tabela 2
                // depois tenho algures aqui a legenda da tabela
                legendaTab2 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(5).Clone();
            }
            catch
            {
                Pagina2 = false;
            }
        }
        // fim da recolha dos elementos template.
        // passamos para a inserção destes elementos para cada competência

        // eliminar o texto do marcador
        par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";

        wp.Paragraph p = null;
        wp.Run r = null;
        wp.Text t = null;
        wp.Table tab = null;
        wp.Table tabTemp = null;
        wp.Table tab1Temp = null;
        wp.Table tab2Temp = null;

        wp.TableRow tab1r = null;
        wp.TableCell tab1c = null;
        wp.TableRow tab2r = null;
        wp.TableCell tab2c = null;

        wp.TableCell tcTemp = null;
        wp.TableRow trTemp = null;
        wp.TableCellProperties tcProps = null;

        int[] critic;
        int count = 0;

        String pergunta;
        //String tempTexto;
        int contaPaginas = 1;
        int ranking;
        String gap;

        foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
            foreach (Competencia comp in fam.Competencias.Values)
            {
                // são duas páginas de detalhes por cada competência
                // header da 1ªpágina
                if (Pagina1)
                {
                    if (comp.Type == "C") continue; // é uma competência comentário
                    if (comp.Type == "D") continue; // é uma zona de derrailers

                    // Nome da competência
                    tab = (wp.Table)tabTitulo1.Clone();
                    p = tab.Elements<wp.TableRow>().ElementAt(0).Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First();
                    r = p.Elements<wp.Run>().First();
                    t = r.Elements<wp.Text>().First();
                    t.Text = repCalcs.getCompetenciaText(comp.CompetenciaID);

                    // Matriz de criticalidade
                    try
                    {
                        tabTemp = (wp.Table)tab.Elements<wp.TableRow>().First().Elements<wp.TableCell>().ElementAt(1).Elements<wp.Table>().First();

                        // ajustar a cor de cada backgroud destas células
                        critic = repCalcs.getCompetenciaCriticalidadeMatrixPos(comp.CompetenciaID);
                        String porRef = critic[1].ToString() + critic[0].ToString();
                        String pos;
                        for (int x = 0; x < 3; x++)
                        {
                            trTemp = tabTemp.Elements<wp.TableRow>().ElementAt(x);
                            for (int y = 0; y < 3; y++)
                            {
                                pos = x.ToString() + y.ToString();
                                tcTemp = trTemp.Elements<wp.TableCell>().ElementAt(y);
                                tcProps = tcTemp.Elements<wp.TableCellProperties>().First();
                                if (pos != porRef)
                                {
                                    tcProps.Shading.Fill = "C0C0C0";
                                }
                                //if ((critic[0] - x) * 10 + critic[1] - y != 0)

                            }
                        }
                    }
                    catch
                    {

                    }
                    par.Append(tab);

                    // um parágrafo de espaçamento para que as tabelas não colem

                    String spreadsheetTemplate = templatePath + "\\" + templateDoc + "_CHART_BARS.xlsx";
                    // String spreadsheetFileName = rootPath + "generatedFiles\\" + templateDoc + _self.Email + ".xlsx";

                    // GRÁFICO
                    // insert um gráfico com o template definido neste parágrafo 5372100, Cy = 1914525
                    String relID;

                    if (inserirChart)
                    {
                        relID = insertChart(mainPart, par, spreadsheetTemplate, 5372100, 1914525);
                        ChartsToUpdate.Add(relID, repCalcs.DB_getDADOS_GRAFICO(comp.CompetenciaID));
                    }
                }

                // PREPARA AS DUAS TABELAS COM OS DETALHES
                if (Pagina1) tab1Temp = (wp.Table)tab1.Clone();
                if (Pagina2) tab2Temp = (wp.Table)tab2.Clone();

                // os valores obtidos em cada comportamento
                List<ReportRow> dataComportamentos = repCalcs.getAvaliacaoComportamentosCriticos(comp.CompetenciaID);
                List<ReportRow> dataComportamentosFracosFortes = repCalcs.getAvaliacaoComportamentosCriticos_FracosFortes(comp.CompetenciaID);
                count = 0;
                foreach (Pratica prat in comp.Praticas.Values)
                {
                    if (Pagina1)
                    {
                        if (tab1Temp.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text == "#TEXT_PRATICA#")
                        {
                            String plainText;
                            if (Utility.theServer != null)
                                plainText = Regex.Replace(Utility.theServer.HtmlDecode(prat.Description), "<[^>]+?>", "");
                            else
                                plainText = prat.Description;

                            plainText = DBHelper.ParseTextProprio(plainText, new Pessoa(), false);

                            tab1Temp.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = plainText;

                        }
                    }
                    if (Pagina2)
                    {
                        if (tab2Temp.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text == "#TEXT_PRATICA#")
                        {
                            String plainText;
                            if (Utility.theServer != null)
                                plainText = Regex.Replace(Utility.theServer.HtmlDecode(prat.Description), "<[^>]+?>", "");
                            else
                                plainText = prat.Description;

                            plainText = DBHelper.ParseTextProprio(plainText, new Pessoa(), false);

                            tab2Temp.Elements<wp.TableRow>().First().Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = plainText;

                        }
                    }
                    foreach (Pergunta perg in prat.Perguntas.Values)
                    {
                        pergunta = repCalcs.getPergunta(perg.PerguntaID);
                        if (count % 2 == 0)
                        {
                            // linha par
                            if (Pagina1) tab1r = (wp.TableRow)rowTab1Par.Clone();
                            if (Pagina2) tab2r = (wp.TableRow)rowTab2Par.Clone();

                        }
                        else
                        {
                            // linha impar
                            if (Pagina1) tab1r = (wp.TableRow)rowTab1Impar.Clone();
                            if (Pagina2) tab2r = (wp.TableRow)rowTab2Impar.Clone();
                        }

                        if (Pagina1) tab1c = tab1r.Elements<wp.TableCell>().ElementAt(0);
                        if (Pagina2) tab2c = tab2r.Elements<wp.TableCell>().ElementAt(0);

                        if (count + 1 < dataComportamentos.Count)
                        {
                            // introduz o texto da pergunta
                            if (Pagina1) tab1c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentos[count + 1].dados[0];
                            if (Pagina2) tab2c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentos[count + 1].dados[0];
                            // introduz os valores de cada prática
                            if (Pagina1)
                            {
                                for (int i = 1; i <= _projecto.GroupsCodes.Count(); i++)
                                {

                                    tab1c = tab1r.Elements<wp.TableCell>().ElementAt(i);
                                    fillPlusMinus(tab1c, dataComportamentos[count + 1].dados[i], plusSign, minusSign, naSign, eqSign);

                                }
                            }

                        }
                        // as cores desta linha (prática)
                        if (Pagina2)
                        {
                            tab2c = tab2r.Elements<wp.TableCell>().ElementAt(2);
                            switch (dataComportamentosFracosFortes[count].dados[1])
                            {
                                case "C":
                                    tab2c.Elements<wp.Paragraph>().First().Append((wp.Run)red.Clone());
                                    break;
                                case "B":
                                    tab2c.Elements<wp.Paragraph>().First().Append((wp.Run)orange.Clone());
                                    break;
                                case "A":
                                    tab2c.Elements<wp.Paragraph>().First().Append((wp.Run)yellow.Clone());
                                    break;
                            }
                        }

                        if (Pagina2)
                        {
                            tab2c = tab2r.Elements<wp.TableCell>().ElementAt(3);
                            if (dataComportamentosFracosFortes[count].dados[2] == "D")
                                tab2c.Elements<wp.Paragraph>().First().Append((wp.Run)green.Clone());

                            // a percentagem de não respostas
                            tab2c = tab2r.Elements<wp.TableCell>().ElementAt(5);
                            NRs.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentosFracosFortes[count].dados[3] + "%";

                            tab2c.Append((wp.Paragraph)NRs.Clone());
                        }
                        // junta às tabelas as linhas
                        if (Pagina1) tab1Temp.Append(tab1r);
                        if (Pagina2) tab2Temp.Append(tab2r);

                        count++;
                    }
                }

                // INSERE A TABELA 1
                if (Pagina1) par.Append(tab1Temp);
                // LEGENDA 1

                //tempTexto = "";

                //legendaTab1.Elements<wp.TableRow>().ElementAt(1).Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = tempTexto;
                if (Pagina1) par.Append((wp.Table)legendaTab1.Clone());

                // QUEBRA DE PÁGINA 1
                if (Pagina1) par.Append((wp.Paragraph)quebraPagina.Clone());

                // HEADER da 2ªpágina
                if (Pagina2)
                {
                    tab = (wp.Table)tabTitulo2.Clone();
                    p = tab.Elements<wp.TableRow>().ElementAt(1).Elements<wp.TableCell>().ElementAt(0).Elements<wp.Paragraph>().First();
                    r = p.Elements<wp.Run>().First();
                    t = r.Elements<wp.Text>().First();
                    t.Text = repCalcs.getCompetenciaText(comp.CompetenciaID);
                    try
                    {
                        // quadro dos RANKINGS ainda no header2
                        p = tab.Elements<wp.TableRow>().ElementAt(0).Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First();
                        r = p.Elements<wp.Run>().First();
                        t = r.Elements<wp.Text>().First();
                        ranking = repCalcs.getCompetenciaRanking(comp.CompetenciaID, "T");
                        t.Text = ranking == 0 ? "-" : ranking.ToString();

                        for (int i = 1; i < _projecto.GroupsCodes.Count(); i++)
                        {
                            p = tab.Elements<wp.TableRow>().ElementAt(0).Elements<wp.TableCell>().ElementAt(i + 2).Elements<wp.Paragraph>().First();
                            r = p.Elements<wp.Run>().First();
                            t = r.Elements<wp.Text>().First();
                            ranking = repCalcs.getCompetenciaRanking(comp.CompetenciaID, repCalcs.ReportGroupCodes[i]);
                            t.Text = ranking == 0 ? "-" : ranking.ToString();
                        }

                        // quadro dos GAPS ainda no header2
                        p = tab.Elements<wp.TableRow>().ElementAt(1).Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First();
                        r = p.Elements<wp.Run>().First();
                        gap = repCalcs.getCompetenciaGAP(comp.CompetenciaID, "T");
                        r.Elements<wp.SymbolChar>().First().Char = gap;

                        for (int i = 1; i < _projecto.GroupsCodes.Count(); i++)
                        {
                            p = tab.Elements<wp.TableRow>().ElementAt(1).Elements<wp.TableCell>().ElementAt(i + 2).Elements<wp.Paragraph>().First();
                            r = p.Elements<wp.Run>().First();
                            gap = repCalcs.getCompetenciaGAP(comp.CompetenciaID, repCalcs.ReportGroupCodes[i]);
                            r.Elements<wp.SymbolChar>().First().Char = gap;
                        }

                    }
                    catch
                    {

                    }

                    // INSERTE A TABELA DETALHE PAGINA 2
                    par.Append(tab);

                    // um parágrafo de espaçamento para que as tabelas não colem
                    par.Append(new wp.Paragraph());

                    // INSERE A TABELA 2
                    par.Append(tab2Temp);

                    // LEGENDA 2
                    //tempTexto = "";
                    par.Append((wp.Table)legendaTab2.Clone());

                    // QUEBRA DE PÁGINA 2
                    if (contaPaginas < repCalcs.getQuantidadeDeCompetencias())
                        par.Append((wp.Paragraph)quebraPagina.Clone());
                }
                contaPaginas++;
            }
    }
Exemple #15
0
    private void insertComentariosGroup(wp.Paragraph par, List<ReportRow> rows, String GroupID)
    {
        wp.Table tableComents;
        wp.TableRow trComents;
        wp.TableRow trHeader;
        wp.TableRow trComentsSep;
        wp.Paragraph parComentsSeparator;
        wp.Paragraph HeaderPar;

        // vai buscar o template para os comentários
        String templateDoc = _projecto.Template_Mnemonica;

        String filename = templatePath + "\\" + templateDoc + "_COMMENTS_BY_GROUP.docx";
        wp.TableRow tr;

        using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
        {

            HeaderPar = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(0).Clone();

            tableComents = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

            trHeader = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(0);
            trComents = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(1);
            trComentsSep = (wp.TableRow)tableComents.Elements<wp.TableRow>().ElementAt(2);
            trComentsSep.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().ElementAt(0).Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";

            tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();
            tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();
            tableComents.Elements<wp.TableRow>().ElementAt(0).Remove();

            parComentsSeparator = (wp.Paragraph)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Paragraph>().ElementAt(0);
        }

        // produzir a secção de comentários

        if (rows == null)
        {
            par.Append((wp.Paragraph)parComentsSeparator.Clone());
        }
        else if (rows.Count == 0)
        {
            par.Append((wp.Paragraph)parComentsSeparator.Clone());
        }
        else
        {
            // o início da secção
            wp.Paragraph h = (wp.Paragraph)HeaderPar.Clone();
            h.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = GroupID;
            par.Append(h);

            foreach (ReportRow rr in rows)
            {
                if (rr.dados[0] == "BREAK")
                    tr = trComentsSep.Clone() as wp.TableRow;
                else if (rr.dados[0] != "")
                {
                    tr = trHeader.Clone() as wp.TableRow;
                    tr.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = repCalcs.getCompetenciaText(int.Parse(rr.dados[0]));
                }
                else
                {
                    tr = trComents.Clone() as wp.TableRow;
                    tr.Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[1];
                }
                tableComents.Append(tr);
            }
            par.Append(tableComents);
        }

        // eliminar o texto do marcador
        par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";
    }
Exemple #16
0
 private static void ModifyWordRowTextContent(OXW.TableRow headerRowTemplate, string txt)
 {
     if (null != headerRowTemplate)
     {
         var cells = headerRowTemplate.Descendants<OXW.TableCell>();
         if (null != cells)
         {
             foreach (var cell in cells)
             {
                 ModifyWordCellTextContent(cell, txt);
             }
         }
     }
 }
        private void insertHABehaveTables(Boolean auto, wp.Paragraph par)
        {
            List<ReportRow> results;
            MediasCompetencia medias;
            wp.Paragraph tempPar = new wp.Paragraph(); ;
            wp.TableRow tRow;
            int count;
            wp.Run rSymbol;

            setupHABehaveTableTemplate();
            wp.Table novaTabela = tempTable.Clone() as wp.Table;

            String vh, va;

            clearParagraphText(par);

            foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
                foreach (Competencia comp in fam.Competencias.Values.Where(a => a.Type != "D"))
                {
                    if ("Orientação para Resultados" == repCalcs.getCompetenciaText(comp.CompetenciaID))
                        vh = "";

                    results = repCalcs.getAvaliacaoComportamentosCriticosExtendedOne2One(comp.CompetenciaID);
                    medias = repCalcs.getMediasCompetencia(comp.CompetenciaID);

                    tRow = tempRowHeader.Clone() as wp.TableRow;
                    setText(repCalcs.getCompetenciaText(comp.CompetenciaID), tRow.Elements<wp.TableCell>().ElementAt(0));

                    setText(medias.mS.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(2));
                    setText(medias.mT.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(3));

                    tempPar = tRow.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First();
                    rSymbol = tempPar.Elements<wp.Run>().First();

                    if (medias.mS > medias.mT)
                    {
                        rSymbol.Elements<wp.SymbolChar>().First().Char = symbUp.Char;
                    }
                    else if (medias.mS < medias.mT)
                    {
                        rSymbol.Elements<wp.SymbolChar>().First().Char = symbDw.Char;
                    }
                    else
                    {
                        rSymbol.Elements<wp.SymbolChar>().First().Char = symbH.Char;
                    }

                    novaTabela.Append(tRow);

                    tRow = tempRowHeader2.Clone() as wp.TableRow; //segundo header
                    novaTabela.Append(tRow);

                    count = 1;
                    results.RemoveAt(0); // para retirara as legendas que aqui naão são utilizadas

                    foreach (ReportRow rr in results)
                    {
                        vh = "";
                        va = "";

                        if (count % 2 == 0)
                        {
                            //par
                            tRow = tempRowPar.Clone() as wp.TableRow;
                        }
                        else
                        {
                            //impar
                            tRow = tempRowImpar.Clone() as wp.TableRow;
                        }

                        setText(rr.dados[0], tRow.Elements<wp.TableCell>().ElementAt(0));

                        tempPar = tRow.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First();
                        rSymbol = tempPar.Elements<wp.Run>().First();

                        if (rr.dados[6] == "-1,00")
                            vh = "-";
                        else
                            vh = rr.dados[6];

                        if (rr.dados[7] == "-1,00")
                            va = "-";
                        else va = rr.dados[7];

                        setText(vh, tRow.Elements<wp.TableCell>().ElementAt(2));
                        setText(va, tRow.Elements<wp.TableCell>().ElementAt(3));

                        // o dados de 7 e o dados de 6 podem viR A nullo

                        if (va != "-" && vh != "-" && rr.dados[7] != null && rr.dados[6] != null)
                        {
                            if (float.Parse(rr.dados[6].Replace(",", ".")) > float.Parse(rr.dados[7].Replace(",", ".")))
                            {
                                rSymbol.Elements<wp.SymbolChar>().First().Char = symbUp.Char;
                                CountUps++;
                            }
                            else if (float.Parse(rr.dados[6].Replace(",", ".")) < float.Parse(rr.dados[7].Replace(",", ".")))
                            {
                                rSymbol.Elements<wp.SymbolChar>().First().Char = symbDw.Char;
                                CountDown++;
                            }
                            else
                            {
                                rSymbol.Elements<wp.SymbolChar>().First().Char = symbH.Char;
                                CountHoriz++;
                            }
                        }
                        else
                            rSymbol.Elements<wp.SymbolChar>().First().Char = "F09F";

                        novaTabela.Append(tRow);
                        count++;
                    }

                    // colocar um parágrafo
                    novaTabela.Append(tempParagraph.Clone() as wp.Paragraph);
                }

            par.Append(novaTabela);
        }
Exemple #18
0
    private void insertTable_Ranking(wp.Paragraph par, List<ReportRow> rows, String tipo)
    {
        if (!rankingTables)
        {
            setupRankingTables();
        }
        if (rows == null)
        {
            par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";
            return;
        }
        // Selecionar o template apropriado por defeito fica o G0
        wp.TableRow theRow;
        wp.Table theTable = (wp.Table)tableRankS.Clone();
        wp.Paragraph theHeader = (wp.Paragraph)parHeadingParS.Clone();

        switch (tipo)
        {
            case "T":
                theTable = (wp.Table)tableRankT.Clone();
                theHeader = (wp.Paragraph)parHeadingParT.Clone();
                break;
            case "G1":
                theTable = (wp.Table)tableRankB.Clone();
                theHeader = (wp.Paragraph)parHeadingParB.Clone();
                break;
            case "G2":
                theTable = (wp.Table)tableRankC.Clone();
                theHeader = (wp.Paragraph)parHeadingParC.Clone();
                break;
            case "G3":
                theTable = (wp.Table)tableRankP.Clone();
                theHeader = (wp.Paragraph)parHeadingParP.Clone();
                break;
            case "G4":
                theTable = (wp.Table)tableRankO.Clone();
                theHeader = (wp.Paragraph)parHeadingParO.Clone();
                break;
        }

        // criar a tabela
        int count = 0;
        wp.Paragraph tempPar;

        foreach (ReportRow rr in rows)
        {
            if (count % 2 == 0)
                theRow = (wp.TableRow)trRankRowPar.Clone();
            else
                theRow = (wp.TableRow)trRankRowImpar.Clone();
            for (int i = 0; i < rr.dados.Length; i++)
            {
                tempPar = theRow.Elements<wp.TableCell>().ElementAt(i).Elements<wp.Paragraph>().First();
                tempPar.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = rr.dados[i];
            }
            theTable.Append(theRow);
            count++;
        }

        // INSERE O HEADER
        par.Append(theHeader);

        // INSERE A TABELA
        par.Append(theTable);

        // eliminar o texto do marcador
        clearParagraphText(par);
    }
        private void setIntervenientes(Boolean auto, wp.Paragraph insertPoint)
        {
            String texto;

            if (auto)
            {
                texto = _self.NomeProprio + " " + _self.Apelido;
            }
            else
            {
                texto = _self.NomeProprio + " " + _self.Apelido + " avalia ";
                texto += _avaliado.NomeProprio + " " + _avaliado.Apelido;
            }

            wp.Paragraph p = insertPoint;
            wp.RunProperties rProps = p.Descendants<wp.RunProperties>().First().Clone() as wp.RunProperties;
            p.RemoveAllChildren<wp.Run>();
            wp.Run r = new wp.Run();
            r.RunProperties = rProps;
            r.Append(new wp.Text(texto));
            p.Append(r);
        }
        void ImportChartFromSpreadsheet(MainDocumentPart mainPart, Word.SdtElement sdt,
   SPFile spreadsheetFileName)
        {
            // Create a paragraph that has an inline drawing object.
            Word.Paragraph p = new Word.Paragraph();
            Word.Run r = new Word.Run();
            p.Append(r);
            Word.Drawing drawing = new Word.Drawing();
            r.Append(drawing);
            // These dimensions work perfectly for the template document.
            WP.Inline inline = new WP.Inline(new WP.Extent() { Cx = 5486400, Cy = 3200400 });
            byte[] byteArray = spreadsheetFileName.OpenBinary();

            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);

                // Open the Excel spreadsheet.
                using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(mem, true))
                {
                    // Get all of the appropriate parts.
                    WorkbookPart workbookPart = mySpreadsheet.WorkbookPart;
                    WorksheetPart worksheetPart = XLGetWorksheetPartByName(mySpreadsheet,
                       "Sheet2");
                    DrawingsPart drawingPart = worksheetPart.DrawingsPart;
                    ChartPart chartPart = (ChartPart)drawingPart.GetPartById("rId1");

                    // Clone the chart part and add it to the Word document.
                    ChartPart importedChartPart = mainPart.AddPart<ChartPart>(chartPart);
                    string relId = mainPart.GetIdOfPart(importedChartPart);

                    // The frame element contains information for the chart.
                    GraphicFrame frame =
                       drawingPart.WorksheetDrawing.Descendants<GraphicFrame>().First();
                    string chartName = frame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Name;
                    // Clone this node so that you can add it to the Word document.
                    Draw.Graphic clonedGraphic = (Draw.Graphic)frame.Graphic.CloneNode(true);
                    ChartReference c = clonedGraphic.GraphicData.GetFirstChild<ChartReference>();
                    c.Id = relId;

                    // Give the chart a unique ID and name.
                    WP.DocProperties docPr = new WP.DocProperties();
                    docPr.Name = chartName;
                    docPr.Id = GetMaxDocPrId(mainPart) + 1;

                    // Add the chart data to the inline drawing object.
                    inline.Append(docPr, clonedGraphic);
                    drawing.Append(inline);
                }
            }
            OpenXmlElement parent = sdt.Parent;
            parent.InsertAfter(p, sdt);
            sdt.Remove();
        }
 private void setText(String text, wp.TableCell theCell)
 {
     wp.Text _text = theCell.Descendants<wp.Text>().First();
     _text.Text = text;
 }
        void ImportProjectsAndMilestones(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile spreadsheetFileName)
        {
            ArrayList cellText = new ArrayList();

            // Create a Word table.
            Word.Table tbl = new Word.Table();
            Word.TableProperties tblPr = new Word.TableProperties();
            Word.TableStyle tblStyle = new Word.TableStyle();
            tblStyle.Val = "LightShading-Accent1";
            tblPr.AppendChild(tblStyle);

            Word.TableWidth tblW = new Word.TableWidth();
            tblW.Width = "5000";
            tblW.Type = Word.TableWidthUnitValues.Pct;
            tblPr.Append(tblW);
            tbl.AppendChild(tblPr);
            byte[] byteArray = spreadsheetFileName.OpenBinary();

            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);

                using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(mem, true))
                {
                    WorkbookPart workbookPart = mySpreadsheet.WorkbookPart;
                    WorksheetPart worksheetPart = XLGetWorksheetPartByName(mySpreadsheet, "Sheet1");

                    Excel.SheetData sheetData =
                       worksheetPart.Worksheet.GetFirstChild<Excel.SheetData>();

                    foreach (Excel.Row r in sheetData)
                    {
                        foreach (Excel.Cell c in r)
                        {
                            cellText.Add(XLGetCellValue(c, workbookPart));
                        }
                        Word.TableRow tr = CreateRow(cellText);
                        tbl.Append(tr);
                        cellText = new ArrayList();
                    }
                }
            }
            // Swap out the content control for the SmartArt.
            OpenXmlElement parent = sdt.Parent;
            parent.InsertAfter(tbl, sdt);
            sdt.Remove();
        }
 private void fillPlusMinus(wp.TableCell cell, String Value, wp.Run plus, wp.Run minus, wp.Run na, wp.Run eq)
 {
     if (Value == "*")
         cell.Elements<wp.Paragraph>().First().Append((wp.Run)na.Clone());
     else if (Value == "+")
         cell.Elements<wp.Paragraph>().First().Append((wp.Run)plus.Clone());
     else if (Value == "-")
         cell.Elements<wp.Paragraph>().First().Append((wp.Run)minus.Clone());
     else
         cell.Elements<wp.Paragraph>().First().Append((wp.Run)eq.Clone());
 }
        void ImportSmartArtFromPowerPoint(MainDocumentPart mainPart, Word.SdtElement sdt, SPFile filename)
        {
            string docLayoutPartId = "";
            string docDataPartId = "";
            string docColorsPartId = "";
            string docStylePartId = "";

            byte[] byteArray = filename.OpenBinary();

            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, (int)byteArray.Length);

                using (PresentationDocument myPres = PresentationDocument.Open(mem, true))
                {
                    PresentationPart presPart = myPres.PresentationPart;
                    // Get the slide that contains the SmartArt graphic.
                    SlidePart slide = (SlidePart)presPart.GetPartById("rId3");
                    // Get all the appropriate parts associated with the SmartArt.
                    DiagramLayoutDefinitionPart layoutPart =
                       slide.DiagramLayoutDefinitionParts.First();
                    DiagramDataPart dataPart = slide.DiagramDataParts.First();
                    DiagramColorsPart colorsPart = slide.DiagramColorsParts.First();
                    DiagramStylePart stylePart = slide.DiagramStyleParts.First();

                    // Get some of the appropriate properties off the SmartArt graphic.
                    PPT.GraphicFrame graphicFrame =
                       slide.Slide.Descendants<PPT.GraphicFrame>().First();
                    PPT.NonVisualDrawingProperties drawingPr = graphicFrame
                       .Descendants<PPT.NonVisualDrawingProperties>().First();
                    Draw.Extents extents =
                       graphicFrame.Descendants<Draw.Extents>().First();

                    // Import SmartArt into the Word document.
                    // Add the SmartArt parts to the Word document.
                    DiagramLayoutDefinitionPart docLayoutPart =
                       mainPart.AddPart<DiagramLayoutDefinitionPart>(layoutPart);
                    DiagramDataPart docDataPart =
                       mainPart.AddPart<DiagramDataPart>(dataPart);
                    DiagramColorsPart docColorsPart =
                       mainPart.AddPart<DiagramColorsPart>(colorsPart);
                    DiagramStylePart docStylePart =
                       mainPart.AddPart<DiagramStylePart>(stylePart);
                    // Get all the relationship ids of the added parts.
                    docLayoutPartId = mainPart.GetIdOfPart(docLayoutPart);
                    docDataPartId = mainPart.GetIdOfPart(docDataPart);
                    docColorsPartId = mainPart.GetIdOfPart(docColorsPart);
                    docStylePartId = mainPart.GetIdOfPart(docStylePart);

                    // Use the document reflector to figure out how to add a SmartArt
                    // graphic to Word.
                    // Change attribute values based on specifics related to the SmartArt.
                    Word.Paragraph p = new Word.Paragraph(
                       new Word.Run(
                       new Word.Drawing(
                       new WP.Inline(
                       new WP.Extent() { Cx = extents.Cx, Cy = extents.Cy },
                       new WP.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L },
                       new WP.DocProperties() { Id = drawingPr.Id, Name = drawingPr.Name },
                       new WP.NonVisualGraphicFrameDrawingProperties(),
                       new Draw.Graphic(
                       new Draw.GraphicData(
                       new Dgm.RelationshipIds()
                       {
                           DataPart = docDataPartId,
                           LayoutPart = docLayoutPartId,
                           StylePart = docStylePartId,
                           ColorPart = docColorsPartId
                       }) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/diagram" }))
                       {
                           DistanceFromTop = (UInt32Value)0U,
                           DistanceFromBottom = (UInt32Value)0U,
                           DistanceFromLeft = (UInt32Value)0U,
                           DistanceFromRight = (UInt32Value)0U
                       })));

                    // Swap out the content control for the SmartArt.
                    OpenXmlElement parent = sdt.Parent;
                    parent.InsertAfter(p, sdt);
                    sdt.Remove();
                }
            }
        }
        private void insertAADerailers(wp.Paragraph par)
        {
            List<ReportRow> results;
            wp.Paragraph tempPar = new wp.Paragraph(); ;
            wp.TableRow tRow;
            setupAADerailersTableTemplate();
            int count;
            wp.Table novaTabela = tempTable.Clone() as wp.Table;
            wp.SymbolChar simbolo;
            float valor;
            clearParagraphText(par);

            // temos de lidar aqui com o bloco dos derailers
            foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
                foreach (Competencia comp in fam.Competencias.Values.Where(a => a.Type == "D"))
                {
                    results = repCalcs.getAvaliacaoDerailersExtended(comp.CompetenciaID);
                    //medias = repCalcs.getMediasCompetencia(comp.CompetenciaID);

                    tRow = tempRowHeader.Clone() as wp.TableRow;
                    setText(repCalcs.getCompetenciaText(comp.CompetenciaID), tRow.Elements<wp.TableCell>().ElementAt(0));

                    //setText(medias.mS.ToString("0.00"), tRow.Elements<wp.TableCell>().ElementAt(1));
                    novaTabela.Append(tRow);

                    tRow = tempRowSeparador.Clone() as wp.TableRow; //separador
                    novaTabela.Append(tRow);

                    tRow = tempRowHeader2.Clone() as wp.TableRow; //segundo header
                    novaTabela.Append(tRow);

                    count = 1;
                    results.RemoveAt(0); // para retirara as legendas que aqui não são utilizadas

                    foreach (ReportRow rr in results)
                    {
                        if (count % 2 == 0)
                        {
                            //par
                            tRow = tempRowPar.Clone() as wp.TableRow;
                        }
                        else
                        {
                            //impar
                            tRow = tempRowImpar.Clone() as wp.TableRow;
                        }

                        setText(rr.dados[0], tRow.Elements<wp.TableCell>().ElementAt(0));
                        valor = float.Parse(rr.dados[6]);

                        if (valor <= 2)
                        {
                            // on target
                            simbolo = symbTarget.Clone() as wp.SymbolChar;
                        }
                        else if (valor >= 4)
                        {
                            // a desenvolver
                            simbolo = symbDelevop.Clone() as wp.SymbolChar;
                        }
                        else
                        {
                            // neutro
                            simbolo = symbNeutral.Clone() as wp.SymbolChar;
                        }

                        tRow.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().AppendChild<wp.SymbolChar>(simbolo);

                        if (rr.dados[6] == "-1.00")
                            rr.dados[6] = "-";
                        setText(rr.dados[6], tRow.Elements<wp.TableCell>().ElementAt(2));
                        novaTabela.Append(tRow);
                        count++;
                    }

                    // colocar um parágrafo

                    novaTabela.Append(tempParagraph.Clone() as wp.Paragraph);

                }

            par.RemoveAllChildren<wp.Text>();
            par.Append(novaTabela);
        }
Exemple #26
0
 private static void ModifyWordCellTextContent(OXW.TableCell cell, string txt)
 {
     if (null != cell)
     {
         OXW.Paragraph paragraph = cell.Descendants<OXW.Paragraph>().FirstOrDefault();
         if (null != paragraph)
         {
             paragraph = paragraph.CloneNode(true) as OXW.Paragraph;
             ModifyWordParagraphTextContent(paragraph, txt);
             cell.RemoveAllChildren<OXW.Paragraph>();
             cell.Append(paragraph);
         }
     }
 }
        private String insertChart(MainDocumentPart mainPart, wp.Paragraph par, String templateName, int dimx, int dimy)
        {
            String relId;
            // vai buscar o gráfico e coloca-o no local com a dimensão definida HARCODED
            wp.Paragraph chartP = new wp.Paragraph();
            wp.Run chartR = new wp.Run();
            chartP.Append(chartR);
            wp.Drawing drawing = new wp.Drawing();
            chartR.Append(drawing);

            clearParagraphText(par);

            //Open Excel spreadsheet
            using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(templateName, true))
            {
                //Get all the appropriate parts

                // assume que há apenas um gráfico por ficheiro template
                // isto deveria evoluir para um ficheiro apenas

                WorkbookPart workbookPart = mySpreadsheet.WorkbookPart;
                WorksheetPart worksheetPart = (WorksheetPart)workbookPart.GetPartById("rId1");
                DrawingsPart drawingPart = worksheetPart.DrawingsPart;
                ChartPart chartPart = (ChartPart)drawingPart.GetPartById("rId1");

                //Clone the chart part and add it to my Word document
                ChartPart importedChartPart = mainPart.AddPart<ChartPart>(chartPart);
                relId = mainPart.GetIdOfPart(importedChartPart);

                //The frame element contains information for the chart
                ssd.GraphicFrame frame = drawingPart.WorksheetDrawing.Descendants<ssd.GraphicFrame>().First();
                string chartName = frame.NonVisualGraphicFrameProperties.NonVisualDrawingProperties.Name;

                //Clone this node so we can add it to my Word document
                Graphic clonedGraphic = (Graphic)frame.Graphic.CloneNode(true);

                // clonedGraphic.GraphicData

                ChartReference c = clonedGraphic.GraphicData.GetFirstChild<ChartReference>();
                c.Id = relId;

                //Give the chart a unique id and name
                wpd.DocProperties docPr = new wpd.DocProperties();
                docPr.Name = chartName;
                docPr.Id = GetMaxDocPrId(mainPart) + 1;

                //add the chart data to the inline drawing object
                // wpd.Inline inline = new wpd.Inline(new wpd.Extent() { Cx = 5372100, Cy = 1914525 });
                wpd.Inline inline;
                if (dimx == 0 && dimy == 0)
                    inline = new wpd.Inline();
                else
                    inline = new wpd.Inline(new wpd.Extent() { Cx = dimx, Cy = dimy });
                inline.Append(docPr, clonedGraphic);
                drawing.Append(inline);
            }

            // JUNTA O GRÁFICO
            par.Append(chartP);

            // retorna o ID do gráfico que necessita update
            return relId;
        }
Exemple #28
0
 private static void ModifyWordParagraphTextContent(OXW.Paragraph paragraph, string txt)
 {
     if (null != paragraph)
     {
         OXW.Run run = paragraph.Descendants<OXW.Run>().FirstOrDefault();
         if (null != run)
         {
             run = run.CloneNode(true) as OXW.Run;
             paragraph.RemoveAllChildren<OXW.Run>();
         }
         else
         {
             run = new OXW.Run();
         }
             OXW.Text text = run.Descendants<OXW.Text>().FirstOrDefault();
             text = (null == text ? new OXW.Text() : text.CloneNode(true) as OXW.Text);
             run.RemoveAllChildren<OXW.Text>();
             text.Text = txt;
         if (!string.IsNullOrEmpty(txt) && (char.IsWhiteSpace(txt[0]) || char.IsWhiteSpace(txt[txt.Length-1]))) {
             text.Space = SpaceProcessingModeValues.Preserve;
         }
             run.Append(text);
             paragraph.Append(run);
         }
 }
        private void insertDetailsSkill(wp.Paragraph par, MainDocumentPart mainPart)
        {
            // na primira fase fazer sem os gráficos

            // ir buscar o template
            // cria o documento final base com base no template
            String templateDoc = _projecto.Template_Mnemonica;

            String filename = rootPath + "docTemplates\\" + templateDoc + "_SKILS_DETAILS.docx";

            wp.Table tabTitulo1;

            wp.Table tab1;
            wp.TableRow rowTab1Par;
            wp.TableRow rowTab1Impar;

            wp.Run plusSign;
            wp.Run minusSign;
            wp.Run naSign;
            wp.Run eqSign;

            wp.Table legendaTab1;
            wp.Paragraph quebraPagina;

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(filename, true))
            {
                // primeira tabela do template
                tabTitulo1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(0).Clone();

                // primeira tabela com comportamentos
                tab1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(1).Clone();
                rowTab1Impar = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(1).Clone();
                rowTab1Par = (wp.TableRow)tab1.Elements<wp.TableRow>().ElementAt(2).Clone();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();
                tab1.Elements<wp.TableRow>().ElementAt(1).Remove();

                // apanha os run + e - (mais e menos)
                minusSign = (wp.Run)rowTab1Impar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                naSign = (wp.Run)rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                plusSign = (wp.Run)rowTab1Par.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();
                eqSign = (wp.Run)rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Clone();

                // eliminar o mais e o menos das linhas e o tracinho
                rowTab1Impar.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Impar.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Par.Elements<wp.TableCell>().ElementAt(1).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();
                rowTab1Par.Elements<wp.TableCell>().ElementAt(2).Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Remove();

                // depois tenho algures aqui a legenda da tabela
                legendaTab1 = (wp.Table)wordDoc.MainDocumentPart.Document.Body.Elements<wp.Table>().ElementAt(2).Clone();

                //parágrafo quebra de página
                quebraPagina = new wp.Paragraph(new wp.Run(new wp.Text("")));
                quebraPagina.ParagraphProperties = new wp.ParagraphProperties();
                quebraPagina.ParagraphProperties.PageBreakBefore = new wp.PageBreakBefore();
                quebraPagina.ParagraphProperties.PageBreakBefore.Val = DocumentFormat.OpenXml.OnOffValue.FromBoolean(true);

            }
            // fim da recolha dos elementos template.
            // passamos para a inserção destes elementos para cada competência

            // eliminar o texto do marcador
            par.Elements<wp.Run>().First().Elements<wp.Text>().First().Text = "";

            wp.Paragraph p;
            wp.Run r;
            wp.Text t;
            wp.Table tab;

            wp.Table tab1Temp;

            wp.TableRow tab1r;
            wp.TableCell tab1c;

            int count = 0;

            String pergunta;
            String tempTexto;
            int contaPaginas = 1;

            foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
                foreach (Competencia comp in fam.Competencias.Values)
                {
                    // são duas páginas de detalhes por cada competência
                    // header da 1ªpágina

                    if (comp.Type == "C") continue; // é uma competência comentário
                    if (comp.Type == "D") continue; // é uma zona de derrailers

                    // Nome da competência
                    tab = (wp.Table)tabTitulo1.Clone();
                    p = tab.Elements<wp.TableRow>().ElementAt(0).Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First();
                    r = p.Elements<wp.Run>().First();
                    t = r.Elements<wp.Text>().First();
                    t.Text = repCalcs.getCompetenciaText(comp.CompetenciaID);

                    par.Append(tab);// o nome da competência

                    // PREPARA AS DUAS TABELAS COM OS DETALHES
                    tab1Temp = (wp.Table)tab1.Clone();
                    // tab2Temp = (wp.Table)tab2.Clone();

                    // os valores obtidos em cada comportamento
                    List<ReportRow> dataComportamentos = repCalcs.getAvaliacaoComportamentosCriticos(comp.CompetenciaID);
                    List<ReportRow> dataComportamentosFracosFortes = repCalcs.getAvaliacaoComportamentosCriticos_FracosFortes(comp.CompetenciaID);
                    count = 0;
                    foreach (Pratica prat in comp.Praticas.Values)
                        foreach (Pergunta perg in prat.Perguntas.Values)
                        {
                            pergunta = repCalcs.getPergunta(perg.PerguntaID);
                            if (count % 2 == 0)
                            {
                                // linha par
                                tab1r = (wp.TableRow)rowTab1Par.Clone();
                                // tab2r = (wp.TableRow)rowTab2Par.Clone();
                            }
                            else
                            {
                                // linha impar
                                tab1r = (wp.TableRow)rowTab1Impar.Clone();
                                // tab2r = (wp.TableRow)rowTab2Impar.Clone();
                            }

                            tab1c = tab1r.Elements<wp.TableCell>().ElementAt(0);
                            // tab2c = tab2r.Elements<wp.TableCell>().ElementAt(0);

                            if (count + 1 < dataComportamentos.Count)
                            {
                                // introduz o texto da pergunta
                                tab1c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentos[count + 1].dados[0];
                                // tab2c.Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = dataComportamentos[count + 1].dados[0];
                                // introduz os valores de cada prática

                                // os mais e os menos desta linha (prática), por S;B;P;C;O
                                for (int i = 1; i < dataComportamentos[count + 1].dados.Length; i++ )
                                {
                                    tab1c = tab1r.Elements<wp.TableCell>().ElementAt(i);
                                    fillPlusMinus(tab1c, dataComportamentos[count + 1].dados[i], plusSign, minusSign, naSign, eqSign);
                                }
                            }

                            // junta às tabelas as linhas
                            tab1Temp.Append(tab1r);
                            // tab2Temp.Append(tab2r);

                            count++;
                        }

                    // INSERE A TABELA 1
                    par.Append(tab1Temp);
                    // LEGENDA 1

                    tempTexto = "";

                    //legendaTab1.Elements<wp.TableRow>().ElementAt(1).Elements<wp.TableCell>().First().Elements<wp.Paragraph>().First().Elements<wp.Run>().First().Elements<wp.Text>().First().Text = tempTexto;
                    par.Append((wp.Table)legendaTab1.Clone());

                    // QUEBRA DE PÁGINA 1
                    par.Append((wp.Paragraph)quebraPagina.Clone());

                    // um parágrafo de espaçamento para que as tabelas não colem
                    par.Append(new wp.Paragraph());

                    contaPaginas++;
                }
        }
Exemple #30
0
    private void insertChartsSkills(wp.Paragraph par, MainDocumentPart mainPart)
    {
        // na primira fase fazer sem os gráficos

        // ir buscar o template
        // cria o documento final base com base no template
        String templateDoc = _projecto.Template_Mnemonica;

        String spreadsheetTemplate = templatePath + "\\" + templateDoc + "_SKILL_CHART.xlsx";

        foreach (FamiliaCompetencias fam in _Modelo.Familias.Values)
            foreach (Competencia comp in fam.Competencias.Values)
            {
                // GRÁFICO
                // insert um gráfico com o template definido neste parágrafo 5372100, Cy = 1914525
                String relID = insertChart(mainPart, par, spreadsheetTemplate, 5372100, 1914525);

                SkillsChartsToUpdate.Add(relID, repCalcs.DB_getDADOS_GRAFICO_SKILL(comp.CompetenciaID));
            }
    }