Skip to content

ES-263025- Add the sample Add-different-document-format-as-OLE-object #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Add-different-document-format-as-OLE-object", "Add-different-document-format-as-OLE-object\Add-different-document-format-as-OLE-object.csproj", "{D3AF529E-DB54-4294-A876-DD42E1E472D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3AF529E-DB54-4294-A876-DD42E1E472D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58137FF9-5AE1-4514-9929-3A8A7DA1DFEB}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Add_different_document_format_as_OLE_object</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Adventure.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\excel.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\pdf.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\powerpoint.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Sample.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Template.pdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\Template.xlsx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\word.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using System.IO;

namespace Add_different_document_format_as_OLE_object
{
class Program
{
static void Main(string[] args)
{
// Create a new Word document.
using (WordDocument document = new WordDocument())
{
// Add a new section to the document.
IWSection section = document.AddSection();

// Add different types of documents as OLE objects.
AddOleObject(document, section, "Data/Template.pdf", "Data/pdf.png", OleObjectType.AdobeAcrobatDocument);
AddOleObject(document, section, "Data/Template.xlsx", "Data/excel.png", OleObjectType.ExcelWorksheet);
AddOleObject(document, section, "Data/Adventure.docx", "Data/word.png", OleObjectType.WordDocument);
AddOleObject(document, section, "Data/Sample.pptx", "Data/powerpoint.png", OleObjectType.PowerPointPresentation);

// Save the Word document to a file.
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
{
document.Save(outputStream, FormatType.Docx);
}
}
}

/// <summary>
/// Adds an OLE object to the Word document.
/// </summary>
private static void AddOleObject(WordDocument document, IWSection section, string filePath, string imagePath, OleObjectType oleType)
{
// Add a new paragraph to the section.
IWParagraph paragraph = section.AddParagraph();

// Open the file to be embedded as an OLE object.
using (FileStream fileStream = new FileStream(Path.GetFullPath(filePath), FileMode.Open))
using (FileStream imageStream = new FileStream(Path.GetFullPath(imagePath), FileMode.Open, FileAccess.ReadWrite))
{
// Load the image as a representation of the OLE object.
WPicture picture = new WPicture(document);
picture.LoadImage(imageStream);

// Append the OLE object to the paragraph.
WOleObject oleObject = paragraph.AppendOleObject(fileStream, picture, oleType);
paragraph.AppendText("\n");

// Set the display size of the OLE object.
oleObject.OlePicture.Height = 80;
oleObject.OlePicture.Width = 100;
}
}
}
}
Loading