using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
using System.Data.SqlClient;
namespace OfficeOperator
{
public class WordOperator
{
Microsoft.Office.Interop.Word.Application wordApp;
Document wordDoc;
public WordOperator()
{
wordApp = new Microsoft.Office.Interop.Word.Application();
wordDoc = new Document();
}
public void CreateWord()
{
wordDoc = wordApp.Documents.Add();
wordDoc.PageSetup.Orientation = WdOrientation.wdOrientPortrait;
wordDoc.PageSetup.LeftMargin = wordApp.MillimetersToPoints(0.5f);
wordDoc.PageSetup.RightMargin = wordApp.MillimetersToPoints(0.5f);
wordDoc.PageSetup.TopMargin = wordApp.MillimetersToPoints(0.5f);
wordDoc.PageSetup.BottomMargin = wordApp.MillimetersToPoints(0.5f);
wordDoc.PageSetup.PageWidth = 600;
wordDoc.PageSetup.PageHeight = 800;
//添加页眉、页脚
SetPageHeader("C#经典实例300个");
SetPageFooter("第17张 访问office");
//插入页码
InsertPageNumber(true);
//插入文字
InsertText("Word文档创建成功!", 16, WdColorIndex.wdBlack, 1, WdParagraphAlignment.wdAlignParagraphCenter, "宋体");
//换行
NewLine();