Example #1
0
    private void ReemplazarDatos(Word.Range rng_datos, string[] aDatos)
    {
        //Ejemplo de Buscar y reemplazar el nombre dentro del rango.
        Word.Find fnd = rng_datos.Find;
        //Clear existing formatting;
        fnd.ClearFormatting();
        fnd.Replacement.ClearFormatting();

        fnd.Text             = "{nombre}";
        fnd.Replacement.Text = aDatos[0];// "Nombre Profesional";
        ExecuteReplace(fnd);

        fnd.Text             = "{nif}";
        fnd.Replacement.Text = aDatos[1];// "123456789Z";
        ExecuteReplace(fnd);

        fnd.Text             = "{perfil}";
        fnd.Replacement.Text = aDatos[2];// "GERENTE";
        ExecuteReplace(fnd);

        fnd.Text             = "{fnacim}";
        fnd.Replacement.Text = aDatos[3];// "15/02/1973";
        ExecuteReplace(fnd);

        fnd.Text             = "{foto}";
        fnd.Replacement.Text = "";// "15/02/1973";
        ExecuteFind(fnd);
        rng_datos.Select();
        rng_datos.SetRange(rng_datos.Start, rng_datos.End);

        Word.Selection currentSelection = wordApplication.Selection;
        currentSelection.MoveRight();
        currentSelection.InlineShapes.AddPicture("D:\\Proyectos\\PRUEBAS\\WordTest01\\images\\01.jpg");

        ExecuteReplace(fnd);

        //TableRow theRow = theTable.Elements<TableRow>().Last();
        //Word.Row oLastRow = newDocument.Bookmarks["Tabla01"].Range.Tables[1].Rows.Last;
        // Word.Row oLastRow = rng_datos.Tables[1].Rows.Last;
        rng_datos.Tables[1].Rows.Add();
        rng_datos.Tables[1].Rows.Last.Cells[1].Select();
        wordApplication.Selection.TypeText("Texto en la primera celda");
        rng_datos.Tables[1].Rows.Last.Cells[2].Select();
        wordApplication.Selection.TypeText("Texto en la segunda celda");
        rng_datos.Tables[1].Rows.Last.Cells[3].Select();
        wordApplication.Selection.TypeText("Texto en la tercera celda");
        //oLastRow
        //TableRow rowCopy = (TableRow)theRow.CloneNode(true);
        //rowCopy.Descendants<TableCell>().ElementAt(0).Append(new Paragraph(new Run(new Text(order.Contact.ToString()))));
        //rowCopy.Descendants<TableCell>().ElementAt(1).Append(new Paragraph(new Run(new Text(order.NameOfProduct.ToString()))));
        //rowCopy.Descendants<TableCell>().ElementAt(2).Append(new Paragraph(new Run(new Text(order.Amount.ToString()))));
        //theTable.AppendChild(rowCopy);
        //Word.Range rowrng = oLastRow.Range;
        //rowrng.Copy();
    }
Example #2
0
    private void CargarDatosPersonales(Word.Range rng_datos, DataRow oFila)
    {
        //Ejemplo de Buscar y reemplazar el nombre dentro del rango.
        Word.Find fnd = rng_datos.Find;
        //Clear existing formatting;
        fnd.ClearFormatting();
        fnd.Replacement.ClearFormatting();

        fnd.Text             = "{nombre}";
        fnd.Replacement.Text = oFila["Profesional"].ToString();
        ExecuteReplace(fnd);

        fnd.Text             = "{nif}";
        fnd.Replacement.Text = oFila["t001_cip"].ToString();
        ExecuteReplace(fnd);

        fnd.Text             = "{perfil}";
        fnd.Replacement.Text = oFila["t035_descripcion"].ToString();
        ExecuteReplace(fnd);

        fnd.Text             = "{fnacimiento}";
        fnd.Replacement.Text = ((DateTime)oFila["t001_fecnacim"]).ToShortDateString();
        ExecuteReplace(fnd);

        fnd.Text             = "{foto}";
        fnd.Replacement.Text = "";// "15/02/1973";
        ExecuteFind(fnd);
        rng_datos.Select();
        rng_datos.SetRange(rng_datos.Start, rng_datos.End);

        bool bHayFoto = false;

        if (oFila["t001_foto"] != DBNull.Value)
        {
            bHayFoto = true;
            //sPathDocs
            SUPER.Capa_Negocio.Utilidades.ByteArrayToFile(sPathDocs + "..\\temp\\foto.jpg", (byte[])oFila["t001_foto"]);
        }

        if (bHayFoto)
        {
            Word.Selection currentSelection = wordApplication.Selection;
            currentSelection.MoveRight();
            //currentSelection.InlineShapes.AddPicture("D:\\Proyectos\\PRUEBAS\\WordTest01\\images\\01.jpg");
            currentSelection.InlineShapes.AddPicture(sPathDocs + "..\\temp\\foto.jpg");
            System.IO.File.Delete(sPathDocs + "..\\temp\\foto.jpg");
        }
        ExecuteReplace(fnd);
    }
