Document variables are used to preserve macro settings in between macro sessions. Spire.Doc allows adding variables, counting the number of variables, retrieving the name and value of variables, and removing specific variables in a Word document.

Add a Variable

Use the Add method to add a variable to a document. The following example adds a document variable named "A1" with a value of 12 to the document.

using Spire.Doc;
using Spire.Doc.Documents;
namespace ADDVARIABLE
{
    class Program
    {

        static void Main(string[] args)
        {
            //Instantiate a document object
            Document document = new Document();
            //Add a section
            Section section = document.AddSection();
            //Add a paragraph
            Paragraph paragraph = section.AddParagraph();
            //Add a DocVariable Filed
            paragraph.AppendField("A1", FieldType.FieldDocVariable);
            //Add a document variable to the DocVariable Filed
            document.Variables.Add("A1", "12");
            //Update fields
            document.IsUpdateFields = true;
            //Save and close the document object
            document.SaveToFile("AddVariable.docx", FileFormat.Docx2013);
            document.Close();
        }
    }
}

Add, Count, Retrieve and Remove Variables in a Word document Using C#

Count the number of Variables

Use the Count property to return the number of variables in a document.

//Load the document
Document document = new Document("AddVariable.docx");
//Get the number of variables in the document
int number = document.Variables.Count;

Console.WriteLine(number);

Add, Count, Retrieve and Remove Variables in a Word document Using C#

Retrieve Name and Value of a Variable

Use the GetNameByIndex and GetValueByIndex methods to retrieve the name and value of the variable by index, and the Variables[String Name] to retrieve or set the value of the variable by name.

using Spire.Doc;
using Spire.Doc.Documents;
using System;
namespace COUNTVARIABLE
{

    class Program
    {

        static void Main(string[] args)
        {
            //Load the document
            Document document = new Document("AddVariable.docx");
            //Get the number of variables in the document
            int number = document.Variables.Count;

            Console.WriteLine(number);

        }
    }
}

Add, Count, Retrieve and Remove Variables in a Word document Using C#

Remove a specific Variable

Use the Remove method to remove the variable from the document.

using Spire.Doc;
using System;
namespace RETRIEVEVARIABLE
{
    class Program
    {
        static void Main(string[] args)
        {
            //Load the document
            Document document = new Document("AddVariable.docx");

            // Retrieve name of the variable by index
            string s1 = document.Variables.GetNameByIndex(0);

            // Retrieve value of the variable by index
            string s2 = document.Variables.GetValueByIndex(0);

            // Retrieve or set value of the variable by name
            string s3 = document.Variables["A1"];

            Console.WriteLine("{0} {1} {2}", s1, s2, s3);
        }
    }
}

When we operate the data on an Excel worksheet, we may need to delete text from a cell in a spreadsheet document and sometimes even remove all the contents with format from the cell range. This article will demonstrate how to remove the value and format from Excel Cell range with the help of Spire.XLS.

Step 1: Create an instance of Excel workbook and load the document from file.

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

Step 2: Get the first worksheet from the workbook.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Set the value as null to remove the original content from the Excel Cell.

sheet.Range["A1"].Value = "";

Step 4: Clear the contents to remove the original content from the Excel Cell.

sheet.Range["A3"].ClearContents();

Step 5: Remove the contents with format from the Excel cell.

sheet.Range["B1"].ClearAll();

Step 6: Save document to file.

workbook.SaveToFile("result.xlsx",FileFormat.Version2010);

Effective screenshot of remove the value and format from Excel Cell range:

How to remove the value and format from Excel Cell range

Full codes:

using Spire.Xls;
namespace RemoveValue
{
    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");

            Worksheet sheet = workbook.Worksheets[0];

            sheet.Range["A1"].Value = "";

            sheet.Range["A3"].ClearContents();

            sheet.Range["B1"].ClearAll();


            workbook.SaveToFile("result.xlsx", FileFormat.Version2010);
        }
    }
}

How to Create PDF417 Barcode in C#

2017-06-16 06:20:53 Written by Koohji

The PDF417 barcode, also known as Portable Data File 417 or PDF417 Truncated, is a two-dimensional (2D), high-density symbology capable of encoding text, numbers, files and actual data bytes.

Compaction Modes

