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

Aspose.Words for .NET是一种高级Word文档处理API,用于执行各种文档管理和操作任务。本文将介绍如何使用Ole对象和在线视频相关知识。

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

>>Aspose.Words for .NET已经更新至v20.6,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 urlstring 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);


还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年5月7日
下一篇 2020年5月7日

相关推荐

发表回复

登录后才能评论