Example #3
0
    private void CargarDatosPersonales(Word.Range rng_datos, string[] aDatos)
    {
        //Ejemplo de Buscar y reemplazar el nombre dentro del rango.
        Word.Find fnd = rng_datos.Find;
        //Clear existing formatting;
        fnd.ClearFormatting();
        fnd.Replacement.ClearFormatting();

        fnd.Text             = "{nombre}";
        fnd.Replacement.Text = aDatos[0];// "Nombre Profesional";
        ExecuteReplace(fnd);

        fnd.Text             = "{nif}";
        fnd.Replacement.Text = aDatos[1];// "123456789Z";
        ExecuteReplace(fnd);

        fnd.Text             = "{perfil}";
        fnd.Replacement.Text = aDatos[2];// "GERENTE";
        ExecuteReplace(fnd);

        fnd.Text             = "{fnacimiento}";
        fnd.Replacement.Text = aDatos[3];// "15/02/1973";
        ExecuteReplace(fnd);

        fnd.Text             = "{foto}";
        fnd.Replacement.Text = "";// "15/02/1973";
        ExecuteFind(fnd);
        rng_datos.Select();
        rng_datos.SetRange(rng_datos.Start, rng_datos.End);

        Word.Selection currentSelection = wordApplication.Selection;
        currentSelection.MoveRight();
        currentSelection.InlineShapes.AddPicture("D:\\Proyectos\\PRUEBAS\\WordTest01\\images\\01.jpg");

        ExecuteReplace(fnd);
    }
        /// <summary>
        /// before whatever initial operations are required to open the filestream
        /// or whatever (in the case of Word Auto, will require global variables)
        /// </summary>
        protected override int InitializeDocument(ControlFile _controlFile)
        {
            //create a word object instead of globals, ie., WOrd(ControlFIle)
            base.InitializeDocument(_controlFile);

            oWord = new Word.Application();
            oWord.Visible = true;
            object template = controlFile.Template;
            oDoc = oWord.Documents.Add( template,  oMissing,
                 oMissing,  oMissing);

            oSelection = oWord.Selection;

            // load defaults from tempalte

            try
            {
                oHeader1 = controlFile.Heading1;
                oHeader2 = controlFile.Heading2; // write getmethods?
                oHeader3 = controlFile.Heading3;
                oHeader4 = controlFile.Heading4;
                oHeader5 = controlFile.Heading5;
                oBullet = controlFile.Bullet;
                oTitle = controlFile.ChapterTitle;
                oStyle = controlFile.BodyText;
                oBulletNumber = controlFile.BulletNumber;
                oTableStyle = controlFile.TableStyle;
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
                return -1;
            }

            // test if style exists before being used
            bool bExists = false;
            foreach (Word.Style style in oDoc.Styles)
            {
                if (style.NameLocal == (oStyle).ToString())
                {
                    bExists = true;
                }
            }
            if (false == bExists)
            {
                NewMessage.Show(oStyle.ToString() + " did not exist");
            }

            oSelection.Style = oStyle;// (March 2013 - this might be reasonable replacement
            // set defaults
             //   oSelection.set_Style(ref oStyle); //this never seemed to happen 12/12/2010 (FIXED! The name was wrong, trying to come up with a better error check system
            Word.Style oSetStyle = (Word.Style)oSelection.Style;

            /* DId not work to test
            if (oSetStyle.NameLocal != (oStyle).ToString())
            {
                NewMessage.Show(oStyle.ToString() + " did not exist");
            }*/

            return 1;
        }
 public virtual void WindowBeforeDoubleClick(NetOffice.WordApi.Selection sel, bool cancel)
 {
     InvokerService.InvokeInternal.ExecuteMethod(this, "WindowBeforeDoubleClick", sel, cancel);
 }
 public virtual void WindowSelectionChange(NetOffice.WordApi.Selection sel)
 {
     InvokerService.InvokeInternal.ExecuteMethod(this, "WindowSelectionChange", sel);
 }
