In our daily work, we may need to copy the contents from one presentation slides to another. This article is aimed to introduce the method of how to copy the content from one paragraph from the source PowerPoint document to the target document by using Spire.Presenation.

Firstly, View the original presentation slide and the target presentation slide.

Copy a paragraph from one presentation slide to another in C#

Step 1: Initialize an instances of Presentation class and load the source document from file

Presentation ppt = new Presentation();
ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 2: Get the text from the first shape on the first slide.

string Text = "";           
IShape shp = ppt.Slides[0].Shapes[0];
Text = ((IAutoShape)shp).TextFrame.Text;

Step 3: Get the first shape on the first slide from the target document file.

Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
IShape destshp = ppt2.Slides[0].Shapes[0];

Step 4: Get text from placeholder.

((IAutoShape)destshp).TextFrame.Text += Text;

Step 5: Save the document to file.

ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);

Effective screenshot after copy the paragraph from the source file:

Copy a paragraph from one presentation slide to another in C#

Full codes:

using Spire.Presentation;
namespace CoppyParagh
{
    class Program
    {
        static void Main(string[] args)
        {

            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

            string Text = "";
            IShape shp = ppt.Slides[0].Shapes[0];
            Text = ((IAutoShape)shp).TextFrame.Text;

            Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
            IShape destshp = ppt2.Slides[0].Shapes[0];
            ((IAutoShape)destshp).TextFrame.Text += Text;

            ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);


        }
    }
}

A navigation button in a PDF document can redirect users from one page to another. For instance, when a navigation button is clicked, we can jump to the next/last page or return to the previous/first page. This article will introduce how to create such a navigation button in PDF using Spire.PDF.

Step 1: Initialize an instance of PdfDocument class and load a PDF document.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Sales Report.pdf");

Step 2: Enable creation of form fields in the document.

doc.AllowCreateForm = true;

Step 3: Get the last page.

PdfPageBase page = doc.Pages[doc.Pages.Count-1];

Step 4: Create a button field and specify the button name, tooltip and border style.

PdfButtonField button = new PdfButtonField(page, "Return to First Page");
button.Bounds = new RectangleF(page.ActualSize.Width/2-50, 400, 100, 20);
button.BorderColor = new PdfRGBColor(Color.AliceBlue);
button.BorderStyle = PdfBorderStyle.Solid;
button.ToolTip = "First Page";
button.Font = new PdfFont(PdfFontFamily.Helvetica, 7f,PdfFontStyle.Bold);

Step 5: Create a PdfNamedAction that goes to the named destination (previous, next, first or last page) and add the action to the button field.

PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.FirstPage);
button.Actions.GotFocus = namedAction;

Step 6: Add the button to the document.

doc.Form.Fields.Add(button);
doc.SaveToFile("NavigationButton.pdf", FileFormat.PDF);

Output:

How to Create Navigation Buttons in PDF in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Actions;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;
using System.Drawing;

namespace NavigationButtons
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Sales Report.pdf");
            doc.AllowCreateForm = true;
            PdfPageBase page = doc.Pages[doc.Pages.Count - 1];

            PdfButtonField button = new PdfButtonField(page, "Return to First Page");
            button.Bounds = new RectangleF(page.ActualSize.Width / 2 - 50, 400, 100, 20);
            button.BorderColor = new PdfRGBColor(Color.AliceBlue);
            button.BorderStyle = PdfBorderStyle.Solid;
            button.ToolTip = "First Page";
            button.Font = new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Bold);

            PdfNamedAction namedAction = new PdfNamedAction(PdfActionDestination.FirstPage);
            button.Actions.GotFocus = namedAction;

            doc.Form.Fields.Add(button);
            doc.SaveToFile("NavigationButton.pdf", FileFormat.PDF);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Actions
Imports Spire.Pdf.Fields
Imports Spire.Pdf.Graphics
Imports System.Drawing

Namespace NavigationButtons
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("C:\Users\Administrator\Desktop\Sales Report.pdf")
			doc.AllowCreateForm = True
			Dim page As PdfPageBase = doc.Pages(doc.Pages.Count - 1)

			Dim button As New PdfButtonField(page, "Return to First Page")
			button.Bounds = New RectangleF(page.ActualSize.Width / 2 - 50, 400, 100, 20)
			button.BorderColor = New PdfRGBColor(Color.AliceBlue)
			button.BorderStyle = PdfBorderStyle.Solid
			button.ToolTip = "First Page"
			button.Font = New PdfFont(PdfFontFamily.Helvetica, 7F, PdfFontStyle.Bold)

			Dim namedAction As New PdfNamedAction(PdfActionDestination.FirstPage)
			button.Actions.GotFocus = namedAction

			doc.Form.Fields.Add(button)
			doc.SaveToFile("NavigationButton.pdf", FileFormat.PDF)
		End Sub
	End Class
