C#/VB.NET: Edit Hyperlinks in Word

2023-01-29 08:50:00 Written by Koohji

In MS Word, a hyperlink is a clickable link that allows you to jump to a web page, a file, an email address, or even another location in the same document. It is undeniable that adding hyperlinks in Word documents is one of the most common operations in daily work, but there are times when you may also need to change the address or update the display text of an existing hyperlink. This article will demonstrate how to programmatically edit a hyperlink in a Word document using Spire.Doc for .NET.

Install Spire.Doc for .NET

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

Edit a Hyperlink in a Word Document in C# and VB.NET

A hyperlink consists of two basic parts: the hyperlink address (URL) and its display text. With Spire.Doc for .NET, you are allowed to modify both the address and display text of an existing hyperlink using Field.Code and Field.FieldText properties. The detailed steps are as follows.

  • Create a Document object.
  • Load a sample Word document using Document.LoadFromFile() method.
  • Create an object of List<Field>.
  • Traverse through all body child objects of sections in the sample document to find all hyperlinks.
  • Modify the address (URL) of a specified hyperlink using Field.Code property.
  • Modify the display text of a specified hyperlink using Field.FieldText property.
  • Save the document to another file using Document.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Collections.Generic;

namespace ModifyHyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Document object
            Document doc = new Document();

            //Load a sample Word document
            doc.LoadFromFile("Hyperlink.docx");

            //Create an object of List 
            List<Field> hyperlinks = new List<Field>();

            //Loop through the items in the sections to find all hyperlinks
            foreach (Section section in doc.Sections)
            {
                foreach (DocumentObject sec in section.Body.ChildObjects)
                {
                    if (sec.DocumentObjectType == DocumentObjectType.Paragraph)
                    {
                        //Loop through all paragraphs in the sections
                        foreach (DocumentObject para in (sec as Paragraph).ChildObjects)
                        {
                            if (para.DocumentObjectType == DocumentObjectType.Field)
                            {
                                Field field = para as Field;

                                if (field.Type == FieldType.FieldHyperlink)
                                {
                                    hyperlinks.Add(field);
                                }
                            }
                        }
                    }
                }
            }
            //Modify the address (URL) of the first hyperlink 
            hyperlinks[0].Code = "HYPERLINK \"" + "https://www.e-iceblue.com/Introduce/word-for-net-introduce.html" + "\"";

            //Modify the display text of the first hyperlink 
            hyperlinks[0].FieldText = "Spire.Doc for .NET";

            //Save the result document
            doc.SaveToFile("EditHyperlinks.docx", FileFormat.Docx);
        }
    }
}

C#/VB.NET: Edit Hyperlinks in Word

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.

Hyperlinks can point to files, emails, websites, imagers or video when readers click on it. Hyperlinks are widely used in word document for it is very convenient to direct readers to related, useful content. By using Spire.Doc, developers can add hyperlinks, finding hyperlinks and modify hyperlinks. This article will show you how to find all the existing hyperlinks in a word document in C#.

Download and install Spire.Doc for .NET and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: "..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to finding hyperlinks in C#.

Firstly, view the word document which contains many hyperlinks:

Finding Hyperlinks in a word document

Please check the code of how to find all the hyperlinks in word document:

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Collections.Generic;
using System.Drawing;
namespace FindHyperlink
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document();
            doc.LoadFromFile("Spire.docx");
            List hyperlinks = new List();
            foreach (Section section in doc.Sections)
            {
                foreach (DocumentObject sec in section.Body.ChildObjects)
                {
                    if (sec.DocumentObjectType == DocumentObjectType.Paragraph)
                    {
                        foreach (DocumentObject para in (sec as Paragraph).ChildObjects)
                        {
                            if (para.DocumentObjectType == DocumentObjectType.Field)
                            {
                                Field field = para as Field;

                                if (field.Type == FieldType.FieldHyperlink)
                                {
                                    hyperlinks.Add(field);
                                }

                            }
                        }
                    }
                }
            }
        }

The effective screenshot of the finding hyperlinks:

Finding Hyperlinks in a word document

Save a PDF file to a stream.

PDF documents are ubiquitous in modern applications, and efficient handling of these files is crucial for developers. In C#, working with PDF files using streams offers memory efficiency and flexibility, especially in web applications, cloud services, or when handling dynamic content.