The data is encoded using one of three compaction modes: Text compaction mode, Binary compaction mode, and Numeric compaction mode.

  • Text: It allows encoding all printable ASCII characters, i.e. values from 32 to 126 inclusive in accordance with ISO/IEC 646, as well as selected control characters such as TAB (horizontal tab ASCII 9), LF (NL line feed, new line ASCII 10) and CR (carriage return ASCII 13).
  • Binary: It allows encoding all 256 possible 8-bit byte values. This includes all ASCII characters value from 0 to 127 inclusive and provides for international character set support.
  • Numeric: It allows efficient encoding of numeric data strings.
  • Auto: It switches between Text, Binary and Numeric modes in order to minimize the number of codewords to be encoded.

PDF417 Error Correction Levels

Error correction allows the symbol to endure some damage without causing loss of data. The error correction level depends on the amount of data that needs to be encoded, the size and the amount of symbol damage that could occur. The error correction levels range from 0 to 8.

EC Level 0 1 2 3 4 5 6 7 8
EC Codewords Generated 2 4 6 8 16 32 64 128 512
Data Codewords 1-40 41-160 161-320 321-863
Data Bytes Encoded 1-56 57-192 193-384 385-1035

Following code snippets show how to create a PDF417 barcode image using Spire.Barcode.

Step 1: Create an instance of BarcodeSetting class.

BarcodeSettings settings = new BarcodeSettings();

Step 2: Set the barode type as Pdf417 and set the data to be encoded.

settings.Type = BarCodeType.Pdf417;
settings.Data = "123456789";

Step 3: Set the data mode as numeric.

settings.Pdf417DataMode = Pdf417DataMode.Numeric;

Step 4: Set the error correction level as level 2.

settings.Pdf417ECL = Pdf417ECL.Level2;

Step 5: Initialize an instance of BarcodeGenerator and generate an image based on the settings.

BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();   

Step 6: Save the image in .png format.

image.Save("PDF417Code.png");

Output:

How to Create PDF417 Barcode in C#

Full Code:

using Spire.Barcode;
using System.Drawing;

namespace PDF417Code
{
    class Program
    {
        static void Main(string[] args)
        {
            BarcodeSettings settings = new BarcodeSettings();
            settings.Type = BarCodeType.Pdf417;
            settings.Data = "123456789";
            settings.Data2D = "123456789";
            settings.Pdf417DataMode = Pdf417DataMode.Numeric;
            settings.Pdf417ECL = Pdf417ECL.Level2;
            BarCodeGenerator generator = new BarCodeGenerator(settings);
            Image image = generator.GenerateImage();
            image.Save("PDF417Code.png");
        }
    }
}

C# QR Code Generating Guide

Generating QR codes with C# is a practical solution for many common development tasks—such as encoding URLs, login tokens, or product information. With the help of a .NET-compatible barcode library, you can quickly create scannable QR images and integrate them into your applications or documents.

This tutorial shows how to build a simple yet powerful C# QR code generator: from generating a QR code from a string, embedding a logo, to inserting the image into PDF, Word, and Excel files. It also covers usage in both Windows and ASP.NET applications, using clean and reusable C# code examples.

Quick Navigation


1. How QR Code Generation Works in C#

Before diving into the code, it’s useful to understand what a QR code is. QR codes are 2D matrix barcodes that can encode URLs, text, contact info, and more. In C#, QR code generation involves three steps:

  1. Encode your content (usually a string)
  2. Configure QR code options (error correction, size, margin, etc.)
  3. Export the result as an image

In this tutorial, we use a simple .NET-compatible library Spire.Barcode for .NET to keep things straightforward and flexible.

Install Spire.Barcode for .NET via NuGet

PM> Install-Package Spire.Barcode

You can also choose Free Spire.Barcode for .NET for smaller tasks:

PM> Install-Package FreeSpire.Barcode

2. Generate QR Code from String in C#

Let’s start with a basic example: generating a QR code from a string in C#. Using the BarcodeSettings and BarCodeGenerator classes provided by Spire.Barcode for .NET, you can easily encode any text or URL into a scannable QR code.

The key steps include:

  • Defining QR code content and format using BarcodeSettings, including data string, error correction level, size, margin, and optional logo;
  • Generating the image via BarCodeGenerator, which produces a ready-to-use System.Drawing.Image object;
  • Saving or embedding the result in external documents or applications.