End Namespace

C#: Get Worksheet Names in Excel

2025-04-02 02:12:00 Written by Koohji

In Excel, the worksheet names can serve as a form of metadata about the workbook's contents. By retrieving a list of these names, it is possible to have a rough understanding of what each worksheet is used for and provide an overview of where a certain type of data is stored. This is particularly useful for larger workbooks or when collaborating with others. In this article, you will learn how to get sheet names in Excel in C# using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Get All Worksheet Names in Excel in C#

The Worksheet.Name property returns the name of a Worksheet. To retrieve the names of all the worksheets in Excel (including hidden ones), you can iterate through each worksheet and use this property to get their names. The detailed steps are as follows:

  • Create a Workbook object.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get all the worksheets in the Excel workbook through Workbook.Worksheets property.
  • Iterate through each worksheet.
  • Get the name of each worksheet through Worksheet.Name property and then output the results.
  • C#
using Spire.Xls;
using Spire.Xls.Collections;

namespace WorksheetName
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook workbook = new Workbook();

            // Load an Excel document
            workbook.LoadFromFile("Budget.xlsx");

            // Get all the worksheets in Excel
            WorksheetsCollection worksheets = workbook.Worksheets;

            // Iterate through each worksheet 
            foreach (Worksheet sheet in worksheets)
            {
                // Get worksheet name               
                Console.WriteLine(sheet.Name);
            }
        }
    }
}

Get the names of all worksheet in an Excel document

Get Hidden Worksheet Names in Excel in C#

If you only need to retrieve the names of the hidden worksheets, you can first iterate through each worksheet to determine whether a worksheet is hidden, and if so, get its name through the Worksheet.Name property. The detailed steps are as follows:

  • Create a Workbook object.
  • Load an Excel file using Workbook.LoadFromFile() method.
  • Get all the worksheets in the Excel workbook through Workbook.Worksheets property.
  • Iterate through each worksheet and find the hidden worksheets.
  • Get the names of the hidden worksheets through Worksheet.Name property and then output the results.
  • C#
using Spire.Xls;
using Spire.Xls.Collections;

namespace HiddenSheetsName
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook workbook = new Workbook();

            // Load an Excel document
            workbook.LoadFromFile("E:\\PythonExcel\\Monthly company budget.xlsx");

            // Get all the worksheets in Excel
            WorksheetsCollection worksheets = workbook.Worksheets;

            // Iterate through each worksheet
            foreach (Worksheet sheet in worksheets)
            {
                // Detect the hidden worksheet
                if (sheet.Visibility == WorksheetVisibility.Hidden)
                {
                    // Get the hidden worksheet name
                    Console.WriteLine(sheet.Name);
                }
            }
        }
    }
}

Get the names of the hidden worksheets in an Excel document

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

Replacing image with text or image in a Word document is possible in Spire.Doc. We've already illustrated how to replace image with text, in this tutorial, we will show you how to replace a specified image with another image using Spire.Doc and C#.

Below is the original Word document before replacing image:

Replace Image with new Image in Word using C#

Code Snippet:

Step 1: Load the Word document.

Document document = new Document("Input.docx");

Step 2: Replace the image which title is "Figure 1" with new image.

//Loop through the paragraphs of the section
foreach (Paragraph paragraph in document.Sections[0].Paragraphs)
{
    //Loop through the child elements of paragraph
    foreach (DocumentObject docObj in paragraph.ChildObjects)
    {
        if (docObj.DocumentObjectType == DocumentObjectType.Picture)
        {
            DocPicture picture = docObj as DocPicture;
            if (picture.Title == "Figure 1")
            {
                //Replace the image
                picture.LoadImage(Image.FromFile("PinkRoses.jpg"));
            }
        }
    }
}

Step 3: Save and close the document.

document.SaveToFile("ReplaceImage.docx");
document.Close();

The resultant document looks as follows:

Replace Image with new Image in Word using C#

Full code:

