June 13th, 2012 05:37 AM
#1
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
June 13th, 2012 06:30 AM
#2
Re: addin word document in c# - template style - crash?
Which Office version is this, Ben?
June 13th, 2012 11:18 AM
#3
Re: addin word document in c# - template style - crash?
Hi Hannes,
it's office 2007. Have you come across this before?
Thanx,
Ben
March 14th, 2013 01:53 AM
#4
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;
}
}
}
March 18th, 2013 03:43 AM
#5
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
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks