Excel header print setting (repeat header content’s on every page during printing) using C#.Net

Excel header print setting (repeat header content’s on every page during printing) using C#.Net





Hello friend's


When we create excel file from C# there may be need to repeat some part’s when we printing.

See below code bloack to set it from C#.



  Microsoft.Office.Interop.Excel.Application xlApp;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
                object misValue = System.Reflection.Missing.Value;
                Microsoft.Office.Interop.Excel.Range chartRange;
                xlApp = new app.Application();

                xlWorkBook = xlApp.Workbooks.Add(misValue);
                xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);

                xlWorkSheet.PageSetup.PrintTitleRows = "R1:R11";

// Repeat Rows from R1 to R11 for every page

                xlWorkSheet.PageSetup.PaperSize = app.XlPaperSize.xlPaperLegal;

// Printer Page Size.


                xlWorkSheet.PageSetup.Zoom = false;
                xlWorkSheet.PageSetup.FitToPagesWide = 1;
                xlWorkSheet.PageSetup.FitToPagesTall = 4;

//Set Content according to Page Width and Height. This is important factor if you want to Print Proper documents.

                xlWorkSheet.PageSetup.LeftMargin = 0;
                xlWorkSheet.PageSetup.RightMargin = 0;
                xlWorkSheet.PageSetup.TopMargin = 0.25;
                xlWorkSheet.PageSetup.BottomMargin = 0.25;
                xlWorkSheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;


that's sit.

Let  me know if have any problem.

Enjoy !!!!!

Create/Format Excel File From C#.Net

Posted in |

4 comments:

  1. Vladimir Says:

    Thank you!

  2. peterson Says:

    Good one .............

  3. Ketan Patel Says:

    Most welcome Vladimir and peterson...

  4. Sumit Kumar Says:

    Very Informative. I would be helpful for My site project.

Post a Comment