Add / copy excel sheet formatting

I’m creating a template excel file and then copying the template sheet to build reports. It’s working ok, but i have two problems;

1) The footer margin isn’t being copied correctly and
2) The custom header image isn’t being copied along with the rest of the sheet.
Can you take a look at this?

thanks,
Dave

Hi Dave,

About 1), please try the attached fix.

About 2), currently Aspose.Excel doesn’t support this feature.

Laurence wrote:
Hi Dave,

About 2), currently Aspose.Excel doesn't support this feature.


How would I populate the middle section of the header with an image using aspose code?

thanks,
David

You can only put the image in your template and use Excel.Open method to import it.

Laurence wrote:
You can only put the image in your template and use Excel.Open method to import it.


Isn't this all kind of circuitious? If the image is in the template sheet and I do an add/copy everything in the template sheet should appear in the new sheet.

Image header/footer is a new feature since ExcelXP. Now Aspose.Excel can only load it in a template but cannot copy them or add them at run time.

I will check this issue. But it may take a relatively long time for it is complex.

@ydb1md,
Aspose.Cells has replaced Aspose.Excel that is no more under active development now. This new product Aspose.Cells supports all the latest features in different versions of MS Excel including the insertion of images in header and footer. You may refer to the following sample code that demonstrates the insertion of images in header and copies them also to other sheets.

// Creating a Workbook object
Workbook workbook = new Workbook();

workbook.Worksheets[0].Cells["A1"].Value = "Test Data";
// Creating a string variable to store the url of the logo/picture
string logo_url = @"aspose-logo.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");

pageSetup.FooterMargin = 3;
pageSetup.SetFooter(1, "&\"Times New Roman,Bold\"&D-&T");

workbook.Worksheets.AddCopy(0);

// Saving the workbook
workbook.Save("InsertImageInHeaderFooter_out.xls");

//Closing the FileStream object
inFile.Close();

Refer to the following article for more information about working with header and footer.
Setting Headers and Footers

The free trial version of this new product can be downloaded here:
Aspose.Cells for .NET(Latest version)

You may download a runnable solution here for testing different functions of this new product.