Free Support Forum - aspose.com

Setheader on Worksheets with type Chart (SheetType.Chart)

Hi,

I'm having difficulties to set a header on a worksheet of the type Chart.
Following shows my code. I iterate over the different sheets, and copy the template header for each one of them. This works fine as long as the sheet is not of type Chart (SheetType.Chart):

foreach(Worksheet ws in originalDoc.Worksheets)
{
for (int i = 0; i < 3; i++)
{
ws.PageSetup.SetHeader(i, overlayDoc.Worksheets[0].PageSetup.GetHeader(i));
Picture pic = overlayDoc.Worksheets[0].PageSetup.GetPicture(true, i);
if (pic != null)
{
byte[] binaryData;
binaryData = pic.Data;
ws.PageSetup.SetHeaderPicture(i, binaryData);
ws.PageSetup.SetHeader(i, "&G");
Picture docpic = ws.PageSetup.GetPicture(true, i);
docpic.Width = pic.Width;
docpic.Height = pic.Height;
}

ws.PageSetup.SetFooter(i, overlayDoc.Worksheets[0].PageSetup.GetFooter(i));
pic = overlayDoc.Worksheets[0].PageSetup.GetPicture(false, i);
if (pic != null)
{
byte[] binaryData;
binaryData = pic.Data;
ws.PageSetup.SetFooterPicture(i, binaryData);
ws.PageSetup.SetFooter(i, "&G");
Picture docpic = ws.PageSetup.GetPicture(false, i);
docpic.Width = pic.Width;
docpic.Height = pic.Height;
}
}
}

Should I be using something else, when encountering a sheet of type Chart?

Thanks for your support.

Hi,

We found the headers/footers are not applied when the sheet type is chart. We will figure it out soon.

We have logged it into our issue tracking system with an issue id: CELLSNET-14384.

Thank you.

Hi,

I think you may try:

If the worksheet is a chart type woksheet, please set the page setup of the chart to apply a simple header (only) as the following code:

workbook.Worksheets[0].Charts[0].PageSetup.SetHeader(0, “Header”);

And we will continue to work on to fix the original issue soon.

Thank you.

Hi,

Please try the attached version.

We have figured your issue out.

Thank you.

Hi,

I could not test the included version, because when the workbook contains charts, I receive an error:

code:

Workbook originalDoc = (Workbook)originalDocObj;

Workbook overlayDoc = (Workbook)overlayDocObj;

foreach(Worksheet ws in originalDoc.Worksheets)

{

for (int i = 0; i < 3; i++)

{

ws.PageSetup.SetHeader(i, overlayDoc.Worksheets[0].PageSetup.GetHeader(i));

Picture pic = overlayDoc.Worksheets[0].PageSetup.GetPicture(true, i);

if (pic != null)

{

byte[] binaryData;

binaryData = pic.Data;

ws.PageSetup.SetHeaderPicture(i, binaryData);

ws.PageSetup.SetHeader(i, "&G");

Picture docpic = ws.PageSetup.GetPicture(true, i);

docpic.Width = pic.Width;

docpic.Height = pic.Height;

}

ws.PageSetup.SetFooter(i, overlayDoc.Worksheets[0].PageSetup.GetFooter(i));

pic = overlayDoc.Worksheets[0].PageSetup.GetPicture(false, i);

if (pic != null)

{

byte[] binaryData;

binaryData = pic.Data;

ws.PageSetup.SetFooterPicture(i, binaryData);

ws.PageSetup.SetFooter(i, "&G");

Picture docpic = ws.PageSetup.GetPicture(false, i);

docpic.Width = pic.Width;

docpic.Height = pic.Height;

}

}

}

On line " ws.PageSetup.SetHeaderPicture(i, binaryData); " the error message is a NullReferenceExcpetion. However none of ws, ws.PageSetup, i or binaryData are equal to 'null'.

To bad I can't trace within the SetHeader procedure to give you more info. Can you take another look at this, please?

Stefaan Verleye

Hi Stefaan,

Yes, we noticed, it works with simple headers / footers for the chart type worksheets. It produces the issue if we insert graphics into header/footer for the chart type worksheet. I have re-opened the issue. We will look into it and get back to you soon.

Thank you.

Hi,
Please try the attached fix, we have fixed your mentioned issue.

Thank you.

Hi,

thanks for the new version. It works now!

Thanks for your fast support!