Set Excel Print Title

In this guide, we will walk you through how to set print titles in an Excel spreadsheet using Aspose.Cells for .NET. Follow the steps below to accomplish this task.

Step 1: Setting up the environment

Make sure you have set up your development environment and installed Aspose.Cells for .NET. You can download the latest version of the library from Aspose official website.

Step 2: Import required namespaces

In your C# project, import the necessary namespaces to work with Aspose.Cells:

using Aspose.Cells;

Step 3: Setting the path to the documents directory

Declare a dataDir variable to specify the path to the directory where you want to save the generated Excel file:

string dataDir = "YOUR_DIRECTORY_OF_DOCUMENTS";

Be sure to replace "YOUR_DOCUMENT_DIRECTORY" with the correct path on your system.

Step 4: Creating a Workbook Object

Instantiate a Workbook object that represents the Excel workbook you want to create:

Workbook workbook = new Workbook();

Step 5: Access to the first worksheet

Navigate to the first worksheet in the Excel workbook using the following code:

Worksheet worksheet = workbook.Worksheets[0];

Step 6: Defining Title Columns

Define the title columns using the following code:

pageSetup.PrintTitleColumns = "$A:$B";

Here we have defined columns A and B as title columns. You can adjust this value according to your needs.

Step 7: Defining Title Lines

Define the title lines using the following code:

pageSetup.PrintTitleRows = "$1:$2";

We have defined rows 1 and 2 as title rows. You can adjust these values according to your needs.

Step 8: Saving the Excel workbook

To save the Excel workbook with the print titles defined, use the Save method of the Workbook object:

workbook.Save(dataDir + "SetPrintTitle_out.xls");

This will save the Excel workbook with file name “SetPrintTitle_out.xls” in the specified directory.

Sample source code for Set Excel Print Title using Aspose.Cells for .NET

// The path to the documents directory.
string dataDir = "YOUR DOCUMENT DIRECTORY";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the PageSetup of the worksheet
Aspose.Cells.PageSetup pageSetup = workbook.Worksheets[0].PageSetup;
// Defining column numbers A & B as title columns
pageSetup.PrintTitleColumns = "$A:$B";
// Defining row numbers 1 & 2 as title rows
pageSetup.PrintTitleRows = "$1:$2";
// Save the workbook.
workbook.Save(dataDir + "SetPrintTitle_out.xls");

Conclusion

Congratulation ! You have learned how to set print titles in an Excel spreadsheet using Aspose.Cells for .NET. Print titles allow you to display specific rows and columns on each printed page, making data easier to read and reference.

FAQs

1. Can I set print titles for specific columns in Excel?

Yes, with Aspose.Cells for .NET you can set specific columns as print titles using the PrintTitleColumns property of the PageSetup object.

2. Is it possible to define both column and print row titles?

Yes, you can set both print column and row titles using the PrintTitleColumns and PrintTitleRows properties of the PageSetup object.

3. What other layout settings can I customize with Aspose.Cells for .NET?

With Aspose.Cells for .NET, you can customize various page layout settings, such as margins, page orientation, print scale, and more.