private void GerarRelatorioBoletoMensalidadeWord(List <BoletoMensalidade> listaBoletoMensalidadeAuxiliar) { int iteraPosicao = 0; foreach (BoletoMensalidade boleto in listaBoletoMensalidadeAuxiliar) { alunoAuxiliarExibicao = PreencheAlunoExibicao(iteraPosicao); GerarRelatorioBoletoMensalidade(alunoAuxiliarExibicao); iteraPosicao++; } }
private void GerarRelatorioBoletoMensalidade(ClasseAuxiliarExibicaoMatricula alunoAuxiliarExibicao) { Object oMissing = System.Reflection.Missing.Value; Object oTrue = true; Object oFalse = false; Word.Application oWord = new Word.Application(); Word.Document oWordDoc = new Word.Document(); oWord.Visible = true; Object oTemplatePath = "C:\\ModeloTeste3.dotx"; oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing); foreach (Word.Field myMergeField in oWordDoc.Fields) { iTotalFields++; Word.Range rngFieldCode = myMergeField.Code; String fieldText = rngFieldCode.Text; if (fieldText.StartsWith(" MERGEFIELD")) { Int32 endMerge = fieldText.IndexOf("\\"); Int32 fieldNameLength = fieldText.Length - endMerge; String fieldName = fieldText.Substring(11, endMerge - 11); fieldName = fieldName.Trim(); if (fieldName == "_nomeUm") { myMergeField.Select(); oWord.Selection.Font.Name = "Times New Roman"; oWord.Selection.Font.Size = 10; oWord.Selection.TypeText(alunoAuxiliarExibicao.nomeMatExibicao); } if (fieldName == "_matriculaUm") { myMergeField.Select(); oWord.Selection.Font.Name = "Times New Roman"; oWord.Selection.Font.Size = 10; oWord.Selection.TypeText(alunoAuxiliarExibicao.numeroMatExibicao); } if (fieldName == "_parcela") { myMergeField.Select(); oWord.Selection.Font.Bold = 1; oWord.Selection.Font.Name = "Bodoni MT Black"; oWord.Selection.Font.Size = 12; oWord.Selection.TypeText(alunoAuxiliarExibicao.parcela); } if (fieldName == "_anoUm") { myMergeField.Select(); oWord.Selection.Font.Name = "Times New Roman"; oWord.Selection.Font.Size = 10; oWord.Selection.TypeText(alunoAuxiliarExibicao.ano); } if (fieldName == "_vencimento") { myMergeField.Select(); oWord.Selection.Font.Name = "Times New Roman"; oWord.Selection.Font.Size = 10; oWord.Selection.TypeText(alunoAuxiliarExibicao.vencimento); } if (fieldName == "_mensalidade") { myMergeField.Select(); oWord.Selection.Font.Name = "Times New Roman"; oWord.Selection.Font.Size = 10; oWord.Selection.TypeText(alunoAuxiliarExibicao.mensalidade); } } } object pageBreak = WdBreakType.wdPageBreak; oWord.Selection.InsertBreak(ref pageBreak); }