Pergunta

Preciso adicionar uma linha a uma tabela no MS Word com limite tardio.Por favor veja meu código aqui...

No código você pode ver que tenho que implementar código para função public void AddNewRow(int tableId).

Aqui preciso adicionar uma nova linha EM BRANCO, pois a contagem de linhas que irei adicionar à tabela varia dependendo do DataSet.

Alguma ideia de como fazer...?Melhor se você puder compartilhar o código ...

(Outras áreas de código funcionando perfeitamente)

Estou usando o .Net versão 2.0

Foi útil?

Solução

Eu mesmo encontrei a resposta, acho que isso será útil para todos vocês ...

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);
            }
        }
    }

Outras dicas

Table table = tables[tableid];

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

Consulte o seguinte link para obter mais informações

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top