Columns are widely used to set page layout, for which could split text into two or more columns so that the text could flow from one column to the next on the same page. Using Spire.Doc, we could achieve this feature and add a line between columns at the same time. This article is going to introduce how to split text into two columns and add line between them.

Note: please download the latest version of Spire.Doc and add Spire.Doc .dll as reference of Visual Studio.

Step 1: Create a new document and load from file

Document document = new Document();
document.LoadFromFile("S.docx");

Step 2: Add a column to section one, set the width of columns and the spacing between columns. Here we set width as 100f and spacing as 20f.

document.Sections[0].AddColumn(100f, 20f);

Step 3: Add a line between the two columns

document.Sections[0].PageSetup.ColumnsLineBetween = true;

Step 4: Save the document and launch to see effects

document.SaveToFile("result.docx",FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");

Before adding the columns:

How to split text into two columns and add line between them

Effects:

How to split text into two columns and add line between them

Full Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;

namespace Column
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();

            document.LoadFromFile("S.docx");

            document.Sections[0].AddColumn(100f, 20f);
        
            document.Sections[0].PageSetup.ColumnsLineBetween = true;
            
            document.SaveToFile("result.docx",FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");

        }
    }
}

Text Box has been widely used in word documents to present additional information to readers. As a powerful and easy to use .NET word component, Spire.Doc has powerful function to work with text box. We have already showed you how to insert text box to word document and extract Text from Text Boxes in Word document. In this article let's see how to remove text box from word document in C#.

Spire.Doc supports to remove the particular text box or clear all the text boxes from the word documents. We will show you the details as below. Firstly, check the original word document contains three text boxes on it.

How to remove Text Box from word document in C#

Here comes to the steps of how to remove the text box from word document by using the class of TextBoxes.

Step 1: Create a new document and load from file.

Document Doc = new Document();
Doc.LoadFromFile("Sample.docx");

Step 2: Remove the first text box by using the class of TextBoxes.

Doc.TextBoxes.RemoveAt(0);

Step 3: Save and launch the file.

Doc.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");

Effective screenshot:

How to remove Text Box from word document in C#

If you want to clear all the text boxes at one time, the following code snippet will fulfill it.

Screenshot after clear all the text boxes:

Doc.TextBoxes.Clear();

How to remove Text Box from word document in C#

Full codes:

namespace Removetextbox
{
    class Program
    {
        static void Main(string[] args)
        {
            Document Doc = new Document();
            Doc.LoadFromFile("Sample.docx");
            
            Doc.TextBoxes.RemoveAt(0);
            //Doc.TextBoxes.Clear();

            Doc.SaveToFile("result.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("result.docx");

        }
    }
}

Merge cells in grid via Spire.PDF

2015-05-27 03:08:26 Written by Koohji

Grid also offers more flexible resizing behavior than Table and lighter weight then a Table. It derives from the Panel element which is best used inside of forms. This article is mainly talk about how to merge cells in grid via Spire.PDF.

Prerequisite:

  • Download Spire.PDF for .NET (or Spire.Office for .NET) and install it on your system.
  • Add Spire.PDF.dll as reference in the downloaded Bin folder thought the below path: "..\Spire.PDF\Bin\NET4.0\ Spire.PDF.dll".
  • Check the codes as below in C#:

Here are the detail steps:

Step 1: Create a new PDF document and add a new page.

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

Step 2: Add a new grid with 5 columns and 2 rows, and set height and width.

PdfGrid grid = new PdfGrid();
grid.Columns.Add(5);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
for (int j = 0; j < grid.Columns.Count;j++)
{
  grid.Columns[j].Width = width * 0.20f;
}

 PdfGridRow row0 = grid.Rows.Add();
 PdfGridRow row1 = grid.Rows.Add();
 float height = 20.0f;
 for (int i = 0; i < grid.Rows.Count; i++)
 {
      grid.Rows[i].Height = height;
 }

Step 3: Draw the current grid.

grid.Draw(page, new PointF(0, 50));

Step 4: Set the font of the grid and fill some content in the cells. Use RowSpan and ColumnSpan to merge certain cells vertically and horizontally.

row0.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
row1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Italic), true);

