We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Can't set size and font in pageHeader

Hello,

I am using Aspose to export Datatables. I want to put a dynamic title on top of the datatable. I managed to add it using Header but I don’t manage to format it.
To begin I just want to set FontSize to 24. But It remains the default size.
Below is my code. Can you help me ?

public void ExportCsvDataTable<T>(HttpResponse response, List<T> datas, TemplateFichierExporteDatatable template)
{
            var donnees = ExportDataTable(datas, template);
            var book = new Workbook();
            var sheet = book.Worksheets[0];

            foreach (var donnee in donnees)
            {
                sheet.Cells.ImportDataTable(donnee, true, 0, 0);
            }

            PageSetup pageSetup = sheet.PageSetup;
            pageSetup.SetHeader(1, template.TitreFichier + "&24");

            var saveOptions = new TxtSaveOptions(Aspose.Cells.SaveFormat.CSV);
            saveOptions.Separator = ';';
            saveOptions.Encoding = new UTF8Encoding(true);

            // Adding Default Style to the table
            book.Save(response, string.Concat(template.NomFichier, " - ", DateTime.Now.ToShortDateString(), ".csv"), ContentDisposition.Attachment, saveOptions);
        }

I found the issue. Seems the doc is wrong.

pageSetup.SetHeader(1, "&24" + template.TitreFichier);

It works by putting the size BEFORE the string content.

Hi,

Yes, the font size should be placed before string content. See the description/text for your reference:
&<FontSize>” —> Represents font size. e.g “&14abc”. But, if this command is followed by a plain number to be printed in the header, this should be separated from the font size with a space character. For example: “&14 123”.

Where you find the doc is wrong?

Here

https://docs.aspose.com/display/cellsnet/Working+with+Headers+and+Footers

//Setting a string at the left footer and changing the font of the footer
pageSetup.SetFooter(0, "Hello World! &\"Courier New\"&14 123");

@KuroTenshi,

Well, the line of code is ok. Here “Hello World!” text will be using the default font with its size but the numeric value “123” will be pasted using font “Courier New” with size “14”.

Hope, this helps a bit.

Thank you. It was not clear. I think it could be interesting to mention this in the doc.

@KuroTenshi,

Thanks for your suggestion.

I have updated the script commands description in the main document accordingly now:
https://docs.aspose.com/display/cellsnet/Setting+Headers+and+Footers#SettingHeadersandFooters-ScriptCommands.

Maybe the example should be precised too :

// Setting a string at the left section of the footer and changing the font
// of the footer
pageSetup.SetFooter(0, “Hello World! &“Courier New”&14 123”);

You should replace the description with this :

// Setting a string at the left section of the footer and changing the font
// of a part of this string (“123”)

@KuroTenshi,

Thanks for your suggestion.

Alright, we will update the relevant example/gist to enhance the comment @ Github repos. soon.

@KuroTenshi

It is completed now. We have modified the comment as per your advice.