資源簡介
調(diào)用WPS實(shí)現(xiàn)WORD轉(zhuǎn)PDF、EXCEL轉(zhuǎn)PDF,需安裝WPS 2012,即所謂的v9版本。
【核心代碼】
ET._Application app = null;
ET._Workbook xls = null;
try
{
app = new ET.Application();
app.set_Visible(false);
xls = app.get_Workbooks().Open(source);
xls.ExportPdf(target);
xls.Close(false);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
finally
{
if (xls != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(xls);
}
if (app != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);
}
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
try
{
File.Delete(source);
}
catch { }
}
代碼片段和文件信息
using?System;
using?System.IO;
namespace?WPSConverter
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????if?(args?==?null?||?args.Length?==?0)
????????????{
????????????????return;
????????????}
????????????try
????????????{
????????????????if?(!File.Exists(args[0]))
????????????????{
????????????????????return;
????????????????}
????????????}
????????????catch?(Exception?ex)
????????????{
????????????????Console.WriteLine(ex.Message);
????????????????return;
????????????}
????????????string?ext?=?Path.GetExtension(args[0]);
????????????string?source?=?Path.Combine(Path.GetDirectoryName(args[0])?Guid.NewGuid().ToString(“N“)?+?ext);
????????????string?target?=?args.Length?>=?2???args[1]?:?Path.ChangeExtension(args[0]?“.p
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-03-30?15:42??bin\
?????文件???????11264??2016-03-30?15:42??bin\WPSConverter.exe
?????文件???????13824??2016-03-30?15:42??bin\WPSConverter.pdb
?????目錄???????????0??2016-03-30?14:57??obj\
?????目錄???????????0??2016-03-30?14:57??obj\x86\
?????目錄???????????0??2016-03-30?15:42??obj\x86\Debug\
?????文件????????7388??2016-03-30?14:57??obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件??????266240??2016-03-30?15:42??obj\x86\Debug\Interop.KSO.dll
?????文件??????434688??2016-03-30?15:42??obj\x86\Debug\Interop.Office.dll
?????文件??????921088??2016-03-30?15:42??obj\x86\Debug\Interop.Word.dll
?????目錄???????????0??2016-03-28?14:21??obj\x86\Debug\TempPE\
?????文件?????????979??2016-03-28?17:34??obj\x86\Debug\wps2pdf.csproj.FileListAbsolute.txt
?????文件?????????971??2016-03-28?17:34??obj\x86\Debug\wps2pdf.csproj.ResolveComReference.cache
?????文件????????5120??2016-03-28?17:34??obj\x86\Debug\wps2pdf.exe
?????文件???????11776??2016-03-28?17:34??obj\x86\Debug\wps2pdf.pdb
?????文件?????????480??2016-03-29?15:50??obj\x86\Debug\WPSBatch.csproj.FileListAbsolute.txt
?????文件?????????971??2016-03-29?15:50??obj\x86\Debug\WPSBatch.csproj.ResolveComReference.cache
?????文件???????10240??2016-03-29?15:50??obj\x86\Debug\WPSBatch.exe
?????文件???????13824??2016-03-29?15:50??obj\x86\Debug\WPSBatch.pdb
?????文件????????1483??2016-03-30?15:42??obj\x86\Debug\WPSConverter.csproj.FileListAbsolute.txt
?????文件????????1339??2016-03-30?15:42??obj\x86\Debug\WPSConverter.csproj.ResolveComReference.cache
?????文件????????7055??2016-03-30?15:42??obj\x86\Debug\WPSConverter.csprojResolveAssemblyReference.cache
?????文件???????11264??2016-03-30?15:42??obj\x86\Debug\WPSConverter.exe
?????文件???????13824??2016-03-30?15:42??obj\x86\Debug\WPSConverter.pdb
?????文件????????5192??2016-03-30?15:33??Program.cs
?????目錄???????????0??2016-03-30?14:57??Properties\
?????文件????????1359??2016-03-29?15:51??Properties\AssemblyInfo.cs
?????文件????????5310??2016-03-30?00:29??WPSConverter.csproj
?????文件?????????379??2016-03-29?16:47??WPSConverter.csproj.user
?????文件?????????972??2016-03-29?15:51??WPSConverter.sln
評論
共有 條評論
相關(guān)資源
- PDF文件 閱讀控件 (VeryPDF PDFView OCX)
- C#文件流讀取CSV文件
- c#讀寫PDF文件sql
- 驗(yàn)證EXCEL導(dǎo)入模板是否符合標(biāo)準(zhǔn)
- C#將Excel導(dǎo)入到Access數(shù)據(jù)庫表(winFor
- C# PDF轉(zhuǎn)圖片
- Unity5實(shí)戰(zhàn):使用C#和Unity開發(fā)多平臺游
- ppt課件:asp.netpdf格式
- Wpf生成word文檔
- C# NPOI導(dǎo)出Excel,Words轉(zhuǎn)PDF
- 自己用C#寫的Word轉(zhuǎn)Html工具,親測可用
- C#使用Adobe Reader讀取PDF
- w3cschool全套PDF教程
- NET 4.0面向?qū)ο缶幊搪?基礎(chǔ)篇 PDF
- C#本質(zhì)論 原書第4版 最新版 高清掃描
- asp·net生成PDF詳解
- c# 調(diào)用word 的vba的宏
- C#本質(zhì)論(第4版C# 5.0).pdf 高清完整版
- 2008.精通LINQ數(shù)據(jù)訪問技術(shù)pdf及源碼
-
Visual.Studio.NET.fr
amework技術(shù)內(nèi)幕(高 - [Csharp高級編程(第6版)].美內(nèi)格爾
- ASP.NET(c#) 從零動態(tài)生成Word文件用程
- c#導(dǎo)出excel支持多sheet導(dǎo)出,可自定義
- 用c#將pdf文件轉(zhuǎn)換成圖片文件
- 2012我的C#全能Excel操作無需Office不使用
- .net批量打印word源碼C#_VS2012
- VS 2008 C#讀寫excel文件
- 安卓使用poi XWPFDocument讀取及修改wor
- 2021最新版NPOI插件
- C#讀寫EXCEl支持xlsx