using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace Replace_Image
{
    class Program
    {        
        static void Main(string[] args)
        {
            //Load the Word document
            Document document = new Document("Input.docx");

            //Loop through the paragraphs of the section
            foreach (Paragraph paragraph in document.Sections[0].Paragraphs)
            {
                //Loop through the child elements of paragraph
                foreach (DocumentObject docObj in paragraph.ChildObjects)
                {
                    if (docObj.DocumentObjectType == DocumentObjectType.Picture)
                    {
                        DocPicture picture = docObj as DocPicture;
                        if (picture.Title == "Figure 1")
                        {
                            //Replace the image
                            picture.LoadImage(Image.FromFile("PinkRoses.jpg"));
                        }
                    }
                }
            }

            //Save and close the document
            document.SaveToFile("ReplaceImage.docx");
            document.Close();            
        }
    }
}

By using Spire.Presentation for .NET, developers can easily modify the texts on the presentation slides. In this topic, we are going to demonstrate how to use Spire.Presentation to replace the specific texts in a placeholder in C#.

Firstly, view the original sample document that the text "Spire.Presentation for .NET" will be replaced later.

Text replacement on the presentation slides

Step 1: Create an instance of Dictionary<string,string> and add an item for the instance.

Dictionary<string, string> TagValues = new Dictionary<string, string>();
TagValues.Add("Spire.Presentation for .NET", "Spire.PPT");

Step 2: Create a presentation instance and load the document from file.

Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

Step 3: Call ReplaceTags event to replace all the texts on the first slide.

ReplaceTags(presentation.Slides[0], TagValues);

Step 4: Save the document to file and lance to process it.

presentation.SaveToFile("Result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("Result.pptx");

The following ReplaceTags() method shows how to replace the text on the first presentation slide:

public void ReplaceTags(Spire.Presentation.ISlide pSlide, Dictionary<string, string> TagValues)
{
    foreach (IShape curShape in pSlide.Shapes)
    {
        if (curShape is IAutoShape)
        {
            foreach (TextParagraph tp in (curShape as IAutoShape).TextFrame.Paragraphs)
            {
                foreach (var curKey in TagValues.Keys)
                {
                    if (tp.Text.Contains(curKey))
                    {
                        tp.Text = tp.Text.Replace(curKey, TagValues[curKey]);
                    }
                }
            }
        }
    }
}

Effective screenshot after the replacing the text on the presentation slide:

Text replacement on the presentation slides

Full codes of how to replace the text on the presentation slides:

public ReplaceText()
{
    {
        Dictionary<string, string> TagValues = new Dictionary<string, string>();
        TagValues.Add("Spire.Presentation for .NET", "Spire.PPT");

        Presentation presentation = new Presentation();

        presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

        ReplaceTags(presentation.Slides[0], TagValues);

        presentation.SaveToFile("Result.pptx", FileFormat.Pptx2010);
        System.Diagnostics.Process.Start("Result.pptx");
    }
}
public void ReplaceTags(Spire.Presentation.ISlide pSlide, Dictionary<string, string> TagValues)
{
    foreach (IShape curShape in pSlide.Shapes)
    {
        if (curShape is IAutoShape)
        {
            foreach (TextParagraph tp in (curShape as IAutoShape).TextFrame.Paragraphs)
            {
                foreach (var curKey in TagValues.Keys)
                {
                    if (tp.Text.Contains(curKey))
                    {
                        tp.Text = tp.Text.Replace(curKey, TagValues[curKey]);
                    }
                }
            }
        }
    }
}

Adding print button to PDF document is possible in Spire.PDF, when the button is clicked, the print dialog will be opened. In this tutorial, I'm going to show you how to add a print button to an existing pdf document using Spire.PDF.

To accomplish the task, first you need to create an instance of the PdfButtonField class. This class also allows you to define the appearance of the button. For instance, you can set text, color of text, background color, border color etc. of the button. Second you need to add the print action to the button by calling the AddPrintAction() method. At last, add the button to the document and save the document to file. The following code example explains the same.

Code snippets:

Step 1: Load the PDF document and enable form creation.

PdfDocument doc = new PdfDocument("Input.pdf");
doc.AllowCreateForm = true;

Step 2: Get the first page.

PdfPageBase page = doc.Pages[0];

Step 3: Create a PdfButtonField instance and set properties for the button.

PdfButtonField button = new PdfButtonField(page, "Print");
button.Bounds = new RectangleF(280, 600, 50, 20);
button.BorderColor = new PdfRGBColor(Color.AliceBlue);
button.BorderStyle = PdfBorderStyle.Solid;
button.ForeColor = new PdfRGBColor(Color.White);
button.BackColor = new PdfRGBColor(Color.Blue);
button.ToolTip = "Print";
button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);