Spire.PDF, a robust PDF processing library, simplifies these operations with its intuitive API. This article explores how to create, load, and save PDF documents using streams in C#, covering the following aspects.

Why Use Streams for PDF Processing?

Stream-based PDF handling in C# offers significant advantages for modern applications:

  • Memory Efficiency: Process large PDFs without loading entire files into memory.
  • Scalability: Ideal for web applications and cloud environments.
  • Reduced I/O Operations: Minimize disk reads/writes for faster performance.
  • Flexibility: Integrate with APIs, databases, and cloud storage seamlessly.

Getting Started with Spire.PDF

Spire.PDF is a feature-rich library that simplifies PDF manipulation in .NET applications. Here’s how to install it:

  • Via NuGet Package Manager (Recommended):

    In Package Manager Console, run the following command to install:

    PM> Install-Package Spire.PDF 
  • 2Manual Installation:

    Download the DLL files from the official website and add a reference to your project.

Create a PDF File and Save it to Stream in C#

This task can be divided into three main parts. Follow the steps below to dynamically create a PDF file and save it to the stream.

  • Create a PDF document.
    • Initialize an instance of the PdfDocument class to represent a PDF file.
    • Add a page to the PDF file.
  • Add content to the PDF (in this case, a simple text string).
  • 3. Save to a Stream
    • Initialize an instance of the FileStream or the MemoryStream class.
    • Call the PdfDocument.SaveToStream(Stream stream) method to save the PDF file to stream.

Code Example:

  • C#
using Spire.Pdf;
using System.IO;
using Spire.Pdf.Graphics;
using System.Drawing;

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

            // Create a PdfDocument instance
            PdfDocument pdf = new PdfDocument();

            // Add a page
            PdfPageBase page = pdf.Pages.Add();

            // Draw text on the page
            page.Canvas.DrawString("Hello, World!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Blue),
                                   100, 100);

            // Save the PDF file to Stream
            FileStream toStream = new FileStream("SavePdfToStream.pdf", FileMode.OpenOrCreate);
            pdf.SaveToStream(toStream);
            toStream.Close();
            pdf.Close();
        }
    }
}

A screenshot of the generated PDF:

Save a PDF file to a stream.

Load a PDF from Stream in C#

Streams provide a flexible way to read PDFs from different sources, such as:

  • FileStream: represents a stream of data stored in a physical file.
  • MemoryStream: represents a stream of data stored in memory (RAM).

Their differences lie in:

Feature FileStream MemoryStream
Storage Disk Memory (RAM)
Performance Slower (disk I/O) Faster (no disk access)
Use Case Persistent files, large data Temporary data, in-memory processing
Size Limit Limited by disk space Limited by available RAM

The PdfDocument.LoadFromStream(Stream stream) method of Spire.PDF library supports loading an existing PDF from a stream directly. The code example is shown below:

  • C#
using Spire.Pdf;
using System.IO;

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

            // Create a PdfDocument instance
            PdfDocument pdf = new PdfDocument();

            // Load PDF file from memory stream
            MemoryStream stream = new MemoryStream();
            File.OpenRead("sample.pdf").CopyTo(stream);
            pdf.LoadFromStream(stream);

            // Load PDF file from file stream
            //FileStream stream = File.OpenRead("sample.pdf");
            //pdf.LoadFromStream(stream);

            // Save the PDF file to disk
            pdf.SaveToFile("LoadPdfFromStream.pdf", FileFormat.PDF);
            pdf.Close();
        }
    }
}

A screenshot of the loaded PDF file:

Load a PDF file from memory stream.

Advanced Example: Merge Multiple PDFs by Streams

By mastering the skills of loading and saving PDFs using streams, you can combine it with other PDF processing functions to perform advanced PDF stream operations.

Below is an example on how to combine multiple PDFs into a single document using streams:

  • C#
using System.IO;
using Spire.Pdf;

