Recently, I meet a problem that I need to insert header and footer in excel with C#, I use the following code:

        Worksheet sheet = workbook.Worksheets[0];
        sheet.PageSetup.FullHeaderString = "E-iceblue";
        sheet.PageSetup.IsPrintHeadings = true;
        sheet.Visibility = WorksheetVisibility.Visible;

        sheet.PageSetup.LeftFooter = "everlasting";

But when I launch it, the header and footer do not appear in the excel table, after I click insert header and footer button, it shows, When I put it in a view and print it out, it shows header and footer.What is the problem?

Can anybody help me?
I use the OS and Spire.XLS.

Dani AI

Generated

Short answer: this is normal Excel behavior — headers and footers exist in the file but are not shown in Excel's Normal worksheet view. As suggested, the values set by code will be visible in Page Layout or Print Preview; that matches 's observation that the header/footer appear after clicking Insert Header & Footer or when printing.

Clarification and common gotchas: "Print headings" (the IsPrintHeadings flag) controls whether row/column labels (A,B,1,2) are printed — it does not affect the header/footer area. Libraries expose several ways to set header/footer (individual Left/Center/Right header/footer properties, or a single full header string that may use the &L, &C, &R placeholders). If a full header string is used, confirm the placement codes are present so text goes to the expected slot.

Quick troubleshooting checklist:

  • Save the generated workbook and re-open it in Excel to ensure the library actually persisted the values.
  • In Excel, switch to View → Page Layout or open Print Preview; the header/footer should be visible there.
  • Inspect Page Setup in Excel to confirm the sheet has header/footer text and reasonable top margins (very small/negative top margins can hide headers on print).
  • Remember that on-screen Normal view will not show header/footer; if an always-visible on-sheet header is required, emulate one by inserting a frozen top row (merged cells) as a visual header.

Final note: this is an Excel UI/behavior issue rather than a Spire bug. Forcing Excel to open in Page Layout programmatically requires launching Excel (Office Interop) on the client and changing the active window view; for server-side generation, saving correctly and verifying in Page Layout/Print Preview is the usual approach.

Recommended Answers

All 2 Replies

Perhaps your excel is not set to display the header & footer even though they are there?

That possibility is very small.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.