Step 4: Add print action to the button.

button.AddPrintAction();

Step 5: Add the button to the document.

doc.Form.Fields.Add(button);

Step 6: Save the document.

doc.SaveToFile("Output.pdf");

The resultant document looks as follows:

Add a Print Button to a PDF Document in C#

Full code:

using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Graphics;

namespace Add_print_button
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the PDF document
            PdfDocument doc = new PdfDocument("Input.pdf");
            //Enable form creation
            doc.AllowCreateForm = true;
            //Get the first page
            PdfPageBase page = doc.Pages[0];

            //Create a PdfButtonField instance
            PdfButtonField button = new PdfButtonField(page, "Print");
            //Set button properties
            button.Bounds = new RectangleF(280, 600, 50, 20);
            button.BorderColor = new PdfRGBColor(Color.AliceBlue);
            button.BorderStyle = PdfBorderStyle.Solid;
            button.ForeColor = new PdfRGBColor(Color.White);
            button.BackColor = new PdfRGBColor(Color.Blue);
            button.ToolTip = "Print";
            button.Font = new PdfFont(PdfFontFamily.Helvetica, 9f);

            //Add print action to the button
            button.AddPrintAction();

            //Add the button to document
            doc.Form.Fields.Add(button);            

            //Save the document
            doc.SaveToFile("Output.pdf");
        }
    }
}

When creating a speaker notes in a presentation slide, you can add more than one item or paragraph in notes and display them within a numbered list. In this tutorial, we’ll show you how to add a numbered list to notes using Spire.Presentation in C#.

Step 1: Initialize an instance of Presentation and get the first slide.

Presentation ppt = new Presentation();
ISlide slide = ppt.Slides[0];

Step 2: Add a new notes slide in the specified slide.

NotesSlide notesSlide = slide.AddNotesSlide();

Step 3: Add a new paragraph with the text to speaker notes.

TextParagraph paragraph = new TextParagraph();
paragraph.Text = "Tips for making effective presentations:";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);

Step 4: Add another paragraph with the text to notes, set the bullet type of the paragraph as numbered, and set the numbered style as Arabic number following by period.

paragraph = new TextParagraph();
paragraph.Text = "Use the slide master feature to create a consistent and simple design template.";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[1].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[1].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

Step 5: Repeat step 4 to add many more numbered paragraphs to notes.

paragraph = new TextParagraph();
paragraph.Text = "Simplify and limit the number of words on each screen.";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[2].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[2].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

paragraph = new TextParagraph();
paragraph.Text = "Use contrasting colors for text and background.";
notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
notesSlide.NotesTextFrame.Paragraphs[3].BulletType = TextBulletType.Numbered;
notesSlide.NotesTextFrame.Paragraphs[3].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

Step 6: Save the file.

ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);

Output:

How to Add a Numbered List to Notes in PowerPoint in C#

Full Code:

using Spire.Presentation;
namespace AddNumberedList
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ISlide slide = ppt.Slides[0];

            NotesSlide notesSlide = slide.AddNotesSlide();

            TextParagraph paragraph = new TextParagraph();
            paragraph.Text = "Tips for making effective presentations:";
            notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);

            paragraph = new TextParagraph();
            paragraph.Text = "Use the slide master feature to create a consistent and simple design template.";
            notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
            notesSlide.NotesTextFrame.Paragraphs[1].BulletType = TextBulletType.Numbered;
            notesSlide.NotesTextFrame.Paragraphs[1].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

            paragraph = new TextParagraph();
            paragraph.Text = "Simplify and limit the number of words on each screen.";
            notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
            notesSlide.NotesTextFrame.Paragraphs[2].BulletType = TextBulletType.Numbered;
            notesSlide.NotesTextFrame.Paragraphs[2].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

            paragraph = new TextParagraph();
            paragraph.Text = "Use contrasting colors for text and background.";
            notesSlide.NotesTextFrame.Paragraphs.Append(paragraph);
            notesSlide.NotesTextFrame.Paragraphs[3].BulletType = TextBulletType.Numbered;
            notesSlide.NotesTextFrame.Paragraphs[3].BulletStyle = NumberedBulletStyle.BulletArabicPeriod;

            ppt.SaveToFile("Output.pptx", FileFormat.Pptx2013);

        }

    }
}

The data validation feature in Excel allows the user to control what data can be entered into a cell. For example, you could use data validation to make sure a numeric entry is between 1 and 5, make sure a text entry is less than 20 characters, or make sure the value entered in a cell is from a predefined list. In this article, you will learn how to apply or remove data validation in Excel in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

