Excel provides an option to display the trendline equation when we add a trendline on a chart. Sometimes, we may have the requirement of extracting the trendline equation from the chart. This article introduces a simple method to implement this aim by using Spire.XLS.

For demonstration, we used a sample chart which contains a trendline equation: y=2x – 1.

How to extract the trendline equation from an Excel chart

Code snippets:

Step 1: Instantiate a Workbook object and load the Excel document.

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

Step 2: Get the chart from the first worksheet.

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

Step 3: Get the trendline of the chart and then extract the equation of the trendline.

IChartTrendLine trendLine = chart.Series[0].TrendLines[0];
string formula = trendLine.Formula;

Effective screenshot:

How to extract the trendline equation from an Excel chart

Full code:

[C#]
using System;
using Spire.Xls;
using Spire.Xls.Core;

namespace Extract_the_equation
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");
            Chart chart = workbook.Worksheets[0].Charts[0];
            IChartTrendLine trendLine = chart.Series[0].TrendLines[0];
            string formula = trendLine.Formula;
            Console.WriteLine("The equation is:\n" +formula);
            Console.ReadKey();
        }
    }
}
[VB.NET]
Imports Spire.Xls
Imports Spire.Xls.Core

Namespace Extract_the_equation
	Class Program
		Private Shared Sub Main(args As String())
			Dim workbook As New Workbook()
			workbook.LoadFromFile("Sample.xlsx")
			Dim chart As Chart = workbook.Worksheets(0).Charts(0)
			Dim trendLine As IChartTrendLine = chart.Series(0).TrendLines(0)
			Dim formula As String = trendLine.Formula
			Console.WriteLine(Convert.ToString("The equation is:" & vbLf) & formula)
			Console.ReadKey()
		End Sub
	End Class
End Namespace

Excel 2013 has provided some new charting features, for example, it enables users to set data callout labels which makes it easier to show the details about the data series or its individual data points in a clear and easy-to-read format. This article is going to introduce how to add data callout labels to a chart using Spire.XLS.

Step 1: Initialize a new instance of Workbook class and set the Excel version as 2013.

Workbook wb = new Workbook();
wb.Version = ExcelVersion.Version2013;

Step 2: Get the first sheet from workbook.

Worksheet ws = wb.Worksheets[0];

Step 3: Insert some data.

ws.Range["A2"].Text = "Product 1";
ws.Range["A3"].Text = "Product 2";
ws.Range["A4"].Text = "Product 3";
ws.Range["A5"].Text = "Product 4";
ws.Range["B1"].Text = "Sales";
ws.Range["B1"].Style.Font.IsBold = true;
ws.Range["B2"].NumberValue = 251;
ws.Range["B3"].NumberValue = 515;
ws.Range["B4"].NumberValue = 454;
ws.Range["B5"].NumberValue = 874;

Step 4: Create a Clustered Column Chart based on the data from range A1:B5.

Chart chart = ws.Charts.Add(ExcelChartType.ColumnClustered);
chart.DataRange = ws.Range["A1:B5"];
chart.SeriesDataFromRange = false;
chart.PrimaryValueAxis.HasMajorGridLines = false;

Step 5: Set the chart position.

chart.LeftColumn = 4;
chart.TopRow = 2;
chart.RightColumn = 12;
chart.BottomRow = 22;

Step 6: Set the HasWedgeCallout property as true to display callout labels in a chart.

foreach (ChartSerie cs in chart.Series)
{
    cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
    cs.DataPoints.DefaultDataPoint.DataLabels.HasWedgeCallout = true;
}

Step 7: Save the file.

wb.SaveToFile("result.xlsx", FileFormat.Version2013);

Output:

How to Add Data Callout Labels to Charts in Excel in C#

Full Code:

using Spire.Xls;
using Spire.Xls.Charts;

namespace AddCalloutLabels
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook wb = new Workbook();
            wb.Version = ExcelVersion.Version2013;
            Worksheet ws = wb.Worksheets[0];

            ws.Range["A2"].Text = "Product 1";
            ws.Range["A3"].Text = "Product 2";
            ws.Range["A4"].Text = "Product 3";
            ws.Range["A5"].Text = "Product 4";
            ws.Range["B1"].Text = "Sales";
            ws.Range["B1"].Style.Font.IsBold = true;
            ws.Range["B2"].NumberValue = 251;
            ws.Range["B3"].NumberValue = 515;
            ws.Range["B4"].NumberValue = 454;
            ws.Range["B5"].NumberValue = 874;

            Chart chart = ws.Charts.Add(ExcelChartType.ColumnClustered);
            chart.DataRange = ws.Range["A1:B5"];
            chart.SeriesDataFromRange = false;
            chart.PrimaryValueAxis.HasMajorGridLines = false;

            chart.LeftColumn = 4;
            chart.TopRow = 2;
            chart.RightColumn = 12;
            chart.BottomRow = 22;

            foreach (ChartSerie cs in chart.Series)
            {
                cs.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
                cs.DataPoints.DefaultDataPoint.DataLabels.HasWedgeCallout = true;
            }
            wb.SaveToFile("result.xlsx", FileFormat.Version2013);
        }
    }
}

Spire.Presentation offers multiple functions to set the format for the chart elements. We have already shown you how to set the color for datapoints of series and format data labels of chart series in the PowerPoint document. This article will focus on demonstrating how to set font for text on chart legend and chart axis in C#.

Firstly please check the custom chart on presentation slides:

Set font for the text on Chart legend and Chart Axis in C#

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

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx", FileFormat.Pptx2010);

Step 2: Get the chart that need to be formatted the font for the text on chart legend and chart axis.

IChart chart = presentation.Slides[0].Shapes[0] as IChart;

Step 3: Set the font for the text on Chart Legend area.

chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.SolidColor.KnownColor = KnownColors.Red;
chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");

Step 4: Set the font for the text on Chart Axis area.

chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.SolidColor.KnownColor = KnownColors.Red;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.FillType = FillFormatType.Solid;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 10;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");

Step 5: Save the document to file:

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

Effective screenshot after formatting the font for the chart legend and chart Axis.

Set font for the text on Chart legend and Chart Axis in C#

Full codes:

Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx", FileFormat.Pptx2010);

IChart chart = presentation.Slides[0].Shapes[0] as IChart;

chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.SolidColor.KnownColor = KnownColors.Red;
chart.ChartLegend.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");

chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.SolidColor.KnownColor = KnownColors.Red;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.FillType = FillFormatType.Solid;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight = 10;
chart.PrimaryCategoryAxis.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont = new TextFont("Arial Unicode MS");

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

Spire.PDF allows getting and verifying a specific signature in a PDF file, now starts from version 3.8.82, Spire.PDF supports to get all certificates in a PDF signature. In this article, we will show you the steps of how to achieve this task by using Spire.PDF.

For demonstration, we used a template PDF file which contains two certificates:

How to get all certificates in a PDF signature

Code snippets:

Step 1: Instantiate a PdfDocument object and load the PDF file.

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

Step 2: Create a List object.

List<PdfSignature> signatures = new List<PdfSignature>();

Step 3: Get all signatures from the PDF file and add them into the list object.

var form = (PdfFormWidget)doc.Form;
for (int i = 0; i < form.FieldsWidget.Count; ++i)
{
    var field = form.FieldsWidget[i] as PdfSignatureFieldWidget;
    if (field != null && field.Signature != null)
    {
        PdfSignature signature = field.Signature;
        signatures.Add(signature);
    }
}

Step 4: Get the first signature from the list, and then get all the certificates from the signature.

PdfSignature signatureOne = signatures[0];
X509Certificate2Collection collection = signatureOne.Certificates;

Effective screenshot:

How to get all certificates in a PDF signature

Full code:

using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Spire.Pdf;
using Spire.Pdf.Security;
using Spire.Pdf.Widget;

namespace Get_all_certificates_in_PDF_signature
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("UPS.pdf");
            List<PdfSignature> signatures = new List<PdfSignature>();
            var form = (PdfFormWidget)doc.Form;
            for (int i = 0; i < form.FieldsWidget.Count; ++i)
            {
                var field = form.FieldsWidget[i] as PdfSignatureFieldWidget;

                if (field != null && field.Signature != null)
                {
                    PdfSignature signature = field.Signature;
                    signatures.Add(signature);
                }
            }
            PdfSignature signatureOne = signatures[0];
            X509Certificate2Collection collection = signatureOne.Certificates;
            foreach (var certificate in collection)
            {
                Console.WriteLine(certificate.Subject);
            }            
            Console.ReadKey();
        }
    }
}

With the help of Spire.Presentation, developers can set the horizontal alignment for the text on presentation slides easily. This article will focus on show you how to set the horizontal alignment for the text on the table of the presentation slides in C#. There are five options for the text alignment on the Spire.Presentation: Left, Right, Center, Justify and None.