namespace MergePDFsByStream
{
    class Program
    {
        static void Main(string[] args)
        {
            // Specify the files to be merged
            string[] pdfFiles = {
                "MergePdfsTemplate_1.pdf",
                "MergePdfsTemplate_2.pdf",
                "MergePdfsTemplate_3.pdf"
            };

            // Initialize FileStreams for input PDF files
            FileStream[] streams = new FileStream[pdfFiles.Length];
            for (int i = 0; i < pdfFiles.Length; i++)
            {
                streams[i] = File.OpenRead(pdfFiles[i]);
            }

            // Merge the PDF files using the streams
            PdfDocumentBase pdf = PdfDocument.MergeFiles(streams);

            // Save the merged PDF file
            pdf.Save("MergePDFByStream.pdf", FileFormat.PDF);

        }
    }
}

Conclusion

Working with PDF files in streams using C# and Spire.PDF provides a flexible and efficient way to handle document processing tasks. Whether you’re loading, modifying existing PDF documents, or saving PDF files, streams offer a memory-efficient alternative to traditional file-based approaches.

To learn more advanced PDF processing features, explore Spire.PDF’s official documentation.

Get a Free License

To fully experience the capabilities of Spire.PDF for .NET without any evaluation limitations, you can request a free 30-day trial license.

XLS and XLSX are two different file formats for Microsoft Excel spreadsheets. XLS is the default file format for Microsoft Excel 2003 and earlier versions, while XLSX is the default file format for Microsoft Excel 2007 and later versions. In some cases, developers may need to convert between Excel XLS and XLSX file formats. In this article, we will explain how to convert XLS to XLSX or XLSX to XLS 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

Convert XLS to XLSX in C# and VB.NET

The following are the steps to convert an XLS file to XLSX format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLS file using Workbook.LoadFromFile() method.
  • Save the XLS file to XLSX format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsToXlsx
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLS file
            workbook.LoadFromFile("Input.xls");

            //Convert the file to XLSX format
            workbook.SaveToFile("ToXlsx.xlsx", ExcelVersion.Version2016);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

Convert XLSX to XLS in C# and VB.NET

The following are the steps to convert an XLSX file to XLS format using Spire.XLS for .NET:

  • Create a Workbook instance.
  • Load the XLSX file using Workbook.LoadFromFile() method.
  • Save the XLSX file to XLS format using Workbook.SaveToFile(string, ExcelVersion) method.
  • C#
  • VB.NET
using Spire.Xls;

namespace ConvertXlsxToXls
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();
            //Load an XLSX file
            workbook.LoadFromFile("Input.xlsx");

            //Convert the file to XLS format
            workbook.SaveToFile("ToXls.xls", ExcelVersion.Version97to2003);
        }
    }
}

C#/VB.NET: Convert XLS to XLSX and Vice versa

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.

Traverse through the cells of Table

2014-06-19 07:17:19 Written by Koohji

Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. There are documents on our site introducing how to insert table and edit table in PowerPoint file. In this document, I will introduce you how to traverse through the cells of table.

It is very easy to traverse through the cells of table using Spire.Presentation. Just get the row collection using the property - TableRows of Table. Then traverse through each cell of each row. Or you can get the column collection using the property – ColumnsList of Table. Then traverse through each cell of each column.

Step 1: Create Presentation instance and load file.

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

Step 2: Get the table in PowerPoint file.

foreach (IShape shape in presentation.Slides[0].Shapes)
{
    if (shape is ITable)
    {
        table = (ITable)shape;
    }
}

Step 3: Traverse through the rows in row collection and traverse through each cell in each row.

foreach (TableRow row in table.TableRows)
{
    foreach (Cell cell in row)
    {
        //print the data in cell
        Console.Write("{0,15}", cell.TextFrame.Text);
    }
    Console.WriteLine();
}

Download and install Spire.Presentation for .NET and refer to below code to traverse through the cells in PowerPoint document.

Screenshots and Full code:

Traverse through the cells of Table

Traverse through the cells of Table

[C#]
using Spire.Presentation;
using System;

namespace Trasverse
{

    class Program
    {

        static void Main(string[] args)
        {
            //create Presentation instance and load file
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("table.pptx");

            ITable table = null;

            //get the table
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //traverse through the cells of table
                    foreach (TableRow row in table.TableRows)
                    {
                        foreach (Cell cell in row)
                        {
                            //print the data in cell
                            Console.Write("{0,15}", cell.TextFrame.Text);
                        }
                        Console.WriteLine();
                    }
                }
            }
            Console.ReadLine();

        }

    }
}

If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.

How to Remove Row or Column in Table

