http://www.cnblogs.com/hanfei8987/articles/1320380.html

 


网址  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;
  }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值