row0.Cells[0].Value = "Corporation";
row0.Cells[0].RowSpan = 2;

row0.Cells[1].Value = "B&K Undersea Photo";
row0.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
row0.Cells[1].ColumnSpan = 3;

row0.Cells[4].Value = "World";
row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
row0.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
row0.Cells[4].Style.BackgroundBrush = PdfBrushes.LightGreen;

row1.Cells[1].Value = "Diving International Unlimited";
row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
row1.Cells[1].ColumnSpan = 4;

Step 5: Draw the new grid and save the file, the review it.

grid.Draw(page, new PointF(0, 100));

doc.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

Following is the result screenshot:

How to merge cells in grid via Spire.PDF

Full Code:

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


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

            PdfGrid grid = new PdfGrid();
            grid.Columns.Add(5);
            float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            for (int j = 0; j < grid.Columns.Count; j++)
            {
                grid.Columns[j].Width = width * 0.20f;
            }

            PdfGridRow row0 = grid.Rows.Add();
            PdfGridRow row1 = grid.Rows.Add();
            float height = 20.0f;
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                grid.Rows[i].Height = height;
            }

            grid.Draw(page, new PointF(0, 50));

            row0.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
            row1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Italic), true);

            row0.Cells[0].Value = "Corporation";
            row0.Cells[0].RowSpan = 2;

            row0.Cells[1].Value = "B&K Undersea Photo";
            row0.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[1].ColumnSpan = 3;

            row0.Cells[4].Value = "World";
            row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            row0.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row0.Cells[4].Style.BackgroundBrush = PdfBrushes.LightGreen;

            row1.Cells[1].Value = "Diving International Unlimited";
            row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            row1.Cells[1].ColumnSpan = 4;

            grid.Draw(page, new PointF(0, 100));

            doc.SaveToFile("result.pdf");
            System.Diagnostics.Process.Start("result.pdf");
        }
    }
}

Table in word document can make your data more logical and uncluttered, this article is talk about set absolute position of table in word document via Spire.Doc. Here try to realize placing a table on the right of an image on header.

Here are the steps:

Step 1: Create a new word document and add new section.

Document doc = new Document();
Section sec = doc.AddSection();

Step 2: Create header on Section[0].

HeaderFooter header = doc.Sections[0].HeadersFooters.Header;

Step 3: Add new paragraph on header and set HorizontalAlignment of the paragraph as left.

Paragraph paragraph = header.AddParagraph();
paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;

Step 4: Load an image for the paragraph.

DocPicture headerimage = paragraph.AppendPicture(Image.FromFile(@"1.png"));

Step 5: Add a table of 4 rows and 2 columns.

Table table = header.AddTable();
table.ResetCells(4, 2);

Step 6: Set the position of the table to the right of the image. Set WrapTextAround is true, HorizPositionAbs is outside, VertRelationTo is margin, and VertPosition is 43 to fit the height of the image.

table.TableFormat.WrapTextAround = true;
table.TableFormat.Positioning.HorizPositionAbs = HorizontalPosition.Outside;
table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Margin;
table.TableFormat.Positioning.VertPosition = 43;

Step 7: Then add contents for the table, first column alignment set as left ,second column alignment set as right.

String[][] data = {
                    new string[] {"Spire.Doc.left","Spire XLS.right"},
                    new string[] {"Spire.Presentatio.left","Spire.PDF.right"},
                    new string[] {"Spire.DataExport.left","Spire.PDFViewe.right"},
                    new string []{"Spire.DocViewer.left","Spire.BarCode.right"}
                              };
           
            for (int r = 0; r < 4; r++)
            {
                TableRow dataRow = table.Rows[r];
                for (int c = 0; c < 2; c++)
                {
                    if (c == 0)
                    {
                        Paragraph par = dataRow.Cells[c].AddParagraph();
                        par.AppendText(data[r][c]);
                        par.Format.HorizontalAlignment = HorizontalAlignment.Left;
                        dataRow.Cells[c].Width = 180;
                    }
                    else
                    {
                        Paragraph par = dataRow.Cells[c].AddParagraph();
                        par.AppendText(data[r][c]);
                        par.Format.HorizontalAlignment = HorizontalAlignment.Right;
                        dataRow.Cells[c].Width = 180;
                    }
                }
            }