The following code demonstrates how to configure the QR code and export it as a PNG image.

using Spire.Barcode;
using System.Drawing;
using System.Drawing.Imaging;

namespace GenerateQRCode
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize barcode settings
            BarcodeSettings settings = new BarcodeSettings();
            // Specify the barcode type as QR Code
            settings.Type = BarCodeType.QRCode;
            // Set the QR code data
            settings.Data = "https://www.example.com/";
            // Set the text to display (optional)
            settings.Data2D = "Scan to go to example.com";
            settings.ShowTextOnBottom = true;
            settings.TextFont = new Font(FontFamily.GenericSansSerif, 16.0f);

            // Set data mode and error correction level
            settings.QRCodeDataMode = QRCodeDataMode.Auto;
            settings.QRCodeECL = QRCodeECL.H;
            // (Optional) Embed a logo image in the QR code
            settings.QRCodeLogoImage = Image.FromFile("Logo.png");
            // Set the width of bar module
            settings.X = 3.0f;

            // Generate the QR code image
            BarCodeGenerator generator = new BarCodeGenerator(settings);
            // Generate the QR code image
            Image qr = generator.GenerateImage();
            // Save the image to a file
            qr.Save("QR Code.png", ImageFormat.Png);
        }
    }
}

You can change the settings.Data to encode any text or URL. To embed a logo, use QRCodeLogoImage with a local image path. Error correction level H ensures that the QR code remains scannable even with a logo.

The QR code generated using C#:

QR Code Image Generated Using C#

You may also like: How to Scan QR Code Using C#


3. Insert QR Codes into Documents (PDF, Word, Excel)

A common use case for a c# qr generator is embedding QR codes into documents—automatically generating reports, receipts, or certificates. The generated QR image can be inserted into files using standard .NET Office libraries.

Insert into PDF

PdfDocument pdf = new PdfDocument();
PdfPageBase page = pdf.AppendPage();

page.Canvas.DrawImage(PdfImage.FromImage(qr), 100, 400, 100, 100);

pdf.SaveToFile("output.pdf");

Use cases: digital invoices, shipping labels, authentication docs.

Insert into Word Document

Document doc = new Document();
Section section = doc.AddSection();
Paragraph para = section.AddParagraph();

DocPicture picture = para.AppendPicture(qr);

doc.SaveToFile("output.docx", FileFormat.Docx);

Use cases: contracts, personalized letters, ID cards.

Insert into Excel Worksheet

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];

sheet.Pictures.Add(2, 2, qr);  // Cell C3

book.SaveToFile("output.xlsx", ExcelVersion.Version2016);

Use cases: customer records, product sheets, logistics tracking.

Recommended article: Read Barcodes from PDF Documents


4. QR Code Generator in Windows and Web Applications

Windows Application

In a Windows Forms app, you can display the generated QR image in a PictureBox, and allow users to save it. This is useful for desktop-based systems like check-in kiosks or internal tools.

pictureBox1.Image = qr;

ASP.NET Web Application

In ASP.NET, return the QR image in a memory stream:

MemoryStream ms = new MemoryStream();
qr.Save(ms, ImageFormat.Png);
return File(ms.ToArray(), "image/png");

These approaches are lightweight and do not depend on heavy frameworks.


FAQ

Q: How to generate a QR code in .NET C# by code? A: Use a barcode library like Spire.Barcode for .NET. Simply define your QR code content, set the desired options (e.g., error correction level, logo image), and export it as an image. It's straightforward to integrate into C# applications.

Q: What is the best QR code generator for C#? A: There are several good options available. Spire.Barcode for .NET is a solid choice—it supports multiple barcode formats, allows logo insertion, and integrates well with Office documents.

Q: Can I adjust the size and layout of the generated QR code? A: Yes. You can modify properties like X, LeftMargin, and TopMargin to control the module size and spacing around the QR code.

Q: How can I use the generated QR code in documents or applications? A: The generated image can be embedded into PDFs, Word documents, Excel sheets, or displayed in Windows Forms or ASP.NET pages. This makes it useful in reports, labels, and web systems.


Conclusion

Creating a QR code generator in C# is simple yet highly effective. This tutorial demonstrated how to generate QR codes with a few lines of C# code, insert them into documents, and deploy them in both desktop and web environments. You can further expand on this by exploring batch generation, QR styling, or integrating scanning features in future enhancements.

