XLSB does not find picture

When taking a file with a picture (Test.xlsx), opening it in Excel and saving it as Test.xlsb, the code below finds a picture for XLSX but not XLSB.

To reproduce, extract the zip file to c:\temp or similar and run it:

string basePath = @"C:\Temp\Test.";
string xlsxPath = basePath + @"xlsx";
string xlsbPath = basePath + @"xlsb";
XlsFileHandler.PrintImageLinks(xlsxPath);
XlsFileHandler.PrintImageLinks(xlsbPath);

public static void PrintImageLinks(string path)
{
var w = new Workbook(path);
var ws = w.Worksheets[0];
Console.WriteLine(@"Image Links for file " + path);
foreach (var picture in ws.Pictures)
{
if (!string.IsNullOrEmpty(picture.SourceFullName) && !picture.SourceFullName.Equals(@"NULL"))
{
Console.WriteLine(picture.SourceFullName);
}
}
Console.WriteLine(@"-------------------------------");
Console.WriteLine();
}

Hi,


Thanks for your posting and using Aspose.Cells.

Please try the following code, it extracts the picture without any issue. I have also attached the extracted picture with this code for your reference.

C#
Workbook wb = new Workbook(“Test.xlsb”);

Worksheet ws = wb.Worksheets[“Sheet1”];

byte[] bts = ws.Pictures[0].Data;

File.WriteAllBytes(“pic.png”, bts);

Thank you, but this is not what I am looking for.


I am looking for the path name of the file of the picture, not the content. It works in XLSX, it does not work in XLSB.

Hi,


Thanks for using Aspose.Cells.

Picture.SourceFullName only works when Picture.IsLink is true. So, you should keep this thing in mind.

Please also check the following definition of

Picture.SourceFullName Property
Gets or sets the path and name of the source file for the linked image.

public string SourceFullName {get; set;}

Remarks
The default value is an empty string. If SourceFullName is not an empty string, the image is linked. If SourceFullName is not an empty string, but Data is null, then the image is linked and not stored in the file.

I understand.

But why is the isLinked true in one case and false in the other case. THAT is the question. When I simply save one file as another format type in Excel I would expect them to be the same.


Is this a bug in Excel (not very likely) or Aspose?

Can you please more thoroughly look at why IsLinked is reported true in one case and false in the other?

Hi,


Thanks for your posting and using Aspose.Cells.

But why is the isLinked true in one case and false in the other case.

Please provide us the sample code which we could test at our end and observe this point. But, we tested this point with the following code and in both cases, it printed false.

C#
Workbook wb = new Workbook(“Test.xlsx”);
Worksheet ws = wb.Worksheets[0];
Picture pic = ws.Pictures[0];

Console.WriteLine(pic.IsLink);

wb.Save(“output.xlsb”);

wb = new Workbook(“output.xlsb”);
ws = wb.Worksheets[0];
pic = ws.Pictures[0];

Console.WriteLine(pic.IsLink);

Console Output
False
False

The sample code is in the first post. Please read it again.

Without making any changes, if I save the XLSX file in Excel as XLSB and use the above code it gives different results. It shouldn't.

I pasted it for your convenience again, plus the steps to reproduce.

To reproduce, extract the zip file to c:\temp or similar and run it:

string basePath = @"C:\Temp\Test.";
string xlsxPath = basePath + @"xlsx";
string xlsbPath = basePath + @"xlsb";
XlsFileHandler.PrintImageLinks(xlsxPath);
XlsFileHandler.PrintImageLinks(xlsbPath);

public static void PrintImageLinks(string path)
{
var w = new Workbook(path);
var ws = w.Worksheets[0];
Console.WriteLine(@"Image Links for file " + path);
foreach (var picture in ws.Pictures)
{
if (!string.IsNullOrEmpty(picture.SourceFullName) && !picture.SourceFullName.Equals(@"NULL"))
{
Console.WriteLine(picture.SourceFullName);
}
}
Console.WriteLine(@"-------------------------------");
Console.WriteLine();
}

Hi,


Thanks for your posting and using Aspose.Cells.

I have tested your code once again and it gave good results. Please check this code and its comment. (Which is actually your comment)

i.e.

Without making any changes, if I save the XLSX file in Excel as XLSB and use the above code it gives different results. It shouldn’t.

Here is the sample code (please see the highlighted comment) and its console output.

C#
static void Run()
{
//This is the first part of your code
string basePath = @“F:\Download\Test.”;
string xlsxPath = basePath + @“xlsx”;
string xlsbPath = basePath + @“xlsb”;

//This is necessary part, please see this comment
//Comment: Without making any changes, if I save the XLSX file in Excel as XLSB and use the above code it gives different results. It shouldn’t.
Workbook workbook = new Workbook(xlsxPath);
workbook.Save(xlsbPath);

//Call these both give correct results
PrintImageLinks(xlsxPath);
PrintImageLinks(xlsbPath);

}

public static void PrintImageLinks(string path)
{
var w = new Workbook(path);
var ws = w.Worksheets[0];
Console.WriteLine(@“Image Links for file " + path);
foreach (var picture in ws.Pictures)
{
if (!string.IsNullOrEmpty(picture.SourceFullName) && !picture.SourceFullName.Equals(@“NULL”))
{
Console.WriteLine(picture.SourceFullName);
}
}
Console.WriteLine(@”-------------------------------");
Console.WriteLine();
}


Console Output
Aspose.Cells for .NET v17.5.5.0
Image Links for file F:\Download\Test.xlsx
Images\LinkFixer Advanced.bmp
-------------------------------

Image Links for file F:\Download\Test.xlsb
Images\LinkFixer Advanced.bmp
-------------------------------