Spire.Presentation is a powerful and standalone .NET component which designed for developers to operate the PowerPoint documents in C# and VB.NET. Spire.Presentation enable developers to insert a new table, remove rows or columns in an existing table, and remove the whole table from the presentation slides. This article we will show you how to add a row to an existing table in presentation slide by using C# code.

Step 1: Create Presentation instance and load file.

Presentation ppt = new Presentation();
ppt.LoadFromFile("table.pptx");

Step 2: Get the table within the PowerPoint document.

ITable table = ppt.Slides[0].Shapes[4] as ITable;

Step 3: Add a new row into the PowerPoint table and set the data for the cells in the new row.

//Get the first row
TableRow row = table.TableRows[0];
//Clone the row and add it to the end of table
table.TableRows.Append(row);
int rowCount = table.TableRows.Count;
//Get the last row
TableRow lastRow = table.TableRows[rowCount - 1];
//Set new data of the first cell of last row
lastRow[0].TextFrame.Text = " The first cell";
//Set new data of the second cell of last row
lastRow[1].TextFrame.Text = " The second cell";

Step 4: Save the document and preview it.

ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("result.pptx");

Effective screenshot:

How to add a row to an existing table in PowerPoint documents

Full codes:

using Spire.Presentation;

namespace AddRow
{

    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("table.pptx");

            ITable table = ppt.Slides[0].Shapes[4] as ITable;
            TableRow row = table.TableRows[0];
            table.TableRows.Append(row);
            int rowCount = table.TableRows.Count;
            TableRow lastRow = table.TableRows[rowCount - 1];
            lastRow[0].TextFrame.Text = "The first cell";
            lastRow[1].TextFrame.Text = "The second cell";

            ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }
    }
}

Spire.Presentation offer developers an easy way to add the watermarks to the presentation slides. There are two kinds of watermarks in PowerPoint documents: text watermark and image watermark. We'll learn how to add image watermark in PowerPoint document via Spire.Presentation.

The goal of the article is to make an image as a background img watermark as following screenshot.

How to add image watermark in PowerPoint document in C#

Here comes to the steps of how to add image watermarks in C#:

Step 1: Create a presentation document and load the document from the file

Presentation ppt = new Presentation();
ppt.LoadFromFile(fileName);

Step 2: Get the image you want to add as image watermark.

IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));

Step 3: Set the properties of SlideBackground, and then fill the image as watermark.

ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType=PictureFillType.Stretch;
ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

step4: Save the document to a new file.

ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);

Full codes:

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace AddimageWatermark
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile(fileName);
            IImageData image = ppt.Images.Append(Image.FromFile("Header.png"));
            ppt.Slides[0].SlideBackground.Type = Spire.Presentation.Drawing.BackgroundType.Custom;
            ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Picture;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.FillType = PictureFillType.Stretch;
            ppt.Slides[0].SlideBackground.Fill.PictureFill.Picture.EmbedImage = image;

            if (fileExtensions == ".ppt")
            {
                ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.PPT);
            }
            else
            {
                ppt.SaveToFile(resultFileName, Spire.Presentation.FileFormat.Pptx2007);
            }

            Viewer(resultFileName);
        }
    }
}

Sometimes we need to make use of the attachments added to the PDF files. There are 2 kinds of attachment in pdf, one is common attachment that added to the file directly, the other is attachment annotations which is add to the particular place as an annotation like the following picture, when you click correlative icon, that attachment will be opened.

In this article, we will learn how to extract these two kinds of attachment in C# via Spire.PdfViewer.

Extract the attachments from PDF document via PDFViewer

Here are the steps:

Step 1: Download PdfViewer, add PdfViewer Control to VS Toolbox (How to add control).

Extract the attachments from PDF document via PDFViewer

Step 2: Create a Windows Forms application, design Form as below.

  • Two buttons respectively for common attachment and attachment annotation, and set name for them.
  • One open file button and one close attachment button.
  • A PdfDocmentViewer in the middle and one ViewList on the bottom.

Step 3: Get attachments

1) Get common attachment via methord GetAttachments(), then traverse attachment array and get common attachment property.

