How to extract Header and Footer text from Excel sheet

Hi,

Is it possible to extract text and font color from excel sheet Header/Footer.

Thanks,

Dhivya

Hi Dhivya,


I am assuming you are using .Net version of Aspose.Cells API.
Yes, it is possible to extract the Text and Font Colour from Header / Footer using the following lines of C# code.
var wb = new Workbook(“C:\temp\List_Object.xlsx”);
var ws = wb.Worksheets[0];
var Hscript = ws.PageSetup.GetHeader(1);
var Fscript = ws.PageSetup.GetFooter(1);

After executing, the string variables Hscript / Fscript will contain the command syntax used to set the Middle Section of Header / Footer. Below is an elaboration for this syntax.

&”,”&KYOURTEXT.

Please check the below link for little more detail on the topic.
<a href="Setting font color for header and footer text in .NET

Once you have this command script, you will be able to manipulate it and set again using PageSetup.SetHeader() / SetFooter() Methods. Please check the below link for PageSetup Class Reference Documentation and get knowledge of Header/Footer Sections.
Aspose.Cells - The Powerful Excel Processing API | Aspose API References

Hope it helped, please feel free to write back.

Hi babar.raza,

Thanks for your sample code. I am using .Net version of Aspose. Cells API. I need to extract Footer/Header font color details, but I couldn't find any property to extract Header/Footer font color name and color RGB values. Kindly tell me is there any way to extract font color information from Header/Footer using Aspose.Cells.dll.

Thanks,

Dhivya

Hi Dhivya,


Currently Aspose.Cells for .Net API does not have properties to directly Get or Set Header / Footer objects or their respective Font and Colour Styles (We already have logged it in our Feature List to provide better means in order to Get / Set these attributes). Right now, this API provide methods to extract this information in specialized strings. Please read my last reply again and check Setting Font, Colour and Text for Header or Footer.

Attached is a sample xlsx file having 3 sections for Header and 3 sections for Footer. Each have different contents also some of them have different Font and colour.

Worksheet.PageSetup.GetHeader(int Section) returns a string that may look like “&CCenter Header”. In this string “&C” is a directive that header section is Centre and content of this section is “Center Header”. This string may also look like “&L&K0000FFLeft Header”. Where “&L” indicate the Left header section, “K0000FF” tells that the content of this header section, that is “Left Header” is in BLUE colour. Another example can be “&R&“Arial,Regular”&12&K00FF00Right Header”. This string shows that header section is Right, text font is Arial size 12, text colour is Green and text is “Right Header”. This way you can Get the Header / Footer Object information.

To Set Header / Footer Object’s Font, Text and Colour, you need to formulate such scripts as discussed above and pass them to SetHeader(string Script) / SetFooter(string Script) methods.

Hi babar.raza,

Thanks for your detailed reply. Please inform me once the new property added in Aspose.Cells.dll for .Net API to Get or Set Header/Footer Font and color details directly.

Hi Dhivya,


Sure, we have associated this thread with your Requested Enhancement Ticket. You will get notified automatically, when this feature is available.

Thanks