Pregunta

Necesito agregar una fila a una tabla en MS Word delimitado tarde.Consulte mi código aquí ...

En el código, puede ver que tengo que implementar el código para la función public void AddNewRow(int tableId).

Aquí necesito agregar una nueva fila EN BLANCO, ya que el recuento de filas que voy a agregar a la tabla varía según el DataSet.

¿Alguna idea de cómo hacerlo ...?Mejor si puedes compartir código ...

(Otras áreas de código funcionan perfectamente)

Estoy usando .Net versión 2.0

¿Fue útil?

Solución

Encontré la respuesta por mí mismo, creo que esto será útil para todos ustedes ...

public void AddNewRow(int tableId, int rowCount)
    {
        object[] oParams = new object[1];
        oParams[0] = tableId;
        object table_ = tables.GetType().InvokeMember("Item",
        BindingFlags.InvokeMethod,
        null,
        tables,
        oParams);
        object rows = table_.GetType().InvokeMember("Rows",
        System.Reflection.BindingFlags.GetProperty,
        null,
        table_,
        null);
        oParams = new object[1];
        if (rowCount == 1)
        {
            object row = rows.GetType().InvokeMember("Add",
            BindingFlags.InvokeMethod,
            null,
            rows,
            null);
        }
        else
        {
            for (int i = 0; i < rowCount; i++)
            {
                object row = rows.GetType().InvokeMember("Add",
            BindingFlags.InvokeMethod,
            null,
            rows,
            null);
            }
        }
    }

Otros consejos

Table table = tables[tableid];

  for (int i = 0; i < 20; i++) // I took it 20 just for example
   {
     Row row = table.Rows.Add();                   
   }

Consulte el siguiente enlace para obtener más información

http://jgvimalan.wordpress.com/2011/02/08/add-rows-to-table-in-ms-word-document-using-c/

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top