Word格式处理控件Aspose.Words for .NET教程——使用Ole对象和在线视频

Aspose.Words for .NET是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

>>Aspose.Words for .NET已经更新至最新版,Font.EmphasisMark向公众公开,引入了MarkdownSaveOptions类,PDF版本1.5标记为过时,点击下载体验


插入对象

如果要Ole Object调用 DocumentBuilder.InsertOleObject。将ProgId与其他参数一起显式传递给此方法。下例显示了如何将Ole Object插入文档。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertOleObject("http://www.aspose.com", "htmlfile", true, true, null);
dataDir = dataDir + "DocumentBuilderInsertOleObject_out.doc";
doc.Save(dataDir);

插入对象时设置文件名和扩展名

如果OLE处理程序未知,则OLE包是用于存储嵌入式对象的旧式“未记录”方式。Windows 3.1、95和98等早期Windows版本具有Packager.exe应用程序,该应用程序可用于将任何类型的数据嵌入到文档中。现在,此应用程序已从Windows排除在外,但是如果OLE处理程序丢失或未知,MS Word和其他应用程序仍将其用于嵌入数据。OlePackage类允许访问OLE包属性。下面的示例演示如何设置OLE包的文件名,扩展名和显示名。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
byte[] bs = File.ReadAllBytes(dataDir + @"input.zip");
using (Stream stream = new MemoryStream(bs))
{
    Shape shape = builder.InsertOleObject(stream, "Package", true, null);
    OlePackage olePackage = shape.OleFormat.OlePackage;
    olePackage.FileName = "filename.zip";
    olePackage.DisplayName = "displayname.zip";
    dataDir = dataDir + "DocumentBuilderInsertOleObjectOlePackage_out.doc";
    doc.Save(dataDir);
}

获取对OLE对象原始数据的访问

下面的代码示例演示如何使用OleFormat.GetRawData()方法获取OLE对象原始数据 。

// Load document with OLE object.
Document doc = new Document(dataDir + "DocumentBuilderInsertTextInputFormField_out.doc");
            
Shape oleShape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
byte[] oleRawData = oleShape.OleFormat.GetRawData();

插入在线视频

可以从“插入”选项卡>“在线视频”将在线视频插入MS Word。您可以通过调用DocumentBuilder.InsertOnlineVideo 方法将在线视频插入当前位置的 文档中。DocumentBuilder类中引入了此方法的四个重载。第一个使用最受欢迎的视频资源,并将视频的URL作为参数。

//The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithOnlineVideo();

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Pass direct url from youtu.be.
string url = "https://youtu.be/t_1LYZ102RA";

double width = 360;
double height = 270;

Shape shape = builder.InsertOnlineVideo(url, width, height);

dataDir = dataDir + "Insert.OnlineVideo_out_.docx";
doc.Save(dataDir);

第二次重载可与所有其他视频资源一起使用,并将嵌入的HTML代码作为参数:

//The path to the documents directory.
string dataDir = RunExamples.GetDataDir_WorkingWithOnlineVideo();

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Shape width/height.
double width = 360;
double height = 270;

// Poster frame image.
byte[] imageBytes = File.ReadAllBytes("TestImage.jpg");

// Visible url
string vimeoVideoUrl = @"https://vimeo.com/52477838";

// Embed Html code.
string vimeoEmbedCode = "";

builder.InsertOnlineVideo(vimeoVideoUrl, vimeoEmbedCode, imageBytes, width, height);

dataDir = dataDir + "Insert.OnlineVideo_out_.docx";
doc.Save(dataDir);
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值