PdfDocumentAttachment[] attchments = this.pdfDocumentViewer1.GetAttachments();
if (attchments != null && attchments.Length > 0)
         {
             for (int i = 0; i < attchments.Length; i++)
             {
                 PdfDocumentAttachment attachment = attchments[i];
                 string fileName = attachment.FileName;
                 string mimeType = attachment.MimeType;
                 string desc = attachment.Description;
                 DateTime createDate = attachment.CreationTime;
                 DateTime modifyDate = attachment.ModifyTime;
                 Object data = attachment.Data;
                 ListViewItem item = new ListViewItem();
                 item.Text = Path.GetFileName(fileName);
                 item.SubItems.Add(mimeType);
                 item.SubItems.Add(desc);
                 item.SubItems.Add(createDate.ToShortDateString());
                 item.SubItems.Add(modifyDate.ToShortDateString());
                 item.Tag = attachment;
                 this.listView1.Items.Add(item);
             }
         }

Results:

Extract the attachments from PDF document via PDFViewer

2) Extract attachment annotation:

Get attachment annotations via methord GetAttachmentAnnotaions(). Then traverse annotation array and save each annotation property as an individual item in listview.

PdfDocumentAttachmentAnnotation[] annotations = this.pdfDocumentViewer1.GetAttachmentAnnotaions();  
if (annotations != null && annotations.Length > 0)
         {
             for (int i = 0; i < annotations.Length; i++)
             {
                 PdfDocumentAttachmentAnnotation annotation = annotations[i];
                 ListViewItem item = new ListViewItem(annotation.FileName);
                 item.SubItems.Add(annotation.Text);
                 item.SubItems.Add(annotation.PageIndex.ToString());
                 item.SubItems.Add(annotation.Location.ToString());
                 item.Tag = annotation;
                 this.listView1.Items.Add(item);
             }
         }

Results:

Extract the attachments from PDF document via PDFViewer

3) ListView

Here if we click the file name information of annotation attachment in the listView, PdfDocumentViewer will go to specified attachment annotation.

if (this.m_isAttachmentAnnotation)
     {
         PdfDocumentAttachmentAnnotation annotation = (PdfDocumentAttachmentAnnotation)this.listView1.SelectedItems[0].Tag;
         this.pdfDocumentViewer1.GotoAttachmentAnnotation(annotation);
     }

Double click it, the attachment can be saved to local. Get data of annotation, and write into file.

PdfDocumentAttachmentAnnotation annotation = (PdfDocumentAttachmentAnnotation)item.Tag;
byte[] data = annotation.Data;
writer.Write(data);

About saving common attachment:

PdfDocumentAttachment annotation = (PdfDocumentAttachment)item.Tag;
byte[] data = annotation.Data;
writer.Write(data);

Spire.PDFViewer is a powerful PDF Viewer component performed on .NET and WPF. It enables developers to load PDF document from stream, file and byte array. Also it supports rotation, page layout setup and thumbnail control. Worth a shot. Click to know more

A chart filled with an image of company logo or propaganda is more impressive than a plain chart; adding a proper image into a chart as background will dramatically draw attention from your readers. As is similar to MS Excel, Spire.XLS enables users to insert pictures to specific chart elements such as chart area, bar area and plot area. In this article, I'll introduce how to enhance your chart by inserting image in chart area and plot area in C#, VB.NET.

Test File:

Fill Chart Elements with Pictures

Code Snippet for Inserting Background Image:

Step 1: Create a new workbook and load the test file

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

Step 2: Get the first worksheet from workbook, get the first chart from worksheet.

Worksheet ws = workbook.Worksheets[0];
Chart chart = ws.Charts[0];

Step 3:

A) Insert chart area with a custom picture and set the transparency of plot area as 0.9. If you don't make plot area transparent, it will cover up the background image filled in chart area. Anyway, it all depends on your own needs.

chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");
chart.PlotArea.Fill.Transparency = 0.9;

B) Insert plot area with a custom picture

chart.PlotArea.Fill.CustomPicture(Image.FromFile("01.jpg"), "None");

Step 4: Save the file

workbook.SaveToFile("Sample.xlsx",ExcelVersion.Version2010);

Result:

A) Fill chart area with image

Fill Chart Elements with Pictures

B) Fill plot area with image

Fill Chart Elements with Pictures

Full Code:

[C#]
using Spire.Xls;
using System.Drawing;
namespace FillChartElement
{
    class Program
    {

        static void Main(string[] args)
        {

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

            Worksheet ws = workbook.Worksheets[0];
            Chart chart = ws.Charts[0];

            // A. Fill chart area with image
            chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");
            chart.PlotArea.Fill.Transparency = 0.9;

            //// B.Fill plot area with image
            //chart.PlotArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");

            workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2010);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports System.Drawing
Namespace FillChartElement
	Class Program

		Private Shared Sub Main(args As String())

			Dim workbook As New Workbook()
			workbook.LoadFromFile("test.xlsx")

			Dim ws As Worksheet = workbook.Worksheets(0)
			Dim chart As Chart = ws.Charts(0)

			' A. Fill chart area with image
			chart.ChartArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None")
			chart.PlotArea.Fill.Transparency = 0.9

			'''/ B.Fill plot area with image
			'chart.PlotArea.Fill.CustomPicture(Image.FromFile("05.jpg"), "None");

			workbook.SaveToFile("Sample.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace

Inserting text watermarks into PowerPoint presentations is an effective way to protect intellectual property and ensure content authenticity of these documents. Spire.Presentation for .NET provides a powerful and flexible way to programmatically add text watermarks to PowerPoint slides. Unlike PowerPoint's built-in features, this approach allows for batch processing, precise control over watermark placement and appearance, and integration into larger .NET applications.

This article will demonstrate how to insert text watermarks to PowerPoint presentations with C# using the Spire.Presentation for .NET library.

Install Spire.Presentation for .NET

To begin with, you need to add the DLL files included in the Spire.Presentation 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.Presentation

Insert a Single Watermark into PowerPoint Slides

Using Spire.Presentation for .NET, developers can add a single text watermark to a PowerPoint presentation by creating a locked transparent text box with the watermark in a custom style on each page. The detailed steps are as follows:

  • Create an instance of Presentation class and load a PowerPoint file using Presentation.LoadFromFile() method.
  • Define the watermark text, create a Font object, and measure the size of the text.
  • Get the size of the slides in the presentation through Presentation.SlideSize.Size property.
  • Create a RectangleF object based on the text size and the slide size.
  • Iterate through the slides in the presentation:
    • Create an IAutoShape object on each slide at the position of the rectangle using ISlide.Shapes.AppendShape() method.
    • Set the style of the shape using the properties under IAutoShape class.
    • Add the watermark text to the shape through IAutoShape.TextFrame.Text property.
    • Get the watermark text as a TextRange object through IAutoShape.TextFrame.TextRange property.
    • Set the format of the watermark text through the properties under TextRange class.
  • Save the presentation using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace SingleTextWatermarkPowerPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of Presentation
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("Sample.pptx");

            // Define the watermark text and create a font for it
            string text = "Example";
            // Create a font object
            Font font = new Font("Arial", 50);
            // Measure the size of the watermark text
            Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
            SizeF size = graphics.MeasureString(text, font);

            // Get the slide size
            SizeF slideSize = presentation.SlideSize.Size;

            // Create a retangle based on the text size and page size
            RectangleF rect = new RectangleF((slideSize.Width - size.Width) / 2, (slideSize.Height - size.Height) /2, size.Width, size.Height);

            // Iterate through the slides in the presentation
            foreach (ISlide slide in presentation.Slides)
            {
                // Create a shape of watermark on each slide
                IAutoShape watermark = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                // Set the style of the watermark
                watermark.Fill.FillType = FillFormatType.None;
                watermark.ShapeStyle.LineColor.Color = Color.Empty;
                watermark.Rotation = -45;
                watermark.Locking.SelectionProtection = true;
                watermark.Line.FillType = FillFormatType.None;
                // Add the watermark text to the shape
                watermark.TextFrame.Text = text;
                // Set the style of the watermark text
                TextRange textRange = watermark.TextFrame.TextRange;
                textRange.Fill.FillType = FillFormatType.Solid;
                textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                textRange.FontHeight = 50;
            }

            // Save the presentation
            presentation.SaveToFile("output/PowerPointSingleTextWatermark.pptx", FileFormat.Auto);
            presentation.Dispose();
        }
    }
}

Single Text Watermark in PowerPoint Slides

Insert Repeated Watermarks into PowerPoint Slides

Developers can insert repeated text watermarks into slides by drawing multiple identical text watermarks at specified intervals on the slides. Here are the detailed steps:

  • Create an instance of Presentation class and load a PowerPoint file using Presentation.LoadFromFile() method.
  • Define the watermark text, create a Font object, and measure the size of the text.
  • Get the size of the slides in the presentation through Presentation.SlideSize.Size property.
  • Iterate through the slides in the presentation:
    • Define the start position and the intervals.
    • Add watermark shapes and text and set their format.
    • Move the lateral position to the next interval on the row after finishing adding a watermark.
    • Move the vertical position to the next row after finishing adding the watermarks of each row.
  • Save the presentation using Presentation.SaveToFile() method.
  • C#
using Spire.Presentation.Drawing;
using Spire.Presentation;
using System.Drawing;

namespace RepeatedTextWatermarkPowerPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create an instance of Presentation
            Presentation presentation = new Presentation();

            // Load a PowerPoint file
            presentation.LoadFromFile("Sample.pptx");

            // Define the watermark text and create a font for it
            string text = "Example";
            // Create a font object
            Font font = new Font("Arial", 20);
            // Measure the size of the watermark text
            Graphics graphics = Graphics.FromImage(new Bitmap(1, 1));
            SizeF size = graphics.MeasureString(text, font);

            // Get the slide size
            SizeF slideSize = presentation.SlideSize.Size;

            // Iterate through the slides in the presentation
            foreach (ISlide slide in presentation.Slides)
            {
                float x = 30;
                float y = 80;
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // Create a rectangle
                        RectangleF rect = new RectangleF(x, y, size.Width, size.Height);
                        IAutoShape watermark = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                        // Set the style of the watermark
                        watermark.Fill.FillType = FillFormatType.None;
                        watermark.ShapeStyle.LineColor.Color = Color.Empty;
                        watermark.Rotation = -45;
                        watermark.Locking.SelectionProtection = true;
                        watermark.Line.FillType = FillFormatType.None;
                        // Add the watermark text to the shape
                        watermark.TextFrame.Text = text;
                        // Set the style of the watermark text
                        TextRange textRange = watermark.TextFrame.TextRange;
                        textRange.Fill.FillType = FillFormatType.Solid;
                        textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                        textRange.FontHeight = 20;
                        x += ((slideSize.Width - 60) / 3 + size.Width / 2);
                    }
                    x = 30;
                    y += ((slideSize.Height - 160) / 3 + size.Height / 2);
                }
            }

            // Save the presentation
            presentation.SaveToFile("output/PowerPointRepeatedTextWatermark.pptx", FileFormat.Auto);
            presentation.Dispose();
        }
    }
}

***

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 for .NET, developers can easily set bullet style for the existing word documents via invoke p.ListFormat.ApplyBulletStyle() method to format. This article will show you how to convert HTML list into word and set the bullet style for the word list in C#.

Firstly, please view the effective screenshot for the result word document:

How to set word bullet style by appending the HTML code in C#

Here comes to the steps:

Step 1: Create a new document and add a section to the document.

Document document = new Document();
Section section=document.AddSection();

Step 2: Add word list to the paragraph by appending HTML.

Paragraph paragraph = section.AddParagraph();
paragraph.AppendHTML("<ol><li>Version 1</li><li>Version 2</li><li>Version 3</li></ol>");

Step 3: Set the bullet style for the paragraph.

foreach (Paragraph p in section.Paragraphs)
{
    p.ApplyStyle(BuiltinStyle.Heading2);

    if (p.ListFormat.CurrentListLevel != null)
    {
        p.ListFormat.ApplyBulletStyle();
    }
}

Step 4: Save the document to file

document.SaveToFile("result.docx",FileFormat.Docx);

Full codes:

// Create a new Word document object
Document document = new Document();

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

// Add a paragraph to the section
Paragraph paragraph = section.AddParagraph();

// Append HTML content to the paragraph 
paragraph.AppendHTML("
  1. Version 1
  2. Version 2
  3. Version 3
"); // Loop through all paragraphs in the section foreach (Paragraph p in section.Paragraphs) { // Apply "Heading 2" built-in style to the paragraph p.ApplyStyle(BuiltinStyle.Heading2); // Check if the paragraph has listformat if (p.ListFormat.CurrentListLevel != null) { // Apply bullet style p.ListFormat.ApplyBulletStyle(); } } // Save the document to a file in DOCX format document.SaveToFile("result.docx", FileFormat.Docx); // Dispose document.Dispose();

In some cases, you have several items that you want them displayed on multiple lines within a PDF grid cell. However if you don't enter a line break at a specific point in a cell, these items will appear as a whole sentence. In the article, you can learn how to insert line breaks in PDF grid cell via Spire.PDF in C#, VB.NET.

Here come the detailed steps:

Step 1: Initialize a new instance of PdfDocument and add a new page to PDF document.

PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

Step 2: Create a PDF gird with one row and three columns.

PdfGrid grid = new PdfGrid();
grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
PdfGridRow row = grid.Rows.Add();
grid.Columns.Add(3);
grid.Columns[0].Width = 80;
grid.Columns[1].Width = 80;
grid.Columns[2].Width = 80;

Step 3: Initialize a new instance of PdfGridCellTextAndStyleList class and PdfGridCellTextAndStyle class. Set parameters of the variable textAndStyle such as text, font and brush. Add textAndStlye into PdfGridCellTextAndStyleList.

PdfGridCellTextAndStyleList lst = new PdfGridCellTextAndStyleList(); 
PdfGridCellTextAndStyle textAndStyle = new PdfGridCellTextAndStyle();
textAndStyle.Text = "Line 1";
textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Airal", 8f, FontStyle.Regular), true);
textAndStyle.Brush = PdfBrushes.Black;
lst.List.Add(textAndStyle);

Step 4: Repeat step 3 to add three other lines. Here you should insert '\n' to where you want this line break appears.

textAndStyle = new PdfGridCellTextAndStyle();
textAndStyle.Text = "\nLine 2";
textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 8f, FontStyle.Regular), true);
textAndStyle.Brush = PdfBrushes.Black;
lst.List.Add(textAndStyle);
textAndStyle = new PdfGridCellTextAndStyle();
textAndStyle.Text = "\nLine 3";
textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 8f, FontStyle.Regular), true);
textAndStyle.Brush = PdfBrushes.Black;
lst.List.Add(textAndStyle);
textAndStyle = new PdfGridCellTextAndStyle();
textAndStyle.Text = "\nLine 4";
textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial",8f, FontStyle.Regular), true);
textAndStyle.Brush = PdfBrushes.Black;
lst.List.Add(textAndStyle);
row.Cells[0].Value = lst;

Step 5: Draw the gird on PDF page and save the file.

grid.Draw(page, new PointF(10, 20));
String outputFile = "..\\..\\Sample.pdf";
doc.SaveToFile(outputFile, FileFormat.PDF);
System.Diagnostics.Process.Start(outputFile);

Result:

How to Insert a Line Break in PDF Grid Cell in C#, VB.NET

Full Code:

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


namespace LineBreak
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            PdfGridRow row = grid.Rows.Add();
            grid.Columns.Add(3);
            grid.Columns[0].Width = 80;
            grid.Columns[1].Width = 80;
            grid.Columns[2].Width = 80;

            PdfGridCellContentList lst = new PdfGridCellContentList();
            PdfGridCellContent textAndStyle = new PdfGridCellContent();
            textAndStyle.Text = "Line 1";
            textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Airal", 8f, FontStyle.Regular), true);
            textAndStyle.Brush = PdfBrushes.Black;
            lst.List.Add(textAndStyle);
            textAndStyle = new PdfGridCellContent();
            textAndStyle.Text = "\nLine 2";
            textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 8f, FontStyle.Regular), true);
            textAndStyle.Brush = PdfBrushes.Black;
            lst.List.Add(textAndStyle);
            textAndStyle = new PdfGridCellContent();
            textAndStyle.Text = "\nLine 3";
            textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 8f, FontStyle.Regular), true);
            textAndStyle.Brush = PdfBrushes.Black;
            lst.List.Add(textAndStyle);
            textAndStyle = new PdfGridCellContent();
            textAndStyle.Text = "\nLine 4";
            textAndStyle.Font = new PdfTrueTypeFont(new System.Drawing.Font("Arial", 8f, FontStyle.Regular), true);
            textAndStyle.Brush = PdfBrushes.Black;
            lst.List.Add(textAndStyle);
            row.Cells[0].Value = lst;

            grid.Draw(page, new PointF(10, 20));
            String outputFile = "..\\..\\Sample.pdf";
            doc.SaveToFile(outputFile, FileFormat.PDF);
            System.Diagnostics.Process.Start(outputFile);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Grid
Imports System.Drawing


Namespace LineBreak
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			Dim page As PdfPageBase = doc.Pages.Add()

			Dim grid As New PdfGrid()
			grid.Style.CellPadding = New PdfPaddings(1, 1, 1, 1)
			Dim row As PdfGridRow = grid.Rows.Add()
			grid.Columns.Add(3)
			grid.Columns(0).Width = 80
			grid.Columns(1).Width = 80
			grid.Columns(2).Width = 80

			Dim lst As New PdfGridCellContentList()
			Dim textAndStyle As New PdfGridCellContent()
			textAndStyle.Text = "Line 1"
			textAndStyle.Font = New PdfTrueTypeFont(New System.Drawing.Font("Airal", 8F, FontStyle.Regular), True)
			textAndStyle.Brush = PdfBrushes.Black
			lst.List.Add(textAndStyle)
			textAndStyle = New PdfGridCellContent()
			textAndStyle.Text = vbLf & "Line 2"
			textAndStyle.Font = New PdfTrueTypeFont(New System.Drawing.Font("Arial", 8F, FontStyle.Regular), True)
			textAndStyle.Brush = PdfBrushes.Black
			lst.List.Add(textAndStyle)
			textAndStyle = New PdfGridCellContent()
			textAndStyle.Text = vbLf & "Line 3"
			textAndStyle.Font = New PdfTrueTypeFont(New System.Drawing.Font("Arial", 8F, FontStyle.Regular), True)
			textAndStyle.Brush = PdfBrushes.Black
			lst.List.Add(textAndStyle)
			textAndStyle = New PdfGridCellContent()
			textAndStyle.Text = vbLf & "Line 4"
			textAndStyle.Font = New PdfTrueTypeFont(New System.Drawing.Font("Arial", 8F, FontStyle.Regular), True)
			textAndStyle.Brush = PdfBrushes.Black
			lst.List.Add(textAndStyle)
			row.Cells(0).Value = lst

			grid.Draw(page, New PointF(10, 20))
			Dim outputFile As [String] = "..\..\Sample.pdf"
			doc.SaveToFile(outputFile, FileFormat.PDF)
			System.Diagnostics.Process.Start(outputFile)
		End Sub
	End Class
End Namespace

Spire.Doc can help developers to create word table with data and format cells easily and it also supports to add text watermark into the word documents. This article will show you how to create a vertical table at one side of the word document, which looks like the vertical watermark in the word document.

Firstly, please check the effective screenshot of the vertical table at the right of the word document added by Spire.Doc:

How to create vertical table at one side of the word document

Here comes to the steps of how to create vertical table in C#.

Step 1: Create a new document and add a section to the document.

Document document = new Document();
Section section=document.AddSection();

Step 2: Add a table with rows and columns and set the text for the table.

Table table = section.AddTable();
table.ResetCells(1, 1);
TableCell cell = table.Rows[0].Cells[0];
table.Rows[0].Height = 150;
cell.AddParagraph().AppendText("Draft copy in vertical style");

Step 3: Set the TextDirection for the table to RightToLeftRotated.

cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;

Step 4: Set the table format.

table.TableFormat.WrapTextAround = true;
table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Page;
table.TableFormat.Positioning.HorizRelationTo = HorizontalRelation.Page;
table.TableFormat.Positioning.HorizPosition = section.PageSetup.PageSize.Width- table.Width;
table.TableFormat.Positioning.VertPosition = 200;

Step 5: Save the document to file.

document.SaveToFile("result.docx",FileFormat.docx2013);

Full codes in C#:

using Spire.Doc;
using Spire.Doc.Documents;

namespace CreateVerticalTable
{
    class Program
    {
        static void Main(string[] args)
        {

            Document document = new Document();
            Section section=document.AddSection();
            Table table = section.AddTable();
            table.ResetCells(1, 1);
            TableCell cell = table.Rows[0].Cells[0];
            table.Rows[0].Height = 150;
            cell.AddParagraph().AppendText("Draft copy in vertical style");
            cell.CellFormat.TextDirection = TextDirection.RightToLeftRotated;
            table.Format.WrapTextAround = true;
            table.Format.Positioning.VertRelationTo = VerticalRelation.Page;
            table.Format.Positioning.HorizRelationTo = HorizontalRelation.Page;
            table.Format.Positioning.HorizPosition = section.PageSetup.PageSize.Width - table.Width;
            table.Format.Positioning.VertPosition = 200;

            document.SaveToFile(""result.docx"", FileFormat.Docx2013);

        }
    }
}

MS Excel contains a set of Windows Forms controls that can be used to Worksheet to host item. Spire.XLS also provides programmers similar features to add controls on Worksheet at runtime without installing any other control program. In this article, I'll introduce you how to insert TextBox, CheckBox and RadioButton into Worksheet via Spire.XLS in C#, VB.NET.

Detailed Steps:

Step 1: Download Spire.XLS and reference dll file to your VS project.

Step 2: Use Spire.Xls.Core as namespace, which contains all the interfaces like ITextBoxShap, ICheckBox, IRadioButton and etc.

Step 3: Initialize a new instance of Workbook and create a Worksheet in it.

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets[0];

Step 4: Insert a TextBox at specified location and input the display text.

ITextBoxShape textbox = ws.TextBoxes.AddTextBox(2, 2, 15, 100);
textbox.Text = "Hello World";

Step 5: Insert three CheckBox into Worksheet at different locations. Set the CheckState and display text.

ICheckBox cb = ws.CheckBoxes.AddCheckBox(4, 2, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 1";

cb = ws.CheckBoxes.AddCheckBox(4, 4, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 2";

cb = ws.CheckBoxes.AddCheckBox(4, 6, 15, 100);
cb.CheckState = CheckState.Checked;
cb.Text = "Check Box 3";

Step 6: Insert three RadioButton and set the related properties.

IRadioButton rb = ws.RadioButtons.Add(6, 2, 15, 100);
rb.Text = "Option 1";

rb = ws.RadioButtons.Add(8, 2, 15, 100);
rb.CheckState = CheckState.Checked;
rb.Text = "Option 2";

rb = ws.RadioButtons.Add(10, 2, 15, 100);
rb.Text = "Option 3";

Step 7: Save the file.

ws.DefaultRowHeight = 15;
wb.SaveToFile("Result.xlsx", ExcelVersion.Version2010);

Output:

How to Insert Controls to Worksheet in C#, VB.NET

Full Code:

[C#]
using Spire.Xls;
using Spire.Xls.Core;
namespace InsertControl
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook wb = new Workbook();
            Worksheet ws = wb.Worksheets[0];

            ITextBoxShape textbox = ws.TextBoxes.AddTextBox(2, 2, 15, 100);
            textbox.Text = "Hello World";

            ICheckBox cb = ws.CheckBoxes.AddCheckBox(4, 2, 15, 100);
            cb.CheckState = CheckState.Checked;
            cb.Text = "Check Box 1";

            cb = ws.CheckBoxes.AddCheckBox(4, 4, 15, 100);
            cb.CheckState = CheckState.Checked;
            cb.Text = "Check Box 2";

            cb = ws.CheckBoxes.AddCheckBox(4, 6, 15, 100);
            cb.CheckState = CheckState.Checked;
            cb.Text = "Check Box 3";

            IRadioButton rb = ws.RadioButtons.Add(6, 2, 15, 100);
            rb.Text = "Option 1";

            rb = ws.RadioButtons.Add(8, 2, 15, 100);
            rb.CheckState = CheckState.Checked;
            rb.Text = "Option 2";

            rb = ws.RadioButtons.Add(10, 2, 15, 100);
            rb.Text = "Option 3";

            ws.DefaultRowHeight = 15;
            wb.SaveToFile("Result.xlsx", ExcelVersion.Version2010);
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports Spire.Xls.Core
Namespace InsertControl
	Class Program
		Private Shared Sub Main(args As String())
			Dim wb As New Workbook()
			Dim ws As Worksheet = wb.Worksheets(0)

			Dim textbox As ITextBoxShape = ws.TextBoxes.AddTextBox(2, 2, 15, 100)
			textbox.Text = "Hello World"

			Dim cb As ICheckBox = ws.CheckBoxes.AddCheckBox(4, 2, 15, 100)
			cb.CheckState = CheckState.Checked
			cb.Text = "Check Box 1"

			cb = ws.CheckBoxes.AddCheckBox(4, 4, 15, 100)
			cb.CheckState = CheckState.Checked
			cb.Text = "Check Box 2"

			cb = ws.CheckBoxes.AddCheckBox(4, 6, 15, 100)
			cb.CheckState = CheckState.Checked
			cb.Text = "Check Box 3"

			Dim rb As IRadioButton = ws.RadioButtons.Add(6, 2, 15, 100)
			rb.Text = "Option 1"

			rb = ws.RadioButtons.Add(8, 2, 15, 100)
			rb.CheckState = CheckState.Checked
			rb.Text = "Option 2"

			rb = ws.RadioButtons.Add(10, 2, 15, 100)
			rb.Text = "Option 3"

			ws.DefaultRowHeight = 15
			wb.SaveToFile("Result.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace

Sparkline is a tiny chart that can be inserted in cells to represent the trends in a series of values. Spire.XLS enables programmers to select a data cell range and display sparkline in another cell, usually next to data range. This article gives an example in C# and VB.NET to show how this purpose is achieved with a few lines of code.

Code Snippet:

Step 1: Create a new Workbook and load the sample file.

Workbook wb = new Workbook();
wb.LoadFromFile("sample.xlsx");

Step 2: Get the Worksheet from Workbook.

Worksheet ws = wb.Worksheets[0];

Step 3: Set SparklineType as line and apply line sparkline to SparklineCollection.

SparklineGroup sparklineGroup = ws.SparklineGroups.AddGroup(SparklineType.Line);
SparklineCollection sparklines = sparklineGroup.Add();

Step 4: Call SparklineCollection.Add(DateRange, ReferenceRange) mothed get data from a range of cells and display sparkline chart inside another cell, e.g., a sparkline in E2 shows the trend of values from A2 to D2.

sparklines.Add(ws["A2:D2"], ws["E2"]);
sparklines.Add(ws["A3:D3"], ws["E3"]);
sparklines.Add(ws["A4:D4"], ws["E4"]);
sparklines.Add(ws["A5:D5"], ws["E5"]);

Step 5: Save the file.

wb.SaveToFile("output.xlsx",ExcelVersion.Version2010);

Output:

How to Insert Sparkline in Excel in C#, VB.NET

Full Code:

[C#]
using Spire.Xls;
namespace InsertSparkline
{
    class Program
    {

        static void Main(string[] args)
        {

            Workbook wb = new Workbook();
            wb.LoadFromFile("sample.xlsx");
            Worksheet ws = wb.Worksheets[0];

            SparklineGroup sparklineGroup = ws.SparklineGroups.AddGroup(SparklineType.Line);
            SparklineCollection sparklines = sparklineGroup.Add();
            sparklines.Add(ws["A2:D2"], ws["E2"]);
            sparklines.Add(ws["A3:D3"], ws["E3"]);
            sparklines.Add(ws["A4:D4"], ws["E4"]);
            sparklines.Add(ws["A5:D5"], ws["E5"]);

            wb.SaveToFile("output.xlsx", ExcelVersion.Version2010);

        }
    }
}
[VB.NET]
Imports Spire.Xls
Namespace InsertSparkline
	Class Program

		Private Shared Sub Main(args As String())

			Dim wb As New Workbook()
			wb.LoadFromFile("sample.xlsx")
			Dim ws As Worksheet = wb.Worksheets(0)

			Dim sparklineGroup As SparklineGroup = ws.SparklineGroups.AddGroup(SparklineType.Line)
			Dim sparklines As SparklineCollection = sparklineGroup.Add()
			sparklines.Add(ws("A2:D2"), ws("E2"))
			sparklines.Add(ws("A3:D3"), ws("E3"))
			sparklines.Add(ws("A4:D4"), ws("E4"))
			sparklines.Add(ws("A5:D5"), ws("E5"))

			wb.SaveToFile("output.xlsx", ExcelVersion.Version2010)

		End Sub
	End Class
End Namespace
page 54