zoukankan      html  css  js  c++  java
  • asp.net访问dcom组件(wps或office)配置

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;

    using WPS;
    using System.IO;

    namespace dveda.Module
    {
    class Word2PDF : IDisposable
    {
    Application wps;

    public Word2PDF()
    {
    wps = new Application();
    }

    /// <summary>
    /// 合并文件
    /// </summary>
    /// <param name="firstfile">第一个文件</param>
    /// <param name="secodefile">第二个文件</param>
    /// <param name="outputfile">合并后输出的文件</param>
    /// <returns></returns>
    public bool mergerFile(string firstfile, string secodefile,string outputfile)
    {
    try
    {
    object objMissing = System.Reflection.Missing.Value;

    Document origDoc = wps.Documents.Open(firstfile, Visible: false);
    origDoc.Activate();

    wps.Selection.InsertFile(secodefile);
    wps.Selection.InsertBreak(WpsBreakType.wpsPageBreak);
    wps.ActiveDocument.SaveAs(outputfile);
    wps.ActiveDocument.Close();
    }
    catch (Exception ex)
    {
    throw ex;
    }


    //wps.Selection.Copy();
    //wps.Selection.Document;

    /*
    //object missing = Missing.Value;
    //string oFirstDoc = @"d:\1.doc";//word檔1
    //object oSecondDoc = @"d:\2.doc";//word檔2
    //object oOutputDoc = @"d:\3.doc";//合併檔s

    ////object oPageBreak = Word.WdBreakType.wdLineBreak;//接下行合併(LineBreak)
    //object oPageBreak = Word.WdBreakType.wdPageBreak;//接下頁合併(PageBreak)

    //Word._Application wordApp = new Word.Application();
    //Word._Document origDoc = wordApp.Documents.Open(ref oSecondDoc, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
    //origDoc.Activate();
    //wordApp.Selection.InsertFile(oFirstDoc, ref missing, ref missing, ref missing, ref missing);
    //wordApp.Selection.InsertBreak(ref oPageBreak);

    //wordApp.ActiveDocument.SaveAs(ref oOutputDoc, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
    //wordApp.ActiveDocument.Close(ref missing, ref missing, ref missing);
    //wordApp.Quit(ref missing, ref missing, ref missing);//加這行可以 Kill WINWORD.EXE process
    * */

    return true;
    }

    public bool ToPdf(string wpsFilename, string pdfFilename = null)
    {
    if (wpsFilename == null) { throw new ArgumentNullException("wpsFilename"); }

    if (pdfFilename == null)
    {
    pdfFilename = Path.ChangeExtension(wpsFilename, "pdf");
    }

    //Console.WriteLine(string.Format(@"正在转换 [{0}]-> [{1}]", wpsFilename, pdfFilename));

    Document doc = wps.Documents.Open(wpsFilename, Visible: false);
    doc.ExportPdf(pdfFilename);
    doc.Close();
    return true;
    }

    public void Dispose()
    {
    if (wps != null) { wps.Terminate();}
    }
    }
    }

    //dcom配置

    dcomcnfg.exe

    添加network service 读写权限

    标识-下列账号administrator/密码

    最后需要注意的是,如果wps损坏,wps自身带有重新注册工具,可以重新注册,注册完成后,要重新启动系统

  • 相关阅读:
    SQL Server 2005中NTEXT与NVARCHAR(MAX)
    WiX安装选项开始菜单项
    Linq to SQL 查询Tips
    WCF的Message Logging 和Tracing
    Publish Server Performance Monitors with MsChart
    Pushing Data to a Silverlight Client with a WCF Duplex Service
    IronPython 2.0 发布了
    设置系统环境变量立即生效的VBS脚本
    微软网络数据包分析工具 Microsoft Network Monitor 3.2
    SQL Server 2005最新Service Pack 3
  • 原文地址:https://www.cnblogs.com/kuailewangzi1212/p/3095457.html
Copyright © 2011-2022 走看看