Step 8: Save the file and review it.

doc.SaveToFile("result.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("result.docx");

Here is the screenshot:

Set position of table in Word Document as outside via Spire.Doc

Full Code:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System;
using System.Drawing;
namespace SetPosition
{
    class Program
    {

        static void Main(string[] args)
        {

            Document doc = new Document();
            Section sec = doc.AddSection();

            HeaderFooter header = doc.Sections[0].HeadersFooters.Header;

            Paragraph paragraph = header.AddParagraph();
            paragraph.Format.HorizontalAlignment = HorizontalAlignment.Left;
            DocPicture headerimage = paragraph.AppendPicture(Image.FromFile(@"1.png"));

            Table table = header.AddTable();
            table.ResetCells(4, 2);

            table.TableFormat.WrapTextAround = true;
            table.TableFormat.Positioning.HorizPositionAbs = HorizontalPosition.Outside;
            table.TableFormat.Positioning.VertRelationTo = VerticalRelation.Margin;
            table.TableFormat.Positioning.VertPosition = 43;


            String[][] data = {
                    new string[] {"Spire.Doc.left","Spire XLS.right"},
                    new string[] {"Spire.Presentatio.left","Spire.PDF.right"},
                    new string[] {"Spire.DataExport.left","Spire.PDFViewe.right"},
                    new string []{"Spire.DocViewer.left","Spire.BarCode.right"}
                              };

            for (int r = 0; r < 4; r++)
            {
                TableRow dataRow = table.Rows[r];
                for (int c = 0; c < 2; c++)
                {
                    if (c == 0)
                    {
                        Paragraph par = dataRow.Cells[c].AddParagraph();
                        par.AppendText(data[r][c]);
                        par.Format.HorizontalAlignment = HorizontalAlignment.Left;
                        dataRow.Cells[c].Width = 180;
                    }
                    else
                    {
                        Paragraph par = dataRow.Cells[c].AddParagraph();
                        par.AppendText(data[r][c]);
                        par.Format.HorizontalAlignment = HorizontalAlignment.Right;
                        dataRow.Cells[c].Width = 180;
                    }
                }
            }
            doc.SaveToFile("result.docx",Spire.Doc.FileFormat.Docx);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}

To display Excel data in a PowerPoint presentation, we can copy and paste the data to a slide as a PowerPoint table, a worksheet object, a picture, or plain text. This article introduces how to insert an Excel sheet in PowerPoint as an OLE object in C# and VB.NET.

In this solution, you'll need to use Spire.XLS to load the Excel file and get the data, and then create OEL object using Spire.Presentation. So, please download Spire.Office and reference the related DLLs in your project.

Workbook book = new Workbook();
book.LoadFromFile(@"data.xlsx");

Step 2: Select the cell range from the first worksheet and save it as image.

Image image = book.Worksheets[0].ToImage(1, 1, 5, 4);

Step 3: Initialize a new instance of Presentation class, add the image to presentation.

Presentation ppt = new Presentation();
IImageData oleImage = ppt.Images.Append(image);

Step 4: Insert an OLE object to presentation based on the Excel data.

Rectangle rec = new Rectangle(60,60,image.Width,image.Height);
using (MemoryStream ms = new MemoryStream())
{
    book.SaveToStream(ms);
    ms.Position = 0;
    Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);
    oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
    oleObject.ProgId = "Excel.Sheet.12";
}

Step 5: Save the PowerPoint file with the specified format.

ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007);

Output:

How to Embed Excel Object into PowerPoint Slide in C#, VB.NET

Entire Code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using Spire.Xls;
using System.Drawing;
using System.IO;
namespace ExceltoPPT
{

    class Program
    {

        static void Main(string[] args)
        {
            Workbook book = new Workbook();
            book.LoadFromFile(@"data.xlsx");
            Image image = book.Worksheets[0].ToImage(1, 1, 5, 4);

            Presentation ppt = new Presentation();
            IImageData oleImage = ppt.Images.Append(image);
            Rectangle rec = new Rectangle(60, 60, image.Width, image.Height);
            using (MemoryStream ms = new MemoryStream())
            {
                book.SaveToStream(ms);
                ms.Position = 0;
                Spire.Presentation.IOleObject oleObject = ppt.Slides[0].Shapes.AppendOleObject("excel", ms.ToArray(), rec);
                oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage;
                oleObject.ProgId = "Excel.Sheet.12";
            }

            ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007);


        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports Spire.Xls
Imports System.Drawing
Imports System.IO
Namespace ExceltoPPT

	Class Program

		Private Shared Sub Main(args As String())
			Dim book As New Workbook()
			book.LoadFromFile("data.xlsx")
			Dim image As Image = book.Worksheets(0).ToImage(1, 1, 5, 4)

			Dim ppt As New Presentation()
			Dim oleImage As IImageData = ppt.Images.Append(image)
			Dim rec As New Rectangle(60, 60, image.Width, image.Height)
			Using ms As New MemoryStream()
				book.SaveToStream(ms)
				ms.Position = 0
				Dim oleObject As Spire.Presentation.IOleObject = ppt.Slides(0).Shapes.AppendOleObject("excel", ms.ToArray(), rec)
				oleObject.SubstituteImagePictureFillFormat.Picture.EmbedImage = oleImage
				oleObject.ProgId = "Excel.Sheet.12"
			End Using

			ppt.SaveToFile("InsertOle.pptx", Spire.Presentation.FileFormat.Pptx2007)


		End Sub
	End Class
End Namespace

How to add a trendline in a chart

2015-05-20 03:44:18 Written by Koohji

A trendline is used to show the trend of data series and predict future tendency. Totally, there are six different types: linear trendline, logarithmic trendline, polynomial trendline, power trendline, exponential trendline, and moving average trendline. We may choose different trendline based on the data type we have for different trendline has different advantages to show trend.

For example, a linear trendline works well to show the increase or decrease of data at a steady rate while a logarithmic trendline is often used to show the rate of change in the data increases or decreases quickly and then levels out.

Spire.XLS supports to add all of those six trendlines in charts. This article is going to show how to add trendlines in visual studio.

Before adding trendlines

How to add a trendline in a chart

After adding trendlines

How to add a trendline in a chart

Step 1: Load the workbook and create a sheet

Workbook workbook = new Workbook();
workbook.LoadFromFile("S2.xlsx");
Worksheet sheet = workbook.Worksheets[0];

Step 2: Select targeted chart, add trendline and set its type

//select chart and set logarithmic trendline
Chart chart = sheet.Charts[0];
chart.Series[0].TrendLines.Add(TrendLineType.Logarithmic);
//select chart and set moving_average trendline
Chart chart1 = sheet.Charts[1];
chart1.Series[0].TrendLines.Add(TrendLineType.Moving_Average);
//select chart and set linear trendline
Chart chart2 = sheet.Charts[2];
chart2.Series[0].TrendLines.Add(TrendLineType.Linear);
//select chart and set exponential trendline
Chart chart3 = sheet.Charts[3];
chart3.Series[0].TrendLines.Add(TrendLineType.Exponential);

Step 3: Save and launch the document

workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010);
System.Diagnostics.Process.Start("S3.xlsx");

Full code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

namespace TradeLine
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("S2.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            
            Chart chart = sheet.Charts[0];
            chart.Series[0].TrendLines.Add(TrendLineType.Logarithmic);
            
            Chart chart1 = sheet.Charts[1];
            chart1.Series[0].TrendLines.Add(TrendLineType.Moving_Average);
            
            Chart chart2 = sheet.Charts[2];
            chart2.Series[0].TrendLines.Add(TrendLineType.Linear);
            
            Chart chart3 = sheet.Charts[3];
            chart3.Series[0].TrendLines.Add(TrendLineType.Exponential);

            workbook.SaveToFile("S3.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("S3.xlsx");

        }
    }
}

Please note that we cannot add a trendline to data series in a stacked, 3-D, radar, pie, surface, or doughnut chart because those types of chart don't support trendline.

With the help of Spire.Presentation, developers can insert new hyperlink into PowerPoint Presentation and edit the existing hyperlinks in C# and VB.NET. This article will show you how to add hyperlink to the existing text on presentation slides.

Firstly check the screenshot of the original presentation slides.

How to add hyperlink to the existing text on presentation slides in C#

Here comes to the steps of how to adding hyperlink to an existing text in Presentation slide:

Step 1: Create a new presentation document and load from file.

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

Step 2: Find the text we want to add link to it.

IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
string temp = tp.Text;

Step 3: Adding the hyperlink to the existing text.

//split the original text
string textToLink = "Spire.Presentation";
string[] strSplit = temp.Split(new string[] { "Spire.Presentation" }, StringSplitOptions.None);

//Clear all text
tp.TextRanges.Clear();

//Add new text
TextRange tr = new TextRange(strSplit[0]);
tp.TextRanges.Append(tr);

//Add the hyperlink
tr = new TextRange(textToLink);
tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";

tp.TextRanges.Append(tr);

Step 4: Save the document to file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Effective screenshot after adding the hyperlink to the existing text:

How to add hyperlink to the existing text on presentation slides in C#

Full codes:

using Spire.Presentation;
using System;
namespace AddHyperlink
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();
            ppt.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);

            IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
            TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
            string temp = tp.Text;

            //split the original text
            string textToLink = "Spire.Presentation";
            string[] strSplit = temp.Split(new string[] { "Spire.Presentation" }, StringSplitOptions.None);

            //Clear all text
            tp.TextRanges.Clear();

            //Add new text
            TextRange tr = new TextRange(strSplit[0]);
            tp.TextRanges.Append(tr);

            //Add the hyperlink
            tr = new TextRange(textToLink);
            tr.ClickAction.Address = "http://www.e-iceblue.com/Introduce/presentation-for-net-introduce.html";

            tp.TextRanges.Append(tr);

            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }
    }
}

