page 179

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#

Microsoft Excel provides 10 date options, ranging from yesterday to next month (see below image) to format selected cells based on the current date. Spire.XLS supports all of these options, in this article, we’re going to show you how to conditionally format dates in Excel using Spire.XLS. If you want to highlight cells based on a date in another cell, or create rules for other dates (i.e., more than a month from the current date), you will have to create your own conditional formatting rule based on a formula.

Conditionally Format Dates in Excel with C#

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: Add a condition to the used range in the worksheet.

ConditionalFormatWrapper conditionalFormat = sheet.AllocatedRange.ConditionalFormats.AddCondition();

Step 4: Specify the format type of the condition as time period and set the time period as last 7 days.

conditionalFormat.FormatType = ConditionalFormatType.TimePeriod;
conditionalFormat.SetTimePeriod(TimePeriodType.Last7Days);

Step 5:Set the highlight color.

conditionalFormat.BackColor = Color.Orange;

Step 6:Save the file.

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

Screenshot::

Conditionally Format Dates in Excel with C#

Full Code:

[C#]
using Spire.Xls;
using Spire.Xls.Core.Spreadsheet.ConditionalFormatting;
using System.Drawing;
namespace ConditionallyFormatDates
{
    class Program
    {
        static void Main(string[] args)
        {
            {

                //Initialize an object of Workbook class
                Workbook workbook = new Workbook();
                //Load the Excel file
                workbook.LoadFromFile("Input.xlsx");

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

                //Highlight cells that contain a date occurring in the last 7 days
                ConditionalFormatWrapper conditionalFormat = sheet.AllocatedRange.ConditionalFormats.AddCondition();
                conditionalFormat.FormatType = ConditionalFormatType.TimePeriod;
                conditionalFormat.SetTimePeriod(TimePeriodType.Last7Days);
                conditionalFormat.BackColor = Color.Orange;

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

        }
    }
}

It is possible to add text transparency to any text shape in PowerPoint. In order to make the text transparent, we’d need to apply the transparency level to the text shape. This article will show you how to set the transparency level of text using Spire.Presentation.

Step 1: Create a Presentation instance.

Presentation ppt = new Presentation();

Step 2: Add a shape to the first slide.

IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70,300, 120));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = FillFormatType.None;

Step 3: Add text to shape.

textboxShape.TextFrame.Text = "Text Transparency";

Step 4: Set the fill type of TextRange to solid, and fill the TextRange using the color created with specified alpha value.

textboxShape.TextFrame.TextRange.Fill.FillType = FillFormatType.Solid;
int alpha = 55;
textboxShape.TextFrame.TextRange.Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);

Step 5:Save the file.

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

Output:

Apply Transparency to Text in PowerPoint in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace ApplyTransparency
{
    class Program
    {
        static void Main(string[] args)
        {

            //create a PowerPoint document
            Presentation ppt = new Presentation();
            ppt.SlideSize.Type = SlideSizeType.Screen16x9;

            //add a shape
            IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 300, 120));
            textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
            textboxShape.Fill.FillType = FillFormatType.None;

            //remove default blank paragraphs
            textboxShape.TextFrame.Paragraphs.Clear();

            //add three paragraphs, apply color with different alpha values to text
            int alpha = 55;
            for (int i = 0; i < 3; i++)
            {
                textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
                textboxShape.TextFrame.Paragraphs[i].TextRanges.Append(new TextRange("Text Transparency"));
                textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.FillType = FillFormatType.Solid;
                textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);
                alpha += 100;
            }

            //save to file
            ppt.SaveToFile("result.pptx", FileFormat.Pptx2013); 

        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace ApplyTransparency
	Class Program
		Private Shared Sub Main(args As String())

			'create a PowerPoint document
			Dim ppt As New Presentation()
			ppt.SlideSize.Type = SlideSizeType.Screen16x9

			'add a shape
			Dim textboxShape As IAutoShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 300, 120))
			textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
			textboxShape.Fill.FillType = FillFormatType.None

			'remove default blank paragraphs
			textboxShape.TextFrame.Paragraphs.Clear()

			'add three paragraphs, apply color with different alpha values to text
			Dim alpha As Integer = 55
			For i As Integer = 0 To 2
				textboxShape.TextFrame.Paragraphs.Append(New TextParagraph())
				textboxShape.TextFrame.Paragraphs(i).TextRanges.Append(New TextRange("Text Transparency"))
				textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.FillType = FillFormatType.Solid
				textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple)
				alpha += 100
			Next

			'save to file
			ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)

		End Sub
	End Class
End Namespace
page 179