How to get slash in MS Excel worksheet header string in .NET

Before I adopted Aspose.Cells, I automated Excel. I noticed then that a slash in a string passed to a header or footer segment caused a linefeed in the displayed text. I also found that I could escape that effect by passing a double slash which displayed as a single slash.

Now when I use PageSetup.SetFooter() I see that a slash causes a linefeed but so does a double slash. How can I get a slash into the footer text?

Thanks,
Bill Below

Hi,

Thanks for your posting and using Aspose.Cells.

As a workaround, you should create your header or footer manually using Microsoft Excel and then load your excel file and observe the header or footer strings, then use those strings in your new excel file.

Please see the following code. It reads header sections from existing workbook and prints them. Then it creates a new workbook and assigns those header sections and save it in the pdf format. When you will open the pdf file, you will see that it has the same header as the source excel file.

I have attached the source excel file used in this code, output pdf generated with the code as well as the console output of the code for your reference.

C#

Workbook wb = new Workbook(“sample.xlsx”);

Worksheet ws = wb.Worksheets[0];

string hl = ws.PageSetup.GetHeader(0);
string hc = ws.PageSetup.GetHeader(1);
string hr = ws.PageSetup.GetHeader(2);

//Print left, center and right header section strings
Console.WriteLine("Left: " + hl);
Console.WriteLine("Center: " + hc);
Console.WriteLine("Right: " + hr);

//Now create a new workbook

Workbook w = new Workbook();
Worksheet s = w.Worksheets[0];
s.Cells[“C4”].PutValue(“Welcome to Aspose.Cells!”);

//Set its header
s.PageSetup.SetHeader(0, hl);
s.PageSetup.SetHeader(1, hc);
s.PageSetup.SetHeader(2, hr);

//Print Pdf
w.Save(“output.pdf”);



Console Output
&K00B0F0H-Left\nH-Left\nH-Left
&K92D050H-Center\nH-Center\nH-Center
&KFF0000H-Right\nH-Right\nH-Right