To emphasize and beautify a set of characters or sentence, applying a border around the characters or sentence is a good option. Spire.Doc enables developers to achieve this feature in C#. And there are plenty of built-in border styles available, such as: Wave, Hairline, DotDash, DashSmallGap, DashLargeGap, DoubleWave, DashDotStroker, Emboss3D, Engrave3D, TwistedLines1 and so on. The following codes show how to achieve character border with some border styles mentioned above:

Note: Before start, please make sure that Visual Studio and Spire.Doc have been installed properly. We will use Spire.Doc .dll as reference.

Step 1: Load word document

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

Step 2: Add the characters needed to apply a border and set the border style

//DashSmallGap Border
Paragraph para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
TextRange tr = para.AppendText("Spire.Doc for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
tr.CharacterFormat.Border.Color = Color.Green;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.DarkKhaki; 
para.AppendBreak(BreakType.LineBreak);

//Wave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.PDF for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
tr.CharacterFormat.Border.Color = Color.Aqua;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.BurlyWood;
para.AppendBreak(BreakType.LineBreak);

//Emboss3D Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.XLS for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
tr.CharacterFormat.FontSize = 24;
para.AppendBreak(BreakType.LineBreak);

//DashDotStroker Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Office for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
tr.CharacterFormat.Border.Color = Color.Olive;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Olive;
para.AppendBreak(BreakType.LineBreak);

//DoubleWave Border
para = section.AddParagraph();
para.Format.HorizontalAlignment = HorizontalAlignment.Left;
tr = para.AppendText("Spire.Presentation for .Net");
tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
tr.CharacterFormat.Border.Color = Color.Blue;
tr.CharacterFormat.FontSize = 24;
tr.CharacterFormat.TextColor = Color.Blue;
para.AppendBreak(BreakType.LineBreak);

Step 3: Save and launch word document

doc.SaveToFile("S1.docx", FileFormat.Docx);
System.Diagnostics.Process.Start("S1.docx");

Effect of screenshot:

How to apply a border around characters or sentence in word document

Full Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            Section section = doc.AddSection();

            //DashSmallGap Border
            Paragraph para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            TextRange tr = para.AppendText("Spire.Doc for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashSmallGap;
            tr.CharacterFormat.Border.Color = Color.Green;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.DarkKhaki; 
            para.AppendBreak(BreakType.LineBreak);

            //Wave Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.PDF for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Wave;
            tr.CharacterFormat.Border.Color = Color.Aqua;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.BurlyWood;
            para.AppendBreak(BreakType.LineBreak);

            //Emboss3D Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.XLS for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.Emboss3D;
            tr.CharacterFormat.FontSize = 24;
            para.AppendBreak(BreakType.LineBreak);

            //DashDotStroker Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.Office for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DashDotStroker;
            tr.CharacterFormat.Border.Color = Color.Olive;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.Olive;
            para.AppendBreak(BreakType.LineBreak);

            //DoubleWave Border
            para = section.AddParagraph();
            para.Format.HorizontalAlignment = HorizontalAlignment.Left;
            tr = para.AppendText("Spire.Presentation for .Net");
            tr.CharacterFormat.Border.BorderType = Spire.Doc.Documents.BorderStyle.DoubleWave;
            tr.CharacterFormat.Border.Color = Color.Blue;
            tr.CharacterFormat.FontSize = 24;
            tr.CharacterFormat.TextColor = Color.Blue;
            para.AppendBreak(BreakType.LineBreak);

            doc.SaveToFile("S1.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("S1.docx");

        }
    }
}