Example #7
0
    private void CargarExperiencias_old(Word.Range rng_datos, DataView dv)
    {
        Word.Range tblrng = rng_datos.Tables[1].Range;
        tblrng.Copy();

        if (dv.Count == 0)
        {
        }
        else
        {
            int i = 0;
            foreach (DataRowView oFila in dv)
            {
                //Redimensiona/reposiciona el rango dos caracteres después, con el mismo inicio y final
                rng_datos.SetRange(rng_datos.End - 1, rng_datos.End - 1);
                ////y se selecciona el rango
                rng_datos.Select();

                //Como se ha establecido el mismo inicio y final, el rango seleccionado es un punto de inserción
                Word.Selection currentSelection = wordApplication.Selection;
                // Test to see if selection is an insertion point.
                if (currentSelection.Type == WdSelectionType.wdSelectionIP)
                {
                    currentSelection.TypeParagraph();
                    wordApplication.Selection.MoveRight(Word.Enums.WdUnits.wdCharacter, 1);
                    wordApplication.Selection.TypeText(i.ToString());
                    wordApplication.Selection.MoveRight(Word.Enums.WdUnits.wdCharacter, 1);
                    //                    wordApplication.Selection.TypeText(" ");
                    //rng_datos.SetRange(rng_datos.End+1, rng_datos.End+1);
                    ////y se selecciona el rango
                    //rng_datos.Select();
                    //currentSelection.TypeParagraph();
                    //currentSelection.TypeParagraph();
                }
                //                //Redimensiona/reposiciona el rango dos caracteres después, con el mismo inicio y final
                //                rng_datos.SetRange(rng_datos.End + 2, rng_datos.End + 2);
                //y se selecciona el rango
                //                rng.Select();
                //Pegamos el rango copiado anteriormente, que contiene la tabla.
                //                currentSelection = wordApplication.Selection;
                //                currentSelection.Select();
                currentSelection = wordApplication.Selection;
                currentSelection.Paste();
                //rng_datos.Paste();
                //rng.Select();
                rng_datos.SetRange(rng_datos.End + 1, rng_datos.End + 1);

                //                rng_datos.Tables[rng_datos.Tables.Count].Rows[1].Cells[2].Select();
                //                wordApplication.Selection.TypeText(oFila["T812_FINICIO"].ToString());

                //rng_datos.Tables[1].Rows.Add();
                //rng_datos.Tables[1].Rows.Last.Cells[1].Select();
                //wordApplication.Selection.TypeText(oFila["TITULO"].ToString());
                //rng_datos.Tables[1].Rows.Last.Cells[2].Select();
                //wordApplication.Selection.TypeText(oFila["PROVEEDOR"].ToString());
                //rng_datos.Tables[1].Rows.Last.Cells[3].Select();
                //wordApplication.Selection.TypeText(oFila["FOBTENCION"].ToString());
                i++;
            }
        }
        // aDatos
    }
 public virtual void XMLSelectionChange(NetOffice.WordApi.Selection sel, NetOffice.WordApi.XMLNode oldXMLNode, NetOffice.WordApi.XMLNode newXMLNode, Int32 reason)
 {
     InvokerService.InvokeInternal.ExecuteMethod(this, "XMLSelectionChange", sel, oldXMLNode, newXMLNode, reason);
 }