最近在做預(yù)覽功能有些壓抑?
vs啟動(dòng)項(xiàng)目可以生成wps實(shí)例
本地iis部署的站點(diǎn)卻不行
原因是vs是管理員權(quán)限,而iis沒有權(quán)限
解決方法
啟動(dòng)IIS,應(yīng)用程序池-“選定的應(yīng)用程序池”-高級(jí)設(shè)置-進(jìn)程模型-標(biāo)識(shí):設(shè)置為管理員賬號(hào)administrator
代碼
1.安裝WPS 2016 專業(yè)版
2.方法一:在項(xiàng)目中引用etapi.dll,wpsapi.dll,wppapi.dll肥照,在WPS的安裝目錄中,如C:\Program Files (x86)\Kingsoft\WPS Office\10.8.2.6666\office6
方法二:根據(jù)實(shí)際需要科添加下面的COM引用
原文:https://blog.csdn.net/xqf222/article/details/81237915
添加引用 -> COM -> Kingsoft Add-In Designer
添加引用 -> COM -> Microsoft Office 11.0 Object Library
添加引用 -> COM -> Upgrade WPS Office 3.0 Object Library(Beta)
添加引用 -> COM -> Upgrade WPS Presentation 3.0 Object Library(Beta)
添加引用 -> COM -> Upgrade Kingsoft WPS 3.0 Object Library(Beta)
添加引用 -> COM -> Kingsoft WPS Extend Apo 1.0 Object Library(Beta)
public class ToPdfHelper : IDisposable
? ? {
? ? ? ? dynamic wps;
? ? ? ? public ToPdfHelper(string typeName)
? ? ? ? {
? ? ? ? ? ? if (typeName == "xls")
? ? ? ? ? ? ? ? typeName = "KET.Application";
? ? ? ? ? ? else if (typeName == "ppt")
? ? ? ? ? ? ? ? typeName = "KWPP.Application";
? ? ? ? ? ? else
? ? ? ? ? ? ? ? typeName = "KWps.Application";
? ? ? ? ? ? //創(chuàng)建wps實(shí)例,需提前安裝wps
? ? ? ? ? ? Type type = Type.GetTypeFromProgID(typeName);
? ? ? ? ? ? if (type == null)
? ? ? ? ? ? ? ? type = Type.GetTypeFromProgID("wps.Application");
? ? ? ? ? ? wps = Activator.CreateInstance(type);
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 使用wps將Word轉(zhuǎn)PDF
? ? ? ? /// </summary>
? ? ? ? /// <param name="saveUrl">文件路徑</param>
? ? ? ? /// <param name="targetPath">源文件路徑</param>
? ? ? ? /// <returns></returns>
? ? ? ? public string WordWpsToPdf(string saveUrl, string targetPath)
? ? ? ? {
? ? ? ? ? ? if (targetPath == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? throw new ArgumentNullException("wpsFilename");
? ? ? ? ? ? }
? ? ? ? ? ? var wordPath = saveUrl + targetPath;
? ? ? ? ? ? var pdfPath = Path.ChangeExtension(wordPath, "pdf");
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //用wps 打開word不顯示界面
? ? ? ? ? ? ? ? dynamic doc = wps.Documents.Open(wordPath, Visible: false);
? ? ? ? ? ? ? ? //doc 轉(zhuǎn)pdf
? ? ? ? ? ? ? ? doc.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);
? ? ? ? ? ? ? ? //設(shè)置隱藏菜單欄和工具欄
? ? ? ? ? ? ? ? //wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);
? ? ? ? ? ? ? ? doc.Close();
? ? ? ? ? ? ? ? doc = null;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Dispose();
? ? ? ? ? ? }
? ? ? ? ? ? return Path.ChangeExtension(targetPath, "pdf");
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 使用wps將xls轉(zhuǎn)PDF
? ? ? ? /// </summary>
? ? ? ? /// <param name="saveUrl">文件路徑</param>
? ? ? ? /// <param name="targetPath">源文件路徑</param>
? ? ? ? /// <returns></returns>
? ? ? ? public string XlsWpsToPdf(string saveUrl, string targetPath)
? ? ? ? {
? ? ? ? ? ? if (targetPath == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? throw new ArgumentNullException("wpsFilename");
? ? ? ? ? ? }
? ? ? ? ? ? var wordPath = saveUrl + targetPath;
? ? ? ? ? ? var pdfPath = Path.ChangeExtension(wordPath, "pdf");
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? XlFixedFormatType targetType = XlFixedFormatType.xlTypePDF;
? ? ? ? ? ? ? ? object missing = Type.Missing;
? ? ? ? ? ? ? ? //xls 轉(zhuǎn)pdf
? ? ? ? ? ? ? ? dynamic doc = wps.Application.Workbooks.Open(wordPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
? ? ? ? ? ? ? ? doc.ExportAsFixedFormat(targetType, pdfPath, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
? ? ? ? ? ? ? ? //設(shè)置隱藏菜單欄和工具欄
? ? ? ? ? ? ? ? //wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);
? ? ? ? ? ? ? ? doc.Close();
? ? ? ? ? ? ? ? doc = null;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Dispose();
? ? ? ? ? ? }
? ? ? ? ? ? return Path.ChangeExtension(targetPath, "pdf");
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 使用ppt將xls轉(zhuǎn)PDF
? ? ? ? /// </summary>
? ? ? ? /// <param name="saveUrl">文件路徑</param>
? ? ? ? /// <param name="targetPath">源文件路徑</param>
? ? ? ? /// <returns></returns>
? ? ? ? public string PptWpsToPdf(string saveUrl, string targetPath)
? ? ? ? {
? ? ? ? ? ? if (targetPath == null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? throw new ArgumentNullException("wpsFilename");
? ? ? ? ? ? }
? ? ? ? ? ? var wordPath = saveUrl + targetPath;
? ? ? ? ? ? var pdfPath = Path.ChangeExtension(wordPath, "pdf");
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //ppt 轉(zhuǎn)pdf
? ? ? ? ? ? ? ? dynamic doc = wps.Presentations.Open(wordPath, MsoTriState.msoCTrue,
? ? ? ? ? ? ? ? ? ? MsoTriState.msoCTrue, MsoTriState.msoCTrue);
? ? ? ? ? ? ? ? object missing = Type.Missing;
? ? ? ? ? ? ? ? //doc.ExportAsFixedFormat(pdfPath, PpFixedFormatType.ppFixedFormatTypePDF,
? ? ? ? ? ? ? ? //? ? PpFixedFormatIntent.ppFixedFormatIntentPrint,
? ? ? ? ? ? ? ? //? ? MsoTriState.msoCTrue, PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst,
? ? ? ? ? ? ? ? //? ? PpPrintOutputType.ppPrintOutputBuildSlides,
? ? ? ? ? ? ? ? //? ? ? MsoTriState.msoCTrue, null, PpPrintRangeType.ppPrintAll,"",
? ? ? ? ? ? ? ? //? ? ? false, false, false, false, false, missing);
? ? ? ? ? ? ? ? doc.SaveAs(pdfPath, PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);
? ? ? ? ? ? ? ? //設(shè)置隱藏菜單欄和工具欄
? ? ? ? ? ? ? ? //wps.setViewerPreferences(PdfWriter.HideMenubar | PdfWriter.HideToolbar);
? ? ? ? ? ? ? ? doc.Close();
? ? ? ? ? ? ? ? doc = null;
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception e)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? targetPath = GetEXCELtoPDF.CreatePDFs(saveUrl, targetPath);
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Dispose();
? ? ? ? ? ? }
? ? ? ? ? ? return Path.ChangeExtension(targetPath, "pdf");
? ? ? ? }
? ? ? ? public void Dispose()
? ? ? ? {
? ? ? ? ? ? if (wps != null) { wps.Quit(); wps = null; }
? ? ? ? }
? ? }