SetHeaderPicture crashed

I have used the sample C# code and Aspose.Cells version 4.3.0.3 to set up header from

This article explains how to programmatically insert an image in the header and footer of Excel worksheets by setting the header and footer with script commands using the C# API or .NET Library.

It crashed at pageSetup.SetHeaderPicture(1, binaryData);

Do you have updates for this sample?

Thanks

Charlie

Hi,

Well, the code is fine and it works perfect. Since you are using some older version of Aspose.Cells, Please try the code with latest 4.4. version or attached version (4.4.0.5).

If you still find the problem, please post your image file with sample code here.

Thank you.


It works for the new dll.

I have another question. Can we specify the relative path for image file? It seems to me that it looks for c:\windows….

We have the web application and we can install the image on web server.

//Creating a string variable to store the url of the logo/picture
string logo_url = "c:\\dog.jpg"; // absolute path

//Declaring a FileStream object
FileStream inFile;

//Declaring a byte array
byte[] binaryData;
//Creating the instance of the FileStream object to open the //logo/picture in the stream
inFile = new System.IO.FileStream(logo_url, System.IO.FileMode.Open, System.IO.FileAccess.Read);

Thanks
Charlie

Hi Charlie,

Please refer to the following code for your need:

string path = MapPath("~");
string logo_url = path + @"\images\dog.jpg";
.

.

.

Thank you.

Thanks Amjad!

It works. I modified workbook.Save to

workbook.Save(strExcelFileName, FileFormatType.Default, SaveType.OpenInBrowser, this.Response);

It can be used for ASP.NET.

-Charlie