這篇文章主要為大家詳細(xì)介紹了調(diào)用shapesApi接口操作Word形狀的方法,圖文詳解容易學(xué)習(xí),非常適合初學(xué)者入門,感興趣的小伙伴們可以參考一下。
步驟一:dll文件獲取及導(dǎo)入。通過(guò)官網(wǎng)本地下載SDK文件包。(須在e-iceblue中國(guó)官網(wǎng)在線編輯板塊中注冊(cè)賬號(hào)并登錄)
下載后,解壓文件,將Spire.Cloud.Word.Sdk.dll文件及其他三個(gè)dll添加引用至VS程序;或者在程序中通過(guò)Nuget搜索下載,直接導(dǎo)入所有dll。dll引用結(jié)果如下圖所示:
步驟二:App ID及Key獲取。在“我的應(yīng)用”板塊中創(chuàng)建應(yīng)用以獲得App ID及App Key。
步驟三:源文檔上傳。在“文檔管理”板塊,上傳源文檔。這里可以建文件夾,將文檔存放在文件夾下。不建文件夾時(shí),源文檔及結(jié)果文檔直接保存在根目錄。本文示例中,建了兩個(gè)文件夾,分別用于存放源文檔及結(jié)果文檔。(云平臺(tái)提供免費(fèi)1 萬(wàn)次調(diào)用次數(shù)和 2G 文檔內(nèi)存)
C# 代碼示例
1. 添加形狀到Word
using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Model;
namespace AddShape
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static void Main(string[] args)
{
//配置AppID和AppKey
Configuration wordConfiguration = new Configuration(appId, appKey);
//實(shí)例化ShapesApi類
ShapesApi shapesApi = new ShapesApi(wordConfiguration);
string name = "test.docx";//源文檔
string paragraphPath = "sections/0/paragraphs/0";//段落路徑
int indexInParagraph = 1;//添加形狀的段落
string folder = "input";//源文檔所在文件夾
string storage = null;//使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null
string password = null;//源文檔密碼
//設(shè)置形狀屬性(包括形狀類型、位置、填充顏色、旋轉(zhuǎn)方向、邊框?qū)挾?顏色、文本環(huán)繞類型/方式
ShapeFormat shapeProperties = new ShapeFormat(50, 50, ShapeFormat.ShapeTypeEnum.Star)
{
HorizontalOrigin = ShapeFormat.HorizontalOriginEnum.Page,
VerticalOrigin = ShapeFormat.VerticalOriginEnum.Page,
VerticalPosition = 40,
HorizontalPosition = 230,
FillColor = new Color(255, 69, 0),
Rotation = 45,
StrokeWeight = 2,
StrokeColor = new Color(255, 255, 0),
TextWrappingType = ShapeFormat.TextWrappingTypeEnum.Both,
TextWrappingStyle = ShapeFormat.TextWrappingStyleEnum.InFrontOfText,
ZOrder = 1
};
string destFilePath = "output/AddShape.docx";//結(jié)果文檔路徑
//調(diào)用方法添加形狀
shapesApi.AddShape(name, paragraphPath, shapeProperties, folder, storage, indexInParagraph, password, destFilePath);
}
}
}
形狀添加效果:
2. 刪除Word中的形狀
using System;
using Spire.Cloud.Word.Sdk.Api;
using Spire.Cloud.Word.Sdk.Client;
namespace DeleteShape
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static void Main(string[] args)
{
//配置AppID和AppKey
Configuration wordConfiguration = new Configuration(appId, appKey);
//實(shí)例化ShapesApi類
ShapesApi shapesApi = new ShapesApi(wordConfiguration);
string name = "AddShape.docx";//源文檔
string paragraphPath = "sections/0/paragraphs/0";//段落路徑
int index = 0;//要?jiǎng)h除形狀的索引
string folder = "output";//源文檔所在文件夾
string storage = null;//使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null
string password = null;//源文檔密碼
string destFilePath = "output/DeleteShape.docx";//結(jié)果文檔路徑
//調(diào)用方法刪除形狀
shapesApi.DeleteShape(name, paragraphPath, index, folder, storage, password, destFilePath);
}
}
}
形狀刪除效果:
3. 讀取Word形狀屬性
using System;
using Spire.Cloud.Word.Sdk.Client;
using Spire.Cloud.Word.Sdk.Api;
namespace GetShapeProperties
{
class Program
{
static string appId = "App ID";
static string appKey = "App Key";
static void Main(string[] args)
{
//配置AppID和AppKey
Configuration wordConfiguration = new Configuration(appId, appKey);
//實(shí)例化ShapesApi類
ShapesApi shapesApi = new ShapesApi(wordConfiguration);
string name = "AddShape.docx";//源文檔
string paragraphPath = "sections/0/paragraphs/0";
int index = 0;//讀取的形狀索引
string folder = "output";//源文檔所在文件夾
string storage = null;//使用冰藍(lán)云配置的2G空間存貯文檔,可設(shè)置為null
string password = null;//源文檔密碼
//讀取屬性
System.Console.WriteLine(shapesApi.GetShapeProperties(name, paragraphPath, index, folder, storage, password));
System.Console.ReadLine();
}
}
}
屬性讀取結(jié)果:
以上就是調(diào)用shapesApi接口操作Word形狀方法的詳細(xì)介紹,看完之后是否有所收獲呢?如果想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊!
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
分享標(biāo)題:如何調(diào)用shapesApi接口操作Word形狀-創(chuàng)新互聯(lián)
分享URL:http://www.rwnh.cn/article24/dcejce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁(yè)設(shè)計(jì)公司、品牌網(wǎng)站制作、網(wǎng)站營(yíng)銷、外貿(mào)網(wǎng)站建設(shè)、用戶體驗(yàn)、靜態(tài)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容