hanfei8987

C#操作WPS示例

 

个人版的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;
  }

分类:

技术点:

相关文章:

  • 2021-10-16
  • 2021-12-18
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
  • 2021-06-24
  • 2022-01-17
猜你喜欢
  • 2022-01-08
  • 2021-06-02
  • 2021-12-05
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案