本文介绍通过调用spire.cloud.word.sdk提供的convertapi接口将word转换为pdf、xps、epub、rtf以及将docx转为doc格式等。调用接口方法及步骤参考以下步骤:
步骤一:dll文件获取及导入。通过官网本地下载sdk文件包。(须在e-iceblue中国官网在线编辑板块中注册账号并登录)
下载后,解压文件,将spire.cloud.word.sdk.dll文件及其他三个dll添加引用至vs程序;或者在程序中通过nuget搜索下载,直接导入所有dll。dll引用结果如下图所示:
步骤二:app id及key获取。在“我的应用”板块中创建应用以获得app id及app key。
步骤三:源文档上传。在“文档管理”板块,上传源文档。这里可以建文件夹,将文档存放在文件夹下。不建文件夹时,源文档及结果文档直接保存在根目录。本文示例中,建了两个文件夹,分别用于存放源文档及结果文档。(云平台提供免费1 万次调用次数和 2g 文档内存)
using system; using spire.cloud.word.sdk.client; using spire.cloud.word.sdk.api; namespace wordtopdf { class program { static string appid = "app id"; static string appkey = "app key"; static void main(string[] args) { //配置app id和app key configuration configuration = new configuration(appid, appkey); //初始化convertapi对象 convertapi convertapi = new convertapi(configuration); string name = "sample.docx";//源文档 string format = "pdf";//转换的目标文档格式 string password = null;//源文档 string folder = "input";//源文档所在文件夹,如果没有文件夹则为null string storage = null;//使用冰蓝云配置的2g空间存贮文档,可设置为null string destfilepath = "output/wordtopdf.pdf";//结果文档路径(结果文档保存在output文件夹下) //调用方法将word转为pdf convertapi.convertdocument(name, format, password, folder, storage, destfilepath); } } }
using system; using spire.cloud.word.sdk.api; using spire.cloud.word.sdk.client; namespace wordtoxps { class program { static string appid = "app id"; static string appkey = "app key"; static void main(string[] args) { //配置app id和app key configuration configuration = new configuration(appid, appkey); //初始化convertapi对象 convertapi convertapi = new convertapi(configuration); string name = "sample.docx"; //源文档 string format = "xps";//转换的目标文档格式 string password = null;//源文档密码 string folder = "input";//源文档的文件夹,如果没有文件夹则为null string storage = null;//使用冰蓝云配置的2g空间存贮文档,可设置为null string destfilepath = "output/wordtoxps.xps";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将word转为xps convertapi.convertdocument(name, format, password, folder, storage, destfilepath); } } }
using system; using spire.cloud.word.sdk.api; using spire.cloud.word.sdk.client; namespace wordtoepub { class program { static string appid = "app id"; static string appkey = "app key"; static void main(string[] args) { //配置app id和app key configuration configuration = new configuration(appid, appkey); //初始化convertapi对象 convertapi convertapi = new convertapi(configuration); string name = "sample.docx"; //源文档 string format = "epub";//转换的目标文档格式 string password = null;//源文档密码 string folder = "input";//源文档的文件夹,如果没有文件夹则为null string storage = null;//使用冰蓝云配置的2g空间存贮文档,可设置为null string destfilepath = "output/wordtoepub.epub";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将word转为epub convertapi.convertdocument(name, format, password, folder, storage, destfilepath); } } }
using system; using spire.cloud.word.sdk.client; using spire.cloud.word.sdk.api; namespace wordtortf { class program { static string appid = "app id"; static string appkey = "app key"; static void main(string[] args) { //配置app id和app key configuration configuration = new configuration(appid, appkey); //初始化convertapi对象 convertapi convertapi = new convertapi(configuration); string name = "sample.docx"; //源文档 string format = "rtf";//转换的目标文档格式 string password = null;//源文档密码 string folder = "input";//源文档的文件夹,如果没有文件夹则为null string storage = null;//使用冰蓝云配置的2g空间存贮文档,可设置为null string destfilepath = "output/wordtortf.rtf";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将word转为rtf convertapi.convertdocument(name, format, password, folder, storage, destfilepath); } } }
using system; using spire.cloud.word.sdk.client; using spire.cloud.word.sdk.api; namespace docxtodoc { class program { static string appid = "app id"; static string appkey = "app key"; static void main(string[] args) { //配置app id和app key configuration configuration = new configuration(appid, appkey); //初始化convertapi对象 convertapi convertapi = new convertapi(configuration); string name = "sample.docx"; //源文档 string format = "doc";//转换的目标文档格式 string password = null;//源文档密码 string folder = "input";//源文档的文件夹,如果没有文件夹则为null string storage = null;//使用冰蓝云配置的2g空间存贮文档,可设置为null string destfilepath = "output/docxtodoc.doc";//结果文档路径及名称(结果文档保存在output文件夹下) //调用方法将docx转为doc convertapi.convertdocument(name, format, password, folder, storage, destfilepath); } } }
(本文完)
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论