To try it yourself, you can apply for a free temporary license here to unlock the full capabilities of Spire.Barcode for .NET.

How to create Code39 barcodes in C#

2017-06-12 07:45:38 Written by Koohji

Code39 is also known as Alpha39, Code 3 of 9, Code 3/9, Type 39, USS Code 39, USD-3. This article will show you how to use Spire.Barcode to create Code39 barcode. It supports 43 characters, consisting of uppercase letters (A through Z), numeric digits (0 through 9) and a number of special characters (*, -, $, /, +, %, and space). Usually Code39 starts and ends with “*”. Here comes to the steps of how to create Code39 barcodes.

Step 1: Create a BarcodeSettings instance.

BarcodeSettings bs = new BarcodeSettings();

Step 2: Set the BarcodeType property to Code39

bs.Type = BarCodeType.Code39;

Step 3: Set the data for the barcode.

bs.Data = "*ABC 12345* ";

Step 4: Generate barcode image using BarCodeGenerator.

BarCodeGenerator bg = new BarCodeGenerator(bs);
bg.GenerateImage().Save("Code39Code.png");    

Effective screenshot of Code39 barcode image:

How to create Code39 barcodes in C#

Full codes:

using Spire.Barcode;


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

            bs.Type = BarCodeType.Code39;
            bs.Data = "*ABC 12345* ";


            BarCodeGenerator bg = new BarCodeGenerator(bs);

            bg.GenerateImage().Save("Code39Code.png");
            System.Diagnostics.Process.Start("Code39Code.png");
        }
    }
}

Convert PDF Page to SVG in C#/VB.NET

2017-06-09 06:41:39 Written by Koohji

Spire.PDF allows us to convert a PDF document, a single page or a range of pages in a PDF document to SVG file format. We have introduced how to convert a PDF document to SVG, in this tutorial, we are going to demonstrate how to convert a PDF page to SVG.

Below is the source PDF file we used in this example:

Convert PDF Page to SVG in C#, VB.NET

Code snippets:

Step 1: Instantiate an object of PdfDocument class and load the PDF document.

PdfDocument doc = new PdfDocument();
doc.LoadFromFile("Test.pdf");

Step 2: Convert the first page of the PDF document to SVG using the SaveToFile(string filename, int startIndex, int endIndex, FileFormat fileFormat) method.

doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);

The resultant SVG file looks as follows:

Convert PDF Page to SVG in C#, VB.NET

Full code:

[C#]
using Spire.Pdf;

namespace PDF_Page_to_SVG
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("Test.pdf");
            doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG);
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace PDF_Page_to_SVG
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("Test.pdf")
			doc.SaveToFile("Result.svg", 0, 0, FileFormat.SVG)
		End Sub
	End Class
End Namespace

When we add an image to the Excel worksheet, we always need to reset the size and position for the image to list the image where we want and make the size coordinate with the other elements on the Excel worksheet. This article will focus on demonstrates how to apply picture settings by using Spire.XLS.

Step 1: Initialize an instance of Workbook and get the first worksheet.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Step 2: Add a picture to the first worksheet.

ExcelPicture picture = sheet.Pictures.Add(1, 1, "Logo.png");

Step 3: Set the size for the picture.

picture.Width = 75;
picture.Height = 75;

Step 4: Set the position for the picture.

picture.Left = 200;
picture.Top = 100;

Step 5: Save the document to file.

workbook.SaveToFile("Output.xlsx",FileFormat.Version2013);

Effective screenshot after reset the size and position for the image:

Reset the size and position for the image on Excel worksheet

Full codes:

using Spire.Xls;
namespace ReseSizeandPosition
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            ExcelPicture picture = sheet.Pictures.Add(1, 1, "Logo.png");

            picture.Width = 75;
            picture.Height = 75;

            picture.Left = 200;
            picture.Top = 100;

            workbook.SaveToFile("Output.xlsx", FileFormat.Version2013);
        }
    }
}

In PDF, buttons can be assigned icon appearances and each button can have as many as three appearances: Normal, Rollover, and Click. With Spire.PDF, not only can we assign icons to buttons, but also we can change the icons of buttons. In this article, we’re going to show you how to assign an icon to a button and set icon layout using Spire.PDF and C#. As for changing icons, please refer How to change the image on button field in C#.