Sometimes in word files, we type another language rather than default, and need spellers and other proofing tools adjust to the language we typed.

This article is talking about how to alter language dictionary as non-default language via Spire.Doc. Here take English as default language and alter to Spanish in Peru as an example.

As for more language information, refer this Link to Microsoft Locale ID Values.

Here are the steps:

Step 1: Create a new word document.

Document document = new Document();

Step 2: Add new section and paragraph to the document.

Section sec = document.AddSection();
Paragraph para = sec.AddParagraph();

Step 3: Add a textRange for the paragraph and append some Peru Spanish words.

TextRange txtRange = para.AppendText("corrige según diccionario en inglés");
txtRange.CharacterFormat.LocaleIdASCII = 10250;

Step 4: Save and review.

document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");

Here is the result screenshot.

How to alter Language dictionary via Spire.Doc

Full Code:

using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace AlterLang
{

    class Program
    {

        static void Main(string[] args)
        {
            Document document = new Document();
            Section sec = document.AddSection();
            Paragraph para = sec.AddParagraph();
            TextRange txtRange = para.AppendText("corrige según diccionario en inglés");
            txtRange.CharacterFormat.LocaleIdASCII = 10250;
            document.SaveToFile("result.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}

To emphasize some words or phrases in a sentence, most probably you will set different formats such as font type, color, and size to these parts. When we programmatically insert a sentence with various kinds of font styles into a PowerPoint slide, it is an easy task if we format the text at the first place and then append the text to a paragraph. In this article, we attach more importance to introduce how to mix font styles within a single TextRange on an existing PowerPoint slide.

Test File:

As is shown in test file, all words in this TextRange are in the same font style. Now we would like to make some changes.

How to Mix Font Styles within a Single TextRange in C#, VB.NET

Code Snippet:

Step 1: Create a new PowerPoint document and load the test file.

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

Step 2: Get the shape from PowerPoint slide, get the text from shape and save to a new string variable.

IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
string originalText = shape.TextFrame.Text;

Step 3: Split the string by specified words and return substrings to a string array.

string[] splitArray = originalText.Split(new string[] { "bold", "red","underlined","bigger font size" }, StringSplitOptions.None);

Step 4: Remove the paragraph from TextRange.

TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
tp.TextRanges.Clear();

Step 5: Append normal text that is in front of ‘bold’ to the paragraph.

TextRange tr = new TextRange(splitArray[0]);
tp.TextRanges.Append(tr);

Step 6: Set font style of the text ‘bold’ as bold, and append it to the paragraph.

tr = new TextRange("bold");
tr.IsBold = TriState.True;
tp.TextRanges.Append(tr);

Step 7: Repeat step 5 and step 6 to append the rest normal texts and formatted texts to the paragraph.

//normal text
tr = new TextRange(splitArray[1]);
tp.TextRanges.Append(tr);
//red text
tr = new TextRange("red");
tr.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
tr.Format.Fill.SolidColor.Color = Color.Red;
tp.TextRanges.Append(tr);
//normal text
tr = new TextRange(splitArray[2]);
tp.TextRanges.Append(tr);
//underline text
tr = new TextRange("underlined");
tr.TextUnderlineType = TextUnderlineType.Single;
tp.TextRanges.Append(tr);
//normal text
tr = new TextRange(splitArray[3]);
tp.TextRanges.Append(tr);
//bigger size text
tr = new TextRange("bigger font size");
tr.FontHeight = 35;
tp.TextRanges.Append(tr);
//normal text
tr = new TextRange(splitArray[4]);
tp.TextRanges.Append(tr);

Step 8: Save the file.

ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

Output:

How to Mix Font Styles within a Single TextRange in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using System;
using System.Drawing;
namespace MixFontStyle
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation("Sample.pptx", FileFormat.Pptx2010);
            IAutoShape shape = ppt.Slides[0].Shapes[0] as IAutoShape;
            string originalText = shape.TextFrame.Text;
            string[] splitArray = originalText.Split(new string[] { "bold", "red", "underlined", "bigger font size" }, StringSplitOptions.None);
            TextParagraph tp = shape.TextFrame.TextRange.Paragraph;
            tp.TextRanges.Clear();
            //normal text
            TextRange tr = new TextRange(splitArray[0]);
            tp.TextRanges.Append(tr);
            //bold text
            tr = new TextRange("bold");
            tr.IsBold = TriState.True;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[1]);
            tp.TextRanges.Append(tr);
            //red text
            tr = new TextRange("red");
            tr.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
            tr.Format.Fill.SolidColor.Color = Color.Red;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[2]);
            tp.TextRanges.Append(tr);
            //underline text
            tr = new TextRange("underlined");
            tr.TextUnderlineType = TextUnderlineType.Single;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[3]);
            tp.TextRanges.Append(tr);
            //bigger size text
            tr = new TextRange("bigger font size");
            tr.FontHeight = 35;
            tp.TextRanges.Append(tr);
            //normal text
            tr = new TextRange(splitArray[4]);
            tp.TextRanges.Append(tr);
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010);

        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing
Namespace MixFontStyle
	Class Program
		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation("Sample.pptx", FileFormat.Pptx2010)
			Dim shape As IAutoShape = TryCast(ppt.Slides(0).Shapes(0), IAutoShape)
			Dim originalText As String = shape.TextFrame.Text
			Dim splitArray As String() = originalText.Split(New String() {"bold", "red", "underlined", "bigger font size"}, StringSplitOptions.None)
			Dim tp As TextParagraph = shape.TextFrame.TextRange.Paragraph
			tp.TextRanges.Clear()
			'normal text
			Dim tr As New TextRange(splitArray(0))
			tp.TextRanges.Append(tr)
			'bold text
			tr = New TextRange("bold")
			tr.IsBold = TriState.[True]
			tp.TextRanges.Append(tr)
			'normal text
			tr = New TextRange(splitArray(1))
			tp.TextRanges.Append(tr)
			'red text
			tr = New TextRange("red")
			tr.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid
			tr.Format.Fill.SolidColor.Color = Color.Red
			tp.TextRanges.Append(tr)
			'normal text
			tr = New TextRange(splitArray(2))
			tp.TextRanges.Append(tr)
			'underline text
			tr = New TextRange("underlined")
			tr.TextUnderlineType = TextUnderlineType.[Single]
			tp.TextRanges.Append(tr)
			'normal text
			tr = New TextRange(splitArray(3))
			tp.TextRanges.Append(tr)
			'bigger size text
			tr = New TextRange("bigger font size")
			tr.FontHeight = 35
			tp.TextRanges.Append(tr)
			'normal text
			tr = New TextRange(splitArray(4))
			tp.TextRanges.Append(tr)
			ppt.SaveToFile("Result.pptx", FileFormat.Pptx2010)

		End Sub
	End Class
End Namespace
page 51