单词互操作,表边框

时间:2014-02-03 15:39:29

标签: c# winforms ms-word interop office-interop

我会试着说出我想要的东西: 我创建一个单词doc,并添加一个表,很好,但表的边框是透明的,我不能使用它,我需要在doc写保存为PDF。

我有一个很好的课程控制单词,但是我失去了理智,我没有解决问题。

我使用winform和.net 3.5

    // atributos - atributes 
    public static object missing = System.Reflection.Missing.Value; // Valores defauls que não precisa alterar
    public static Word.Application w_app; // aplicação do word
    public static Word.Document w_doc; // documento do word

    // metodos - methods
    public void criar_novo_arquivo_word() // create a new file word doc
    {
        Word.Application app = new Word.Application();
        w_app = app;
        w_doc = app.Documents.Add(missing, missing, missing, missing);
        w_app.Visible = false;
    }

    public void visualizar_word(bool opcao) // set visible
    {
        w_app.Visible = opcao;
    }

    public void inserir_tabela(int numero_de_linhas, int numero_de_colunas) // insert table, here live my problema
    {
        Word.Range range = w_doc.Range(ref missing, ref missing);
        range.Tables.Add(range, numero_de_linhas, numero_de_colunas);
    }

1 个答案:

答案 0 :(得分:5)

试试这个:

public void inserir_tabela(int numero_de_linhas, int numero_de_colunas) // insert table, here live my problema
{
    Word.Range range = w_doc.Range(ref missing, ref missing);
    Word.Table myTable = range.Tables.Add(range, numero_de_linhas, numero_de_colunas);

    myTable.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
    myTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
}