Code Snippets:

Step 1: Create a PDF document and add a page to it.

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

Step 2: Create a button field.

PdfButtonField btn = new PdfButtonField(page, "button1");
btn.Bounds = new RectangleF(0, 50, 120, 100);

Step 3: Set button layout.

btn.HighlightMode = PdfHighlightMode.Push;
btn.LayoutMode = PdfButtonLayoutMode.CaptionOverlayIcon;
//Set text and icon for Normal appearance
btn.Text = "Normal Text";
btn.Icon = PdfImage.FromFile("Image.png");
//Set text and icon for Click appearance (Can only be set when highlight mode is Push)
btn.AlternateText = "Alternate Text";
btn.AlternateIcon = PdfImage.FromFile("Sunflower.jpg");
//Set text and icon for Rollover appearance (Can only be set when highlight mode is Push)
btn.RolloverText = "Rollover Text";
btn.RolloverIcon = PdfImage.FromFile("PinkRoses.jpg");

Step 4: Set icon layout.

btn.IconLayout.Spaces = new float[] { 0.5f, 0.5f };
btn.IconLayout.ScaleMode = PdfButtonIconScaleMode.Proportional;
btn.IconLayout.ScaleReason = PdfButtonIconScaleReason.Always;
btn.IconLayout.IsFitBounds = false;

Step 5: Add the button to the document.

doc.Form.Fields.Add(btn);

Step 6: Save the document.

doc.SaveToFile("AddIcon.pdf");

The resultant document looks as follows:

Assign an Icon to a PDF Button Field and Set Icon Layout in C#

Full code:

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

namespace Add_Icon_to_PDF_Button_Field
{
    class Program
    {
        static void Main(string[] args)
        {   
            //Create a PDF document       
            PdfDocument doc = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            //Create a Button
            PdfButtonField btn = new PdfButtonField(page, "button1");
            btn.Bounds = new RectangleF(0, 50, 120, 100);
            btn.HighlightMode = PdfHighlightMode.Push;
            btn.LayoutMode = PdfButtonLayoutMode.CaptionOverlayIcon;
            //Set text and icon for Normal appearance
            btn.Text = "Normal Text";
            btn.Icon = PdfImage.FromFile("Image.png");
            //Set text and icon for Click appearance (Can only be set when highlight mode is Push)
            btn.AlternateText = "Alternate Text";
            btn.AlternateIcon = PdfImage.FromFile("Sunflower.jpg");
            //Set text and icon for Rollover appearance (Can only be set when highlight mode is Push)
            btn.RolloverText = "Rollover Text";
            btn.RolloverIcon = PdfImage.FromFile("PinkRoses.jpg");

            //Set icon layout
            btn.IconLayout.Spaces = new float[] { 0.5f, 0.5f };
            btn.IconLayout.ScaleMode = PdfButtonIconScaleMode.Proportional;
            btn.IconLayout.ScaleReason = PdfButtonIconScaleReason.Always;
            btn.IconLayout.IsFitBounds = false;

            //Add the button to the document
            doc.Form.Fields.Add(btn);

            //Save the document
            doc.SaveToFile("AddIcon.pdf");            
        }
    }
}

In PowerPoint, a combination chart is a type of chart that combines two or more different chart types into a single chart. It allows you to display multiple sets of data in the same chart, making it easier to compare and analyze different variables. In this article, you will learn how to programmatically create a combination chart in a PowerPoint presentation using Spire.Presentation for .NET.

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

Create a Combination Chart in PowerPoint in C# and VB.NET

Spire.Presentation for .NET offers the ISlide.Shapes.AppendChart(ChartType type, RectangleF rectangle) method to add a certain chart type to a slide, and then you can change the chart type of the second series to another chart to create a combo chart. The following are the steps to combine a column chart and a line chart in PowerPoint.

  • Create a Presentation instance.
  • Get a specified slide and add a column chart to it using ISlide.Shapes.AppendChart(ChartType.ColumnClustered, RectangleF rectangle) method.
  • Create a DataTable object and add some data, then import data from data table to chart data.
  • Set the chart title, categories labels, series labels and series values.
  • Change the chart type of the second series to a line chart with data markers using IChart.Series[int index].Type property.
  • Plot the second series on the secondary value axis by setting the IChart.Series[int index].UseSecondAxis property to true.
  • Set the number format and gridlines of the secondary value axis.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Data;
