Free Support Forum - aspose.com

Insert images in headers

Hi,

Is it possible to insert an image in the header of a worksheet?

For information, i'm running Aspose.Excell v3.6.1.0

Sincerely

Guillaume

No, it’s not supported. You can only insert image in header of a worksheet within your template file. Aspose.Cells doesn’t support to insert it at run time.

hi laurence,

will this feature (i.e., runtime definition / insertion of image in headers) be planned for future versions? or is this technically impossible?

i have the same requirement to embed images in headers but without using Designer Template file, so this feature will help. currently, the alternative is to use PrintTitleRows though the end effect is not ideal.

thanks,

nick

I will make the feature in the future version. It may take about 1-2 months.

hi laurence, thanks.

suggestion: perhaps a simpler and practical approach will be to extend the current header/footer script to accept a path to a physical image file name. this negates the need to handle memorystream object in the script.

for your consideration. thanks,

nick

hi laurence, just wondering if you have any updates on the support for images in headers.

thanks,

nick

We are still working on this feature. Hopefully it can be available in the next week.

laurence – great to hear that. thanks as always!


nick

laurence, just wanted to register my thanks for the image insertion picture to be included in the latest release!

nick

Hi Nick,

You are welcome.

hi laurence,

i was trying to incoroporate the image embedding in header feature and met with the following problem: an exception is thrown when i try the SetHeaderPicture() method:

"Unknow image format:Unsupported image foramt."

the bytes passed in are read from a PNG file stream. similar for image in JPG format. i have attached the image file for your test.

any ideas why?

nick


Hi nick,

Thanks for considering Aspose.

Well I ran the following code with your picture with Aspose.Cells 4.0.3 and it 's perfect. You can see the attachment.

//Creating a Workbook object

Workbook workbook = new Workbook();

//Creating a string variable to store the url of the logo/picture

string logo_url = "d:\\ZTE_Corporate_Logo_Small.jpg";

//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);

//Instantiating the byte array of FileStream object's size

binaryData = new Byte[inFile.Length];

//Reads a block of bytes from the stream and writes data in a given buffer of byte array.

long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);

//Creating a PageSetup object to get the page settings of the first worksheet of the workbook

PageSetup pageSetup = workbook.Worksheets[0].PageSetup;

//Setting the logo/picture in the central section of the page header

pageSetup.SetHeaderPicture(1, binaryData);

//Setting the script for the logo/picture

pageSetup.SetHeader(1, "&G");

//Setting the Sheet's name in the right section of the page header with the script

pageSetup.SetHeader(2,"&A");

//Saving the workbook

workbook.Save("d:\\headerpictest.xls");

//Closing the FileStream object

inFile.Close();

Regards

Amjad Sahi

Aspose Nanjing Team

hi,

thanks for the response – i found the problem. this problem occurs if i passed in a static stream created previously. however, if i create a file name it’s ok.

not sure what caused the other problem, but it’s working now. thanks!

nick