At first, please check a document with default alignment (Left) prepared. Then, different alignment styles will be applied for the different rows on the table.

How to set vertical alignment for the text in table on presentation slides

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

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

Step 2: Get the table from the sample document.

ITable table = null;

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

Step 3: Align text horizontally.

for (int i = 0; i < table.ColumnsList.Count; i++)
{
   
    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;

}

Step 4: Save the document to file.

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

Effective screenshot after apply the horizontal alignment for the text on table:

How to set vertical alignment for the text in table on presentation slides

Full codes of how to set horizontal alignment for the text on the presentation slide's table:

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

        ITable table = null;

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

                for (int i = 0; i < table.ColumnsList.Count; i++)
                {
                   
                    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
                    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
                    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
                    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
                    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;

                
                }
            }
        }
        presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
    }

We have already had an article of showing how to convert the XPS files into PDF file. Starts from Spire.PDF V3.8.68, it newly supports to keep the high quality image on the resulted PDF file from the XPS document. Spire.PDF offers a property of pdf.UseHighQualityImage to set the image quality before loading the original XPS file. This article will focus on demonstrate how to save image with high quality for the conversion from XPS to PDF.

Here comes to the code snippets:

Step 1: Create a PDF instance.

PdfDocument pdf = new PdfDocument();

Step 2: Set the value of UseHighQualityImage as true to use the high quality image when convert XPS to PDF.

pdf.UseHighQualityImage = true;

Step 3: Load the XPS document by use either the method of pdf.LoadFromFile() or pdf.LoadFromXPS().

pdf.LoadFromFile("Sample.xps",FileFormat.XPS);

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot of the high quality image after saving XPS as PDF file format:

How to keep high quality image when convert XPS to PDF in C#

Full codes:

{
    PdfDocument pdf = new PdfDocument();

    pdf.UseHighQualityImage = true;

    pdf.LoadFromFile("Sample.xps",FileFormat.XPS);
    //pdf.LoadFromXPS("Sample.xps");

    pdf.SaveToFile("result.pdf", FileFormat.PDF);

}

Spire.XLS enables developers to change the color of data series in an Excel chart with just a few lines of code. Once changed, the legend color will also turn into the same as the color you set to the series.

The following part demonstrates the steps of how to accomplish this task. Below picture shows the original colors of the data series in an Excel chart:

How to change the color of data series in an Excel chart

Code snippets:

Step 1: Instantiate a Workbook object and load the Excel workbook.

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

Step 2: Get the first worksheet.

Worksheet sheet = book.Worksheets[0];

Step 3: Get the second series of the chart.

ChartSerie cs = sheet.Charts[0].Series[1];

Step 4: Change the color of the second series to Purple.

cs.Format.Fill.FillType = ShapeFillType.SolidColor;
cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);

Step 5: Save the Excel workbook to file.

book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);

After running the code, the color of the second series has been changed into Purple, screenshot as shown below.

How to change the color of data series in an Excel chart

Full code:

[C#]
using System.Drawing;
using Spire.Xls;
using Spire.Xls.Charts;

namespace Change_Series_Color
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook book = new Workbook();
            book.LoadFromFile("Sample.xlsx");
            Worksheet sheet = book.Worksheets[0];
            ChartSerie cs = sheet.Charts[0].Series[1];
            cs.Format.Fill.FillType = ShapeFillType.SolidColor;
            cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple);
            book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010);
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Xls
Imports Spire.Xls.Charts

Namespace Change_Series_Color
	Class Program
		Private Shared Sub Main(args As String())
			Dim book As New Workbook()
			book.LoadFromFile("Sample.xlsx")
			Dim sheet As Worksheet = book.Worksheets(0)
			Dim cs As ChartSerie = sheet.Charts(0).Series(1)
			cs.Format.Fill.FillType = ShapeFillType.SolidColor
			cs.Format.Fill.ForeColor = Color.FromKnownColor(KnownColor.Purple)
			book.SaveToFile("ChangeSeriesColor.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace

Browsed at a kiosk (full screen) is one kind of the slide show types in PowerPoint, if users choose this option, the Slide Show is full screen but they cannot navigate from slide to slide, for example, move to the next or previous slides.

The following part will demonstrate how to set the presentation show type as kiosk in C# and VB.NET using Spire.Presentation.

Detail steps:

Step 1: Instantiate a Presentation object and load the PPT file.

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

Step 2: Specify the presentation show type as kiosk.

presentation.ShowType = SlideShowType.Kiosk;

Step 3: Save the file.

presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);

