addin word document in c# - template style - crash?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: addin word document in c# - template style - crash?

Hybrid View

  1. #1
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128

    addin word document in c# - template style - crash?

    Hi,
    I was wondering if anyone had done any C# office word addin coding?

    Everything is great - except I can't seem to work out how to add custom table styles. I can add normal styles. But want to specify and add table styles particularly.

    For example, I was trying this:

    Word.Selection sel = application.Selection;
    Word.Table table = null;
    table = sel.Tables.Add( sel.Range, 1, 2 );
    table.set_Style("ANewStyle"); //<-- causes an assert exception

    So I've been wondering, how to add a table style and details to the word office design?

    Thanx,

    Ben

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,090

    Re: addin word document in c# - template style - crash?

    Which Office version is this, Ben?

  3. #3
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128

    Re: addin word document in c# - template style - crash?

    Hi Hannes,
    it's office 2007. Have you come across this before?

    Thanx,

    Ben

  4. #4
    Join Date
    Feb 2013
    Posts
    2

    Re: addin word document in c# - template style - crash?

    Hello,
    If you're creating a non сommercial project you may want a look at OpenXML:

    http://www.microsoft.com/en-us/downl...s.aspx?id=5124
    http://msdn.microsoft.com/en-us/libr.../cc850841.aspx
    http://www.c-sharpcorner.com/Blogs/9051/

    For commercial purposes i would recommend you this C# Word component.
    It allows easy customization of the document styles:

    using System;
    using System.Drawing;
    using Docs.Word;

    namespace SampleManager
    {
    class Tables_Style
    {
    internal static Document Main1()
    {
    // Open a source document and gets both tables
    Document Doc = Document.ReadDocX("Temp.docx");
    Table Table1 = (Table)Doc.Sections[0].Nodes[0];
    Table Table2 = (Table)Doc.Sections[0].Nodes[2];

    // Change style properties of 1st table
    Table1.Rows[0].Cells[0].Style.Shading = new Shading(Color.Yellow);
    Table1.Rows[1].Cells[1].Style.Shading = new Shading(Color.Tomato, Color.Violet, ShadingStyle.HorizontalStripe);
    Table1.Rows[1].Cells[0].Style.Borders.Bottom = new Border(2, Color.Blue);

    // Change style properties of 2nd table
    Table2.Rows[0].Cells[0].Style.Width.Width = 240;
    Table2.Rows[1].Cells[1].Style.Borders = new Borders(3, Color.Red);

    return Doc;
    }
    }
    }

  5. #5
    Join Date
    Jul 2011
    Posts
    6

    Re: addin word document in c# - template style - crash?

    Hello,

    This guide: How to Set Word Tablet Style may be helpful for you. Have a look!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center