page 177

Using Excel conditional formatting, we can quickly find and highlight the duplicate and unique values in a selected cell range. In this article, we’re going to show you how to programmatically highlight duplicate and unique values with different colors using Spire.XLS and conditional formatting.

Detail steps:

Step 1: Initialize an object of Workbook class and Load the Excel file.

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

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Use conditional formatting to highlight duplicate values in range "A2:A10" with IndianRed color.

ConditionalFormatWrapper format1 = sheet.Range["A2:A10"].ConditionalFormats.AddCondition();
format1.FormatType = ConditionalFormatType.DuplicateValues;
format1.BackColor = Color.IndianRed;

Step 4: Use conditional formatting to highlight unique values in range "A2:A10" with Yellow color.

ConditionalFormatWrapper format2 = sheet.Range["A2:A10"].ConditionalFormats.AddCondition();
format2.FormatType = ConditionalFormatType.UniqueValues;
format2.BackColor = Color.Yellow;

Step 5: Save the file.

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

Screenshot:

Highlight Duplicate and Unique Values in Excel Using C#

Full code:

using Spire.Xls;
using System.Drawing;
namespace HighlightDuplicateandUniqueValues
{
    class Program
    {
        static void Main(string[] args)
        {
            {

                //Load the Excel file
                Workbook workbook = new Workbook();
                workbook.LoadFromFile("Input.xlsx");

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

                //Use conditional formatting to highlight duplicate values in range "A2:A10" with IndianRed color
                ConditionalFormatWrapper format1 = sheet.Range["A2:A10"].ConditionalFormats.AddCondition();
                format1.FormatType = ConditionalFormatType.DuplicateValues;
                format1.BackColor = Color.IndianRed;

                //Use conditional formatting to highlight unique values in range "A2:A10" with Yellow color
                ConditionalFormatWrapper format2 = sheet.Range["A2:A10"].ConditionalFormats.AddCondition();
                format2.FormatType = ConditionalFormatType.UniqueValues;
                format2.BackColor = Color.Yellow;

                //Save the file            
                workbook.SaveToFile("HighlightDuplicates.xlsx", ExcelVersion.Version2013);
            }

        }
    }
}

We have already demonstrated how to insert footnote to the word document with the help of Spire.Doc. This article we will show you how to set the position and number format for the footnote. The footnote position can be at the bottom of each page or below text. The default number format for the footnote is “1, 2, 3”. The following example shows how to set the position, number format, and the restart rule of footnote by calling the property of Section.FootnoteOptions.

Firstly, view the Footnote options under Microsoft Word and the original sample document file:

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

Step 1: Create a new instance of Document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2013);

Step 2: Get the first section from the document.

Section sec = doc.Sections[0];

Step 3: Set the number format, restart rule and position for the footnote.

sec.FootnoteOptions.NumberFormat = FootnoteNumberFormat.UpperCaseLetter;
sec.FootnoteOptions.RestartRule = FootnoteRestartRule.RestartPage;
sec.FootnoteOptions.Position = FootnotePosition.PrintAtBottomOfPage;

Step 4: Save the document to file.

doc.SaveToFile("Footnoteoptions.docx", FileFormat.Docx2013);

Effective screenshot after setting the formatting for the footnote.

How to set the position and number format for word footnote in C#

How to set the position and number format for word footnote in C#

Full codes of how to set the footnote options:

Document doc = new Document();
doc.LoadFromFile("Sample.docx", FileFormat.Docx2013);

Section sec = doc.Sections[0];

sec.FootnoteOptions.NumberFormat = FootnoteNumberFormat.UpperCaseLetter;
sec.FootnoteOptions.RestartRule = FootnoteRestartRule.RestartPage;
sec.FootnoteOptions.Position = FootnotePosition.PrintAtBottomOfPage;

////Clear all the formatting for the footnote and back to the default opitions
//sec.FootnoteOptions.ClearFormatting();

doc.SaveToFile("Footnoteoptions.docx", FileFormat.Docx2013);

Text watermark and image watermark are two kinds of watermarks in Word document. The text watermark always shows some additional but related information to the word context. While image watermark is used to make the Word document be more attractive. This section will demonstrate how to use Spire.Doc to add text watermark and image watermark to Word document in C#.

Add Image Watermark in C#:

using Spire.Doc;
namespace SetImageWatermark
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //create a new instance of Document and load the document from file.
                Document doc = new Document();
                doc.LoadFromFile("Sample.docx", FileFormat.Docx2013);

                //create a new instance of the PictureWatermark and load the picture from file.
                PictureWatermark picture = new PictureWatermark();
                picture.Picture = System.Drawing.Image.FromFile("logo.png");

                //set the image watermark scaling and Washout property
                picture.Scaling = 20;
                picture.IsWashout = false;

                //add the picture watermark
                doc.Watermark = picture;

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

            }
        }
    }
}

Add text watermark and image watermark to word document in C#

Add Text Watermark in C#::

using Spire.Doc;
using Spire.Doc.Documents;
using System.Drawing;
namespace SetTextWatermark
{
    class Program
    {
        static void Main(string[] args)
        {
            {
                //create a new instance of Document and load the document from file.
                Document doc = new Document();
                doc.LoadFromFile("Sample.docx", FileFormat.Docx2013);

                //create a new instance of the TextWatermark 
                TextWatermark txtWatermark = new TextWatermark();

                //set the text watermark with text string, font, color and layout.
                txtWatermark.Text = "Confidential";
                txtWatermark.FontSize = 45;
                txtWatermark.Color = Color.Green;
                txtWatermark.Layout = WatermarkLayout.Diagonal;

                //add the text watermark
                doc.Watermark = txtWatermark;

                //save the file.
                doc.SaveToFile("TextWatermark.docx", FileFormat.Docx2013);

            }
        }
    }
}

Add text watermark and image watermark to word document in C#

page 177

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details