2014-06-12 07:03:21 Written by Koohji

We have previously introduced how to insert a custom table and how to edit a table in PowerPoint documents. Now, we are going to make a brief introduction about how to remove the rows or columns that belong to an existing table.

Spire.Presentation for .NET, built to provide flexible PowerPoint document handling capabilities, allows developers to add a table to a slide and perform some basic operations as removing rows and columns in the table in an easy way.

Step 1: Create a PowerPoint instance and load a sample file.

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

Step 2: Find the table and remove the second column and second row.

ITable table = null;  
foreach (IShape shape in presentation.Slides[0].Shapes)
{
  if (shape is ITable)
  {
    table = (ITable)shape;
    table.ColumnsList.RemoveAt(1, false)    
    table.TableRows.RemoveAt(1, false);       
  }
}

Step 3: Save the document.

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

The sample table with the second row and second column highlighted.

Remove Row or Column in Table

Result:

Remove Row or Column in Table

Full C# code:

using Spire.Presentation;

namespace RemoveRow
{

    class Program
    {

        static void Main(string[] args)
        {
            //create a PPT document
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("table.pptx");

            //get the table in PPT document
            ITable table = null;
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //remove the second column
                    table.ColumnsList.RemoveAt(1, false);

                    //remove the second row
                    table.TableRows.RemoveAt(1, false);
                }
            }
            //save the document
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }

    }
}

Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. In this document, I will introduce you how to create PowerPoint file and save it to stream. I also introduce you how to load PowerPoint file from stream. Check it below.

Create PowerPoint file and save it to Stream

Step 1: Create Presentation instance.

Presentation presentation = new Presentation();

Step 2: Set background image.

string ImageFile = "bg.png";
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

Step 3: Add text to PowerPoint document.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 450, 150));
shape.Fill.FillType = FillFormatType.None;
shape.ShapeStyle.LineColor.Color = Color.White;

//add text to shape
shape.TextFrame.Text = "This demo shows how to Create PowerPoint file and save it to Stream.";
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

Step 4: Save document to stream.

FileStream to_stream = new FileStream("To_stream.pptx", FileMode.Create);
presentation.SaveToFile(to_stream, FileFormat.Pptx2010);
to_stream.Close();

Preview the generated PowerPoint file:

Save and Load PowerPoint file to/from Stream

Load PowerPoint file from stream.

Step 1: Create Presentation instance.

Presentation presentationLoad = new Presentation();

Step 2: Load PowerPoint file from stream.

FileStream from_stream = File.OpenRead("sample.pptx");
presentationLoad.LoadFromStream(from_stream, FileFormat.Pptx2010);

Step 3: Save the document.

presentationLoad.SaveToFile("From_stream.pptx",FileFormat.Pptx2010);
from_stream.Dispose();

Preview the PowerPoint file:

Save and Load PowerPoint file to/from Stream

Full code:

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

            //A: create PowerPoint file and save it to stream
            Presentation presentation = new Presentation();

            //set background Image
            string ImageFile = "bg.png";
            RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
            presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
            presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

            //append new shape
            IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 450, 150));
            shape.Fill.FillType = FillFormatType.None;
            shape.ShapeStyle.LineColor.Color = Color.White;

            //add text to shape
            shape.TextFrame.Text = "This demo shows how to Create PowerPoint file and save it to Stream.";
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid;
            shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black;

            //save to Stream
            FileStream to_stream = new FileStream("To_stream.pptx", FileMode.Create);
            presentation.SaveToFile(to_stream, FileFormat.Pptx2010);
            to_stream.Close();

            System.Diagnostics.Process.Start("To_stream.pptx");


            //B: Load PowerPoint file from Stream
            Presentation presentationLoad = new Presentation();

            //load PowerPoint file from stream
            FileStream from_stream = File.OpenRead("sample.pptx");
            presentationLoad.LoadFromStream(from_stream, FileFormat.Pptx2010);

            //save the document
            presentationLoad.SaveToFile("From_stream.pptx", FileFormat.Pptx2010);
            from_stream.Dispose();

            System.Diagnostics.Process.Start("From_stream.pptx");


        }
    }
}

If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.

How to Remove Page breaks in C#

2014-06-11 08:24:54 Written by Koohji