Output:

How to set the presentation show type as kiosk (full screen) in C#, VB.NET

Full code:

[C#]
using Spire.Presentation;

namespace Set_Presentation_show_type_as_ kiosk
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Sample.pptx");
            presentation.ShowType = SlideShowType.Kiosk;
            presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);
        }
    }
}
[VB.NET]
Imports Spire.Presentation

Namespace Set_Presentation_show_type_as_ kiosk
	Class Program
		Private Shared Sub Main(args As String())
			Dim presentation As New Presentation()
			presentation.LoadFromFile("Sample.pptx")
			presentation.ShowType = SlideShowType.Kiosk
			presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013)
		End Sub
	End Class
End Namespace

In charts, each category on the category axis is identified by a tick-mark label and separated from other categories by tick marks. The tick-mark label text comes from the name of the associated category and is usually placed next to the axis.

In this article, we will introduce how we can custom the tick-mark labels by changing the labels' position, rotating labels and specifying interval between labels in C#, VB.ENT.

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Figure 1 – Chart in Example File

To facilitate the introduction, we prepared a PowerPoint document that contains a column chart looks like the screenshot in Figure 1 and used below code to get the chart from the PowerPoint slide. Then we're able to custom the labels through the following ways.

Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

Rotate tick labels

chart.PrimaryCategoryAxis.TextRotationAngle = 45;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Specify interval between labels

To change the number of unlabeled tick marks, we must set IsAutomaticTickLabelSpacing property as false and change the TickLabelSpacing property to any number between 1 - 255.

chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Change tick labels' position

chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

Working with Tick-mark Labels on the Category Axis in C#, VB.NET

Full Code:

[C#]
Presentation ppt = new Presentation(@"C:\Users\Administrator\Desktop\ColumnChart.pptx",FileFormat.Pptx2013);
IChart chart = ppt.Slides[0].Shapes[0] as IChart;

//rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45;

//specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = false;
chart.PrimaryCategoryAxis.TickLabelSpacing = 2;

////change position
//chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);
[VB.NET]
Dim ppt As New Presentation("C:\Users\Administrator\Desktop\ColumnChart.pptx", FileFormat.Pptx2013)
Dim chart As IChart = TryCast(ppt.Slides(0).Shapes(0), IChart)

'rotate tick labels
chart.PrimaryCategoryAxis.TextRotationAngle = 45

'specify interval between labels
chart.PrimaryCategoryAxis.IsAutomaticTickLabelSpacing = False
chart.PrimaryCategoryAxis.TickLabelSpacing = 2

'''/change position
'chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionHigh;

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)
Tuesday, 15 November 2016 07:43

How to change the image on button field in C#

We have already had an article of showing how to replace the image on the existing PDF file. Starts from Spire.PDF V3.8.45, it newly supports to update the image on button field via the method of field.SetButtonImage(PdfImage.FromFile(@"")). This article will focus on demonstrate how to replace the image on the button field in C#.

Firstly, check the original PDF file with the button field.

How to change the image on button field in C#

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

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

Step 2: Get the form from the loaded PDF document.

PdfFormWidget form = pdf.Form as PdfFormWidget;

Step 3: Find the button field named "Image" and then set a new image for this button field.

for (int i = 0; i < form.FieldsWidget.Count; i++)
{
    if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
    {
        PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
        if (field.Name == "Image")
        { field.SetButtonImage(PdfImage.FromFile("logo.png")); }
    }
}

Step 4: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot after replace the image on the button field.

How to change the image on button field in C#

Full codes:

public ButtonField()
{
    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile("Sample.PDF", FileFormat.PDF);

    PdfFormWidget form = pdf.Form as PdfFormWidget;

    for (int i = 0; i < form.FieldsWidget.Count; i++)
    {
        if (form.FieldsWidget[i] is PdfButtonWidgetFieldWidget)
        {
            PdfButtonWidgetFieldWidget field = form.FieldsWidget[i] as PdfButtonWidgetFieldWidget;
            if (field.Name == "Image")
            { field.SetButtonImage(PdfImage.FromFile("logo.png")); }

        }
    }

    pdf.SaveToFile("result.pdf");

}