To begin with, you need to add the DLL files included in the Spire.XLS for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.XLS

Apply Data Validation to Excel Cells

The following are the steps to add various types of data validation to cells using Spire.XLS for .NET.

  • Create a Workbook object
  • Get the first worksheet through Workbook.Worksheets[index] property.
  • Get a specific cell through Worksheet.Range property.
  • Set the data type allowed in the cell through CellRange.DataValidation.AllowType property. You can select Integer, Time, Date, TextLength, Decimal, etc. as the data type.
  • Set the comparison operator through CellRange.DataValiation.CompareOperator property. The comparison operators include Between, NotBetween, Less, Greater, and Equal.
  • Set one or two formulas for the data validation through CellRange.DataValidation.Formula1 and CellRange.DataValidation.Formula2 properties.
  • Set the input prompt through CellRange.DataValidation.InputMessage property.
  • Save the workbook to an Excel file using Workbook.SaveToFile() method.
  • C#
  • VB.NET
using System;
using Spire.Xls;

namespace ApplyDataValidation
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook object
            Workbook workbook = new Workbook();

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Insert text in cells
            sheet.Range["B2"].Text = "Number Validation:";
            sheet.Range["B4"].Text = "Date Validation:";
            sheet.Range["B6"].Text = "Text Length Validation:";
            sheet.Range["B8"].Text = "List Validation:";
            sheet.Range["B10"].Text = "Time Validation:";

            //Add a number validation to C2
            CellRange rangeNumber = sheet.Range["C2"];
            rangeNumber.DataValidation.AllowType = CellDataType.Integer;
            rangeNumber.DataValidation.CompareOperator = ValidationComparisonOperator.Between;
            rangeNumber.DataValidation.Formula1 = "1";
            rangeNumber.DataValidation.Formula2 = "10";
            rangeNumber.DataValidation.InputMessage = "Enter a number between 1 and 10";
            rangeNumber.Style.KnownColor = ExcelColors.Gray25Percent;

            //Add a date validation to C4
            CellRange rangeDate = sheet.Range["C4"];
            rangeDate.DataValidation.AllowType = CellDataType.Date;
            rangeDate.DataValidation.CompareOperator = ValidationComparisonOperator.Between;
            rangeDate.DataValidation.Formula1 = "1/1/2010";
            rangeDate.DataValidation.Formula2 = "12/31/2020";
            rangeDate.DataValidation.InputMessage = "Enter a date between 1/1/2010 and 12/31/2020";
            rangeDate.Style.KnownColor = ExcelColors.Gray25Percent;

            //Add a text length validation to C6
            CellRange rangeTextLength = sheet.Range["C6"];
            rangeTextLength.DataValidation.AllowType = CellDataType.TextLength;
            rangeTextLength.DataValidation.CompareOperator = ValidationComparisonOperator.LessOrEqual;
            rangeTextLength.DataValidation.Formula1 ="5";
            rangeTextLength.DataValidation.InputMessage = "Enter text lesser than 5 characters";
            rangeTextLength.Style.KnownColor = ExcelColors.Gray25Percent;

            //Apply a list validation to C8
            CellRange rangeList = sheet.Range["C8"];
            rangeList.DataValidation.Values = new String[] { "United States", "Canada", "United Kingdom", "Germany" };
            rangeList.DataValidation.IsSuppressDropDownArrow = false;
            rangeList.DataValidation.InputMessage ="Choose an item from the list";
            rangeList.Style.KnownColor =ExcelColors.Gray25Percent;

            //Apply a time validation to C10
            CellRange rangeTime = sheet.Range["C10"];
            rangeTime.DataValidation.AllowType = CellDataType.Time;
            rangeTime.DataValidation.CompareOperator = ValidationComparisonOperator.Between;
            rangeTime.DataValidation.Formula1 = "9:00";
            rangeTime.DataValidation.Formula2 = "12:00";
            rangeTime.DataValidation.InputMessage = "Enter a time between 9:00 and 12:00";
            rangeTime.Style.KnownColor = ExcelColors.Gray25Percent;

            //Auto fit width of column 2
            sheet.AutoFitColumn(2);

            //Set the width of column 3
            sheet.Columns[2].ColumnWidth = 20;

            //Save to file
            workbook.SaveToFile("ApplyDataValidation.xlsx", ExcelVersion.Version2016);
        }
    }
}

C#/VB.NET: Apply or Remove Data Validation in Excel