In Word document, users can add new page break or remove existing page breaks. This sample shows how to remove page breaks from the word document by using Spire.Doc. Spire.Doc supports to remove the page breaks from the word document from the format of .docx, .doc, and RTF etc.

Firstly make sure Spire.Doc for .NET has been installed correctly and then add Spire.Doc.dll as reference in the downloaded Bin folder though the below path: ".. \Spire.Doc\Bin\NET4.0\ Spire.Doc.dll". Here comes to the details of how to remove page breaks in C#.

//Create a new word document and load from the file.
Document document = new Document();
document.LoadFromFile("sample.docx");

// Traverse every paragraph of the first section of the document
for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++)
  {
   Paragraph p = document.Sections[0].Paragraphs[j];

// Traverse every child object of a paragraph
for (int i = 0; i < p.ChildObjects.Count; i++)
    {
     DocumentObject obj = p.ChildObjects[i];

//Find the page break object
 if (obj.DocumentObjectType == DocumentObjectType.Break)
    {
     Break b = obj as Break;

// Remove the page break object from paragraph
p.ChildObjects.Remove(b);

//save the document to file.
document.SaveToFile("result.docx");

Please check the effective screenshot:

How to Remove Page breaks in C#

Full codes:

using Spire.Doc;
using Spire.Doc.Documents;
namespace RemovePageBreak
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile("sample.docx", FileFormat.Docx);
            for (int j = 0; j < document.Sections[0].Paragraphs.Count; j++)
            {
                Paragraph p = document.Sections[0].Paragraphs[j];
                for (int i = 0; i < p.ChildObjects.Count; i++)
                {
                    DocumentObject obj = p.ChildObjects[i];
                    if (obj.DocumentObjectType == DocumentObjectType.Break)
                    {
                        Break b = obj as Break;
                        p.ChildObjects.Remove(b);
                    }
                }
            }
            document.SaveToFile("result.docx", FileFormat.Docx);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}

Edit Table in PowerPoint document

2014-06-10 03:57:22 Written by Koohji

Spire.Presentation is a powerful and easy-to-use .NET component, especially designed for developers. Using Spire.Presentation you can generate, modify, convert, render, and print documents without installing Microsoft PowerPoint on your machine. There is a document in our website introducing you how to insert table. And in this document, you will be introduced how to edit a table within a PPT document.

Step 1: Create a Presentation instance and load the file.

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

Step 2: Store the data used in replacement in string [].

string[] str = new string[] { "Germany", "Berlin", "Europe", "0152458", "20860000" };

Step 3: Get the table within the PPT document.

ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
    if (shape is ITable)
    {
        table = (ITable) shape;
    }
}

Step 4: Fill in the third row with new data and set the HighlightColor.

for (int i = 0; i < table.ColumnsList.Count;i++ )
{
    //replace the data in cell
    table[i, 2].TextFrame.Text = str[i];

    //set the highlightcolor
    table[i, 2].TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet;
}

Step 5: Set the style of the table.

table.StylePreset = TableStylePreset.LightStyle1Accent2;

Step 6: Save the document.

presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);

Download and install Spire.Presentation for .NET and refer to below code to edit table within PPT document.

Screenshots and full code:

Before:

Edit Table in PowerPoint document

After:

Edit Table in PowerPoint document

