New ImagePart is created as .bin instead of real extension
See original GitHub issueDescribe the bug I have asked the question on Stackoverflow: https://stackoverflow.com/questions/75100804/embedding-image-as-new-imagepart-creates-a-bin-file-using-open-xml-sdk
I don’t expect to get any answer there, and I am also increasingly curious whether, this is an implementation error but an issue in the SDK.
Issue is, I create new embedded image in Excel and it is saved to /xl/media/image.[WhatEverExtensionItIs]
If I create a new ImagePart with the SDK and feed it data like this:
ImagePart new_ImagePart = worksheetPart.AddImagePart(ImagePartType.Tiff);
stream.Position = 0;
new_ImagePart.FeedData(stream);
Then the file will be saved as /xl/media/image.bin
.
This behaviour it should not do. It should write the extension as .tiff, since this is the ImagePartType
, that I specify. Or secondly it should read the stream and identify it as .tiff through i.e. a magic number.
If you unzip the package and change the image extension to real extension, then the image will open perfectly and I have used a TIFF validator to confirm the image is well-formed.
What do you think of this? Am I doing anything wrong in my implementation, or can we change the SDK to write real extension like Excel does?
Screenshots If applicable, add screenshots to help explain your problem.
To Reproduce Steps to reproduce the behavior:
- Use the supplied code to stream any TIFF image (or change ImagePartType to any other image type) to a new ImagePart
- Unzip the spreadsheet and go to /xl/media/ to find the file as a .bin
- Change extension to .tiff and the image will open perfectly
Observed behavior ImagePart creates a new image with .bin extension
Expected behavior ImagePart should create a new image with extension based on ImagePartType.
Desktop (please complete the following information):
- OS: Windows 11
- Office version: 2212
- .NET Target: .Net latest version
- DocumentFormat.OpenXml Version: 2.19
Issue Analytics
- State:
- Created 8 months ago
- Comments:13 (8 by maintainers)
+1 can confirm the same issue of a
.bin
in/media/image.bin
using v2.20 when saving a word document:Confirmed fix.