lazyzu.ClosedXML.Extension.EmbeddedObject
0.0.3
.NET Standard 2.1
This package targets .NET Standard 2.1. The package is compatible with this framework or higher.
.NET Framework 4.5.2
This package targets .NET Framework 4.5.2. The package is compatible with this framework or higher.
dotnet add package lazyzu.ClosedXML.Extension.EmbeddedObject --version 0.0.3
NuGet\Install-Package lazyzu.ClosedXML.Extension.EmbeddedObject -Version 0.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="lazyzu.ClosedXML.Extension.EmbeddedObject" Version="0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add lazyzu.ClosedXML.Extension.EmbeddedObject --version 0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: lazyzu.ClosedXML.Extension.EmbeddedObject, 0.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install lazyzu.ClosedXML.Extension.EmbeddedObject as a Cake Addin #addin nuget:?package=lazyzu.ClosedXML.Extension.EmbeddedObject&version=0.0.3 // Install lazyzu.ClosedXML.Extension.EmbeddedObject as a Cake Tool #tool nuget:?package=lazyzu.ClosedXML.Extension.EmbeddedObject&version=0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
About ClosedXML.Extension.EmbeddedObject:
ClosedXML.Extension.EmbeddedObject
is a .NET library for embedding OLE objects when using ClosedXML
And currently, it only supports embedding and does not support reading, updating, or deleting actions.
[!NOTE] Supports ClosedXML versions 0.96.0 and later, except for 0.103.x and 0.104.x due to the not strongly named issue.
Using ClosedXML.Extension.EmbeddedObject:
- Basic usage
public void AddTxtOleObject()
{
var outputTargetPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "AddTxtOleObject.xlsx");
var targetOleContentFilePath = Template.Sample("sample.txt");
var workbook = new XLWorkbook();
var helloOleWorksheet = workbook.Worksheets.Add("sampleTxt");
// 1. Load Object Sote
var helloOleWorksheetEmbeddedObjectStroe = helloOleWorksheet.GetEmbeddedObjectStore();
// 2. Record the information of the object to be embedded in Store
helloOleWorksheetEmbeddedObjectStroe.Add(new EmbeddedObjectInfo
{
OleObject = new StreamOleObjectInfo(new FileStream(targetOleContentFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), targetOleContentFilePath),
Icon = IconSet.Txt.GetIconInfo(),
Dimension = DimensionInfo.FromCell(helloOleWorksheet.Cell($"A1"))
});
// 3. Write the embedded object when saving the workbook
workbook.SaveAsWithEmbeddedObjectGenerate(outputTargetPath);
}
OleObject
can implementIOleObjectInfo
for customization, such as the implementation ofStreamOleObjectInfo
as follows:
public class StreamOleObjectInfo : IOleObjectInfo
{
public string FileName { get; private init; }
public string FilePath { get; private init; }
public string TemporaryPath { get; private init; }
private readonly Stream stream;
public StreamOleObjectInfo(Stream stream, string filePath, string fileName = null)
{
this.stream = stream;
this.FilePath = filePath;
this.FileName = fileName;
if (this.FileName == null)
{
var sourceFilePurePath = PathLib.PurePath.Create(filePath);
this.FileName = sourceFilePurePath.Filename;
}
this.TemporaryPath = this.FileName;
}
public bool IsContentStreamValid()
{
if(this.stream == null || this.stream.Length == 0) return false;
return true;
}
public Stream ContentStreamGetter()
{
this.stream.Position = 0;
return this.stream;
}
}
- The rendering position can be customized by implementing
IDimensionInfo
. Currently, three rendering methods are supported: FromCell, FromCellCenter, and FromRange. The implementation ofXLRangeDimensionInfo
is as follows:
// Default supported rendering methods
DimensionInfo.FromCell(helloOleWorksheet.Cell($"A1"))
DimensionInfo.FromCellCenter(helloOleWorksheet.Cell($"A3"))
DimensionInfo.FromRange( helloOleWorksheet.Range($"A5", $"A7"))
public class XLRangeDimensionInfo : IDimensionInfo
{
public IXLRange TargetRange { get; private init; }
public XLRangeDimensionInfo(IXLRange range)
{
if (range == null) throw new ArgumentNullException(nameof(range));
this.TargetRange = range;
var firstCell = this.TargetRange.FirstCell();
this.Column = firstCell.Address.ColumnNumber - 1; // 1 Base TO 0 Base
this.Row = firstCell.Address.RowNumber - 1; // 1 Base TO 0 Base
var lastCell = this.TargetRange.LastCell();
this.ColumnCountWidth = lastCell.Address.ColumnNumber - firstCell.Address.ColumnNumber + 1;
this.RowCountHeight = lastCell.Address.RowNumber - firstCell.Address.RowNumber + 1;
}
public int Column { get; private init; }
public int Row { get; private init; }
public int ColumnCountWidth { get; private init; }
public int RowCountHeight { get; private init; }
public long ColumnFromOffset => 0;
public long ColumnToOffset => 0;
}
- Icon can initialize an
IconInfo
object to customize settings, as shown in the following example.
new EmbeddedObjectInfo.IconInfo
{
ImageContentType = "image/x-emf",
ImageStreamGetter = getEmbeddedResourceIcon("text.emf")
};
private static Stream getEmbeddedResourceIcon(string fileName)
{
return _assembly.Value.GetManifestResourceStream($"{_namespace.Value}.{fileName}");
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
0.0.3 | 127 | 3/13/2025 | |
0.0.2 | 207 | 3/13/2025 | |
0.0.2-hotfix1 | 205 | 3/13/2025 | |
0.0.1 | 223 | 3/12/2025 |