[C#]
using Spire.Presentation;
using System.Drawing;

namespace EditTable
{

    class Program
    {

        static void Main(string[] args)
        {
            //create a PPT document
            Presentation presentation = new Presentation();

            presentation.LoadFromFile("table.pptx");

            //the data used in replacement
            string[] str = new string[] { "Germany", "Berlin", "Europe", "0152458", "20860000" };

            ITable table = null;

            //get the table in PPT document
            foreach (IShape shape in presentation.Slides[0].Shapes)
            {
                if (shape is ITable)
                {
                    table = (ITable)shape;

                    //change the style of table
                    table.StylePreset = TableStylePreset.LightStyle1Accent2;

                    for (int i = 0; i < table.ColumnsList.Count; i++)
                    {
                        //replace the data in cell
                        table[i, 2].TextFrame.Text = str[i];

                        //set the highlightcolor
                        table[i, 2].TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet;
                    }
                }
            }

            //save the document
            presentation.SaveToFile("result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("result.pptx");

        }

    }
}
[VB.NET]
Imports Spire.Presentation
Imports System.Drawing

Namespace EditTbale

	Class Program

		Private Shared Sub Main(args As String())
			'create a PPT document
			Dim presentation As New Presentation()

			presentation.LoadFromFile("table.pptx")

			'the data used in replacement
			Dim str As String() = New String() {"Germany", "Berlin", "Europe", "0152458", "20860000"}

			Dim table As ITable = Nothing

			'get the table in PPT document
			For Each shape As IShape In presentation.Slides(0).Shapes
				If TypeOf shape Is ITable Then
					table = DirectCast(shape, ITable)

					'change the style of table
					table.StylePreset = TableStylePreset.LightStyle1Accent2

					For i As Integer = 0 To table.ColumnsList.Count - 1
						'replace the data in cell
						table(i, 2).TextFrame.Text = str(i)

						'set the highlightcolor
						table(i, 2).TextFrame.TextRange.HighlightColor.Color = Color.BlueViolet
					Next
				End If
			Next

			'save the document
			presentation.SaveToFile("result.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("result.pptx")

		End Sub

	End Class
End Namespace

If you couldn't successfully use Spire.Presentation, please refer Spire.Presentation Quick Start which can guide you quickly use Spire.Presentation.

Set X dimension of Barcode

2014-06-06 06:53:23 Written by Koohji

Spire.Barcode is a free .NET component specially designed for developers. It can generate many kinds of barcode such as EAN128, Codabar, DataMatrix, PostNet and so on. It can also scan the barcode images. X dimension is the measure of the narrowest bar in a barcode. Barcodes and scanners have different X dimensions, so they must be matched. Using Spire.Barcode, it is quiet an easy job to do this.

In this document, I will introduce you how to so.

Step 1: Create a BarcodeSettings instance.

BarcodeSettings setting = new BarcodeSettings();

Step 2: Set the data to render.

setting.Data = "58465157484";
setting.Data2D = "58465157484";

Step 3: Set the type of barcode to generate.

setting.Type = BarCodeType.UPCA;

Step 4: Set the value of X dimension.

setting.Unit = GraphicsUnit.Millimeter;
setting.X = 0.8F;

The property Unit specifies the measurement unit. In this sample, the measurement unit is millimeter.

Step 5: Generate barcode image using BarCodeGenerator.

BarCodeGenerator gen = new BarCodeGenerator(setting);
Image img = gen.GenerateImage();
img.Save("barcode.png");

Screenshot and Full Code:

Set X dimension of Barcode

[C#]
using Spire.Barcode;
using System.Drawing;


namespace SetXDimension
{
    class Program
    {
        static void Main(string[] args)
        {
            BarcodeSettings barsetting = new BarcodeSettings();

            //set the x dimension
            barsetting.X = 0.8f;
            barsetting.Unit = GraphicsUnit.Millimeter;

            barsetting.HasBorder = true;
            barsetting.BorderWidth = 0.5F;

            //set the data
            barsetting.Data = "58465157484";
            barsetting.Data2D = "58465157484";

            //generate UPCA barcode
            barsetting.Type = BarCodeType.UPCA;

            BarCodeGenerator bargenerator = new BarCodeGenerator(barsetting);
            Image barcodeimage = bargenerator.GenerateImage();
            barcodeimage.Save("barcode.png");

            System.Diagnostics.Process.Start("barcode.png");
        }
    }
}
[VB.NET]
Imports Spire.Barcode
Imports System.Drawing


Namespace SetXDimension
	Class Program
		Private Shared Sub Main(args As String())
			Dim barsetting As New BarcodeSettings()

			'set the x dimension
			barsetting.X = 0.8F
			barsetting.Unit = GraphicsUnit.Millimeter

			barsetting.HasBorder = True
			barsetting.BorderWidth = 0.5F

			'set the data
			barsetting.Data = "58465157484"
			barsetting.Data2D = "58465157484"

			'generate UPCA barcode
			barsetting.Type = BarCodeType.UPCA

			Dim bargenerator As New BarCodeGenerator(barsetting)
			Dim barcodeimage As Image = bargenerator.GenerateImage()
			barcodeimage.Save("barcode.png")

			System.Diagnostics.Process.Start("barcode.png")
		End Sub
	End Class
End Namespace
page 60