Remove Data Validation from Excel Cells

Below are the steps to remove data validation from the specified cell using Spire.XLS for .NET.

  • Create a Workbook object.
  • Load the Excel file containing data validation using Workbook.LoadFromFile() method.
  • Get the first worksheet though Workbook.Worksheets[index] property.
  • Create an array of rectangles, which is used to locate the cells where the validation will be removed.
  • Remove the data validation from the selected cells using Worksheet.DVTable.Remove() method.
  • Save the workbook to another Excel file using Workbook.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Xls;
using System.Drawing;

namespace RemoveDataValidation
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook object
            Workbook workbook = new Workbook();

            //Load a sample Excel file
            workbook.LoadFromFile("C:\\Users\\Administrator\\Desktop\\ApplyDataValidation.xlsx");

            //Get the first worksheet
            Worksheet worksheet = workbook.Worksheets[0];

            //Create an array of rectangles, which is used to locate the ranges in worksheet
            Rectangle[] rectangles = new Rectangle[]{

                //one Rectangle(startColumnIndex, startRowIndex, endColumnIndex, endRowIndex) specifies a  cell range to remove data validation
                //the column or row index starts at 0
                new Rectangle(0, 0, 2, 9)
            };

            //Remove the data validation from the selected cells
            worksheet.DVTable.Remove(rectangles);

            //Save the workbook to an Excel file
            workbook.SaveToFile("RemoveDataValidation.xlsx");
        }
    }
}

C#/VB.NET: Apply or Remove Data Validation in Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

With the help of Spire.Doc, we can easily add and remove header on the word documents in C#. This article we will demonstrate how to lock down the header information from editing. We will divide it into two parts for the demo. Once is for locking the header information on the existing word document with header and the other is on the new creating word document.

How to lock the header information on the existing word document.

//Load the sample document with header
Document doc = new Document();
doc.LoadFromFile("sample.docx");

//Get the first section from the word document
Section section = doc.Sections[0];

//Protect the document and set the ProtectionType as AllowOnlyFormFields
doc.Protect(ProtectionType.AllowOnlyFormFields, "123");

//Set the ProtectForm as false to unprotect the section
section.ProtectForm = false;

//Save the document to file
doc.SaveToFile("Result.docx", FileFormat.Docx2013);

Effective screenshot of the header has been locked and the other area can be edited:

How to lock the header from editing on word document in C#

How to lock the header information for the new word document.

//Create a new instance of word document
Document doc = new Document();

//Add a section to the word document
Section section = doc.AddSection();

//Add header information to the section
HeaderFooter header = section.HeadersFooters.Header;
Paragraph HParagraph = header.AddParagraph();
TextRange HText = HParagraph.AppendText("Protect header");

//Add a paragraph to the section
Paragraph Para = section.AddParagraph();
Para.AppendText("Demo of how to lock the header information by Spire.Doc ");

//Set the ProtectionType as AllowOnlyFormFields and then unprotect the section
doc.Protect(ProtectionType.AllowOnlyFormFields, "123");
section.ProtectForm = false;

//Save the document to file
doc.SaveToFile("Result.docx", FileFormat.Docx2013);

How to lock the header from editing on word document in C#

Excel enables us to split an excel worksheet into two or four independent panes. After splitting up the window into panes, we can use the horizontal and vertical scroll bars to view and compare data in different parts of the same worksheet. This article demonstrates how to vertical and horizontal split an excel worksheet into four panes programmatically using Spire.XLS.

Detail steps:

Step 1: Instantiate a Workbook instance and load the excel document.

Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Split the worksheet horizontally and vertically.

sheet.FirstVisibleColumn = 3;

sheet.FirstVisibleRow = 5;

sheet.VerticalSplit = 110;

sheet.HorizontalSplit = 100;
sheet.ActivePane = 1;

Step 4: Save the excel document.

workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);

Screenshot after splitting:

How to Split Excel Worksheet into Multiple Panes in C#

Full codes:

using Spire.Xls;

namespace Split_Panes
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the excel document
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");
            
            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Vertical and horizontal split the worksheet into four panes

            sheet.FirstVisibleColumn = 3;

            sheet.FirstVisibleRow = 5;

            sheet.VerticalSplit = 110;

            sheet.HorizontalSplit = 100;

            sheet.ActivePane = 1;
 
            //Save the excel document
            workbook.SaveToFile("Output.xlsx", ExcelVersion.Version2013);

            workbook.Dispose();
        }
    }
}
page 29