3

I am working on a application using C# and Spire.Doc which saves the word document to specified format which includes logo at the header and specified font size and style.

Now I can paste logo at the header using spire.doc but I'm not able to change the font style and size of the whole document:

font size should be 10;
font should be: franklin gothic demi

Can someone please help me for this? Thanks in advance.

hdoghmen
  • 3,175
  • 4
  • 29
  • 33
pavan betageri
  • 123
  • 1
  • 1
  • 9

2 Answers2

3

You will need to use Microsoft.Office.Interop.Word.

This will allow you to do something like this:

var start = this.Content.Start;
var end = this.Content.End;

var docRange = this.Range(ref start, ref end).Select();

docRange.Font.Size = 10; 
docRange.Font.Name = "Franklin Gothic Demi"; 

For more detail see: How to: Programmatically Format Text in Documents.

EDIT:

To add an image to the header you need to do something like:

section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
       .Shapes
       .AddPicture(@"headerImage.jpg", left, top, width, height);

Or:

Document doc = new Document();
doc.LoadFromFile(@"C:\MyDoc.docx", FileFormat.Docx);
HeaderFooter header = doc.Sections[0].HeadersFooters.Header;
Image headerImage = Image.FromFile(@"C:\headerImage.png");
header.Paragraphs[0].AppendPicture(logo).TextWrappingStyle = TextWrappingStyle.Tight;
RagtimeWilly
  • 5,265
  • 3
  • 25
  • 41
  • Thank you so much...its working...now my doubt is can we add image into header of word document using Microsoft.Office.Interop.Word??....please suggest me some solutions...thank in advance – pavan betageri Mar 26 '15 at 19:10
  • @pavanbetageri I've edited answer to include information about adding an image. Can you be sure to accept as answer if this solved your problem? :) – RagtimeWilly Mar 26 '15 at 22:03
  • @RagtimeWilly...sure..ill try this code today...thank you so much – pavan betageri Mar 27 '15 at 04:57
  • @RagtimeWilly...its working, can i do the same using spire.doc for entire word document?? – pavan betageri Mar 29 '15 at 15:29
1

If you are using Spire.Doc :

        //Font name
        txtRange.CharacterFormat.FontName = "Century Gothic";

        //Size
        txtRange.CharacterFormat.FontSize = 15;

        //Underline
        txtRange.CharacterFormat.UnderlineStyle = UnderlineStyle.Dash;

        //Color
        txtRange.CharacterFormat.TextColor = Color.Brown;
        txtRange1.CharacterFormat.TextColor = Color.ForestGreen;
hdoghmen
  • 3,175
  • 4
  • 29
  • 33