网址 http://www.cnblogs.com/hanfei8987/articles/1320380.html
使用C#实现简单操作金山公司的WPS Office软件
个人版的WPS软件永久免费,且操作界面与Microsoft Office基本相同,可快速上手!下载
地址:http://kad.www.duba.net/ever/WPS2007.12012.exe
public WPS.Application WPSApp;
/// <summary>
/// 启动WPS文字,并添加居中文字,以及插入一幅图片
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStart_Click(object sender, System.EventArgs e)
{
object MissingValue=Type.Missing;
object lleft = 100, ltop = 50, lwidth = 148, lheight = 60;
// 启动WPS
WPSApp = new WPS.ApplicationClass();
// 使WPS可见
WPSApp.Visible = true;
// 在Documents中新建一篇文档
WPS.Document WPSDocument = WPSApp.Documents.Add(ref MissingValue, false, 0,
true);
// 设置文字居中对齐
WPSApp.Selection.ParagraphFormat.Alignment =
WpsParagraphAlignment.wpsAlignParagraphCenter;
// 插入文字,该文字是居中显示的
WPSApp.Selection.Range.Text = "hello,world";
// 插入图片
WPSDocument.Shapes.AddPicture
("http://img.kingsoft.com/publish/kingsoft/images/gb/sy/logo.gif",
ref lleft, ref ltop, ref lwidth, ref lheight,
ref MissingValue, ref MissingValue, ref MissingValue);
}
/// <summary>
/// 关闭WPS
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClose_Click(object sender, System.EventArgs e)
{
object MissingValue=Type.Missing;
object bSave = false;
if (WPSApp != null)
{
// 首先调用WPS.Application的Quit方法,并且不保存修改
WPSApp.Quit(ref bSave, ref MissingValue, ref MissingValue);
}
// 释放对象
System.Runtime.InteropServices.Marshal.ReleaseComObject(WPSApp);
WPSApp = null;
}