using System.Drawing;

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

            //Add a column clustered chart to the first slide
            RectangleF rect = new RectangleF(80, 120, 550, 320);
            IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, rect);

            //Set and format chart title
            chart.ChartTitle.TextProperties.Text = "Monthly Sales Report";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;

            //Create a datatable and add some data
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add(new DataColumn("Month", Type.GetType("System.String")));
            dataTable.Columns.Add(new DataColumn("Sales", Type.GetType("System.Int32")));
            dataTable.Columns.Add(new DataColumn("Growth rate", Type.GetType("System.Decimal")));
            dataTable.Rows.Add("January", 200, 0.6);
            dataTable.Rows.Add("February", 250, 0.8);
            dataTable.Rows.Add("March", 300, 0.6);
            dataTable.Rows.Add("April", 150, 0.2);
            dataTable.Rows.Add("May", 200, 0.5);
            dataTable.Rows.Add("June", 400, 0.9);

            //Import data from datatable to chart data
            for (int c = 0; c < dataTable.Columns.Count; c++)
            {
                chart.ChartData[0, c].Text = dataTable.Columns[c].Caption;
            }
            for (int r = 0; r < dataTable.Rows.Count; r++)
            {
                object[] datas = dataTable.Rows[r].ItemArray;
                for (int c = 0; c < datas.Length; c++)
                {
                    chart.ChartData[r + 1, c].Value = datas[c];

                }
            }

            //Set series labels
            chart.Series.SeriesLabel = chart.ChartData["B1", "C1"];

            //Set categories labels    
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A7"];

            //Assign data to series values
            chart.Series[0].Values = chart.ChartData["B2", "B7"];
            chart.Series[1].Values = chart.ChartData["C2", "C7"];

            //Change the chart type of series 2 to a line chart with data markers
            chart.Series[1].Type = ChartType.LineMarkers;

            //Plot data of series 2 on the secondary axis
            chart.Series[1].UseSecondAxis = true;

            //Set the number format of the secondary value axis
            chart.SecondaryValueAxis.NumberFormat = "0%";

            //Hide the gridlines of the secondary value axis
            chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;

            //Set the legend position
            chart.ChartLegend.Position = ChartLegendPositionType.Top;

            //Set overlap
            chart.OverLap = -50;

            //Set gapwidth
            chart.GapWidth = 200;

            //Save the result document
            presentation.SaveToFile("CombinationChart.pptx", FileFormat.Pptx2010);
        }
    }
}

C#/VB.NET: Create a Combination Chart in PowerPoint

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.

In our daily work, we may need to copy the contents from one presentation slides to another. This article is aimed to introduce the method of how to copy the content from one paragraph from the source PowerPoint document to the target document by using Spire.Presenation.

Firstly, View the original presentation slide and the target presentation slide.

Copy a paragraph from one presentation slide to another in C#

Step 1: Initialize an instances of Presentation class and load the source document from file

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

Step 2: Get the text from the first shape on the first slide.

string Text = "";           
IShape shp = ppt.Slides[0].Shapes[0];
Text = ((IAutoShape)shp).TextFrame.Text;

Step 3: Get the first shape on the first slide from the target document file.

Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
IShape destshp = ppt2.Slides[0].Shapes[0];

Step 4: Get text from placeholder.

((IAutoShape)destshp).TextFrame.Text += Text;

Step 5: Save the document to file.

ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);

Effective screenshot after copy the paragraph from the source file:

Copy a paragraph from one presentation slide to another in C#

Full codes:

using Spire.Presentation;
namespace CoppyParagh
{
    class Program
    {
        static void Main(string[] args)
        {

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

            string Text = "";
            IShape shp = ppt.Slides[0].Shapes[0];
            Text = ((IAutoShape)shp).TextFrame.Text;

            Presentation ppt2 = new Presentation("Sample1.pptx", FileFormat.Pptx2010);
            IShape destshp = ppt2.Slides[0].Shapes[0];
            ((IAutoShape)destshp).TextFrame.Text += Text;

            ppt2.SaveToFile("Sample1.pptx", FileFormat.Pptx2010);


        }
    }
}
page 28