Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to transfer a header to several worksheets?

I create the following header and want to apply it to several worksheets instead of writing the same code for every 16 worksheets. Is there a way to build a method for this and use it for all worksheets?

            // Create Worksheet
            var nf = package.Workbook.Worksheets.Add("Station_1");
            // +15 worksheets...

            // Format Header
            nf.Cells["A1"].Value = "Login";
            nf.Cells["A2"].Value = "Password";
            nf.Cells["A3"].Value = "Date";
            nf.Row(1).Style.Font.Bold = true;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I suppose nf is of type WorkSheet. Add a method FormatHeader(WorkSheet ws) and call it with all your worksheets:

private void FormatHeader(WorkSheet ws)
{
    // Format Header
    ws.Cells["A1"].Value = "Login";
    ws.Cells["A2"].Value = "Password";
    ws.Cells["A3"].Value = "Date";
    ws.Row(1).Style.Font.Bold = true;
}

Call it like this:

FormatHeader(package.Workbook.Worksheets.Add("Station_1"));
FormatHeader(package.Workbook.Worksheets.Add("Station_2"));
...

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading