Typografi i Word
Hej, jeg har lavet et lille program, der eksporterer en text til et nyt word-dokument.Jeg har dog ikke fundet ud af hvordan jeg ændrer skrifttypen.
Jeg vil nemlig gerne anvende en anden skrifttype end Times New Roman.
Nogen der kan hjælpe ?
På forhånd tak!
-----------------------------------------
Min kode:
-----------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WordExport
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox tbText;
private System.Windows.Forms.Button btnExp;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.tbText = new System.Windows.Forms.TextBox();
this.btnExp = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// tbText
//
this.tbText.Location = new System.Drawing.Point(104, 56);
this.tbText.Name = "tbText";
this.tbText.Size = new System.Drawing.Size(152, 20);
this.tbText.TabIndex = 0;
this.tbText.Text = "";
//
// btnExp
//
this.btnExp.Location = new System.Drawing.Point(112, 88);
this.btnExp.Name = "btnExp";
this.btnExp.TabIndex = 1;
this.btnExp.Text = "exporter";
this.btnExp.Click += new System.EventHandler(this.btnExp_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(416, 358);
this.Controls.Add(this.btnExp);
this.Controls.Add(this.tbText);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnExp_Click(object sender, System.EventArgs e)
{
string text = tbText.Text;
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */
//Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//Insert a paragraph at the end of the document.
Word.Paragraph oParaH;
object Rng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oParaH = oDoc.Content.Paragraphs.Add(ref Rng);
oParaH.Range.Text = text;
oParaH.Range.Font.Bold = 1;
oParaH.Range.Font.Size = 30;
oParaH.Format.SpaceAfter = 5;
oParaH.Range.InsertParagraphAfter();
}
}
}
