A doughnut chart (also spelled donut) is a variant of the pie chart, with a blank center allowing for additional information about the data as a whole to be included. In this article, you will learn how to create a doughnut chart in PowerPoint using Spire.Presentation.

Step 1: Initialize an instance of Presentation class.

Presentation presentation = new Presentation();

Step 2: Insert a Doughnut chart in the first slide and set the chart title.

RectangleF rect = new RectangleF(40, 100, 550, 320);
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.Doughnut, rect, false);
chart.ChartTitle.TextProperties.Text = "Market share by country";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;

Step 3: Define the chart data.

string[] countries = new string[] { "Guba", "Mexico","France","German" };
int[] sales = new int[] { 1800, 3000, 5100, 6200 };
chart.ChartData[0, 0].Text = "Countries";
chart.ChartData[0, 1].Text = "Sales";
for (int i = 0; i < countries.Length; ++i)
{
    chart.ChartData[i + 1, 0].Value = countries[i];
    chart.ChartData[i + 1, 1].Value = sales[i];
}

Step 4: Set the data range of category labels, series label and series values.

chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];
chart.Series[0].Values = chart.ChartData["B2", "B5"];

Step 5: Add data points to series and fill each data point with different color.

for (int i = 0; i < chart.Series[0].Values.Count; i++)
{
    ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
    cdp.Index = i;
    chart.Series[0].DataPoints.Add(cdp);
}
chart.Series[0].DataPoints[0].Fill.FillType = FillFormatType.Solid;
chart.Series[0].DataPoints[0].Fill.SolidColor.Color = Color.LightBlue;
chart.Series[0].DataPoints[1].Fill.FillType = FillFormatType.Solid;
chart.Series[0].DataPoints[1].Fill.SolidColor.Color = Color.MediumPurple;
chart.Series[0].DataPoints[2].Fill.FillType = FillFormatType.Solid;
chart.Series[0].DataPoints[2].Fill.SolidColor.Color = Color.DarkGray;
chart.Series[0].DataPoints[3].Fill.FillType = FillFormatType.Solid;
chart.Series[0].DataPoints[3].Fill.SolidColor.Color = Color.DarkOrange;

Step 6: Display value and percentage in data labels.

chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[0].DataLabels.PercentValueVisible = true;

Step 7: Adjust the hole size of doughnut chart.

chart.Series[0].DoughnutHoleSize = 60;

Step 8: Save the file.

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

Output:

How to Create Doughnut Chart in PowerPoint in C#

Full Code:

using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace SetFont
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();
            RectangleF rect = new RectangleF(40, 100, 550, 320);
            IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.Doughnut, rect, false);
            chart.ChartTitle.TextProperties.Text = "Market share by country";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;

            string[] countries = new string[] { "Guba", "Mexico", "France", "German" };
            int[] sales = new int[] { 1800, 3000, 5100, 6200 };
            chart.ChartData[0, 0].Text = "Countries";
            chart.ChartData[0, 1].Text = "Sales";
            for (int i = 0; i < countries.Length; ++i)
            {
                chart.ChartData[i + 1, 0].Value = countries[i];
                chart.ChartData[i + 1, 1].Value = sales[i];
            }
            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];
            chart.Series[0].Values = chart.ChartData["B2", "B5"];

            for (int i = 0; i < chart.Series[0].Values.Count; i++)
            {
                ChartDataPoint cdp = new ChartDataPoint(chart.Series[0]);
                cdp.Index = i;
                chart.Series[0].DataPoints.Add(cdp);
            }
            chart.Series[0].DataPoints[0].Fill.FillType = FillFormatType.Solid;
            chart.Series[0].DataPoints[0].Fill.SolidColor.Color = Color.LightBlue;
            chart.Series[0].DataPoints[1].Fill.FillType = FillFormatType.Solid;
            chart.Series[0].DataPoints[1].Fill.SolidColor.Color = Color.MediumPurple;
            chart.Series[0].DataPoints[2].Fill.FillType = FillFormatType.Solid;
            chart.Series[0].DataPoints[2].Fill.SolidColor.Color = Color.DarkGray;
            chart.Series[0].DataPoints[3].Fill.FillType = FillFormatType.Solid;
            chart.Series[0].DataPoints[3].Fill.SolidColor.Color = Color.DarkOrange;

            chart.Series[0].DataLabels.LabelValueVisible = true;
            chart.Series[0].DataLabels.PercentValueVisible = true;
            chart.Series[0].DoughnutHoleSize = 60;

            presentation.SaveToFile("DoughnutChart.pptx", FileFormat.Pptx2013);
        }
    }
}

How to remove page breaks in a worksheet

2017-02-23 07:25:37 Written by Koohji

We have already demonstrated how to add page breaks in Excel worksheet in C# with the help of Spire.XLS. Spire.XLS supports to remove all the horizontal and vertical page breaks and it also supports to remove the special page breaks. Here comes to the steps of how to remove the page breaks from an Excel worksheet.

Firstly, view the same Excel document with horizontal page breaks and vertical page breaks:

How to remove page breaks in a worksheet

Step 1: Initialize an instance of 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: Clear all the vertical page breaks by call the VPageBreaks.Clear() method.

sheet.VPageBreaks.Clear();

Step 4: Remove the specified horizontal Page Break by call the HPageBreaks.RemoveAt() method.

sheet.HPageBreaks.RemoveAt(0);

Step 5: Set the ViewMode as Preview to see how the page breaks work.

sheet.ViewMode = ViewMode.Preview;

Step 6: Save the document to file.

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

Effective screenshot of removing the page breaks in a worksheet:

How to remove page breaks in a worksheet

Full codes:

using Spire.Xls;
namespace RemovePageBreak
{
    class Program
    {

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

            Worksheet sheet = workbook.Worksheets[0];

            //sheet.HPageBreaks.Clear();
            sheet.VPageBreaks.Clear();

            sheet.HPageBreaks.RemoveAt(0);


            sheet.ViewMode = ViewMode.Preview;

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

Replace font(s) in PDF document

2017-02-22 09:12:35 Written by Koohji

Spire.PDF supports the functionality to replace font(s) used in PDF document. The following parts shows how we can use Spire.PDF to replace all the fonts used in an existing PDF document with another alternate font in C# and VB.NET.

Screenshot before replacing font:

How to replace font(s) in PDF document

Code snippets:

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

PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"E:\Program Files\input.pdf");

Step 2: Use the UsedFonts attribute of PdfDocument class to get all the fonts used in the document.

PdfUsedFont[] fonts = doc.UsedFonts;

Step 3: Create a new PDF font. Loop through the fonts and call PdfUsedFont.replace() method to replace them with the new font.

PdfFont newfont = new PdfFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Italic | PdfFontStyle.Bold);
foreach (PdfUsedFont font in fonts)
{
    font.Replace(newfont);
}

Step 4: Save the resultant document.

doc.SaveToFile("output.pdf");

Screenshot after replacing font:

How to replace font(s) in PDF document

Full code:

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

namespace Replace_font_in_PDF
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(@"E:\Program Files\input.pdf");
            PdfUsedFont[] fonts = doc.UsedFonts;
            PdfFont newfont = new PdfFont(PdfFontFamily.TimesRoman, 11f, PdfFontStyle.Italic | PdfFontStyle.Bold);
            foreach (PdfUsedFont font in fonts)
            {
                font.Replace(newfont);
            }

            doc.SaveToFile("output.pdf");
        }
    }
}
[VB.NET]
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.Graphics.Fonts

Namespace Replace_font_in_PDF
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("E:\Program Files\input.pdf")
			Dim fonts As PdfUsedFont() = doc.UsedFonts
			Dim newfont As New PdfFont(PdfFontFamily.TimesRoman, 11F, PdfFontStyle.Italic Or PdfFontStyle.Bold)
			For Each font As PdfUsedFont In fonts
				font.Replace(newfont)
			Next

			doc.SaveToFile("output.pdf")
		End Sub
	End Class
End Namespace

C#/VB.NET: Flatten Form Fields in PDF

2022-08-15 09:07:00 Written by Koohji

Flattening form fields is an efficient way to prevent others from modifying or deleting the form field contents in PDF. After flattening, the editing or filling capability of the form fields will be removed and their contents will appear as regular text. In this article, you will learn how to flatten form fields in a PDF document in C# and VB.NET using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLLs files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Flatten a Specific Form Field in PDF in C# and VB.NET

The following are the steps to flatten a specific form field in a PDF document using Spire.PDF for .NET:

  • Initialize an instance of PdfDocument class.
  • Load a PDF document using PdfDocument.LoadFromFile() method.
  • Get the form widget collection from the document.
  • Get a specific form field from the widget collection by its name or index through PdfFormWidget.FieldsWidget["fieldName"] property or PdfFormWidget.FieldsWidget.List[fieldIndex] property.
  • Flatten the form field through PdfField.Flatten property.
  • Save the result document using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Fields;
using Spire.Pdf.Widget;

namespace FlattenSpecificFormField
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument instance
            PdfDocument pdf = new PdfDocument();
            //Load a PDF document
            pdf.LoadFromFile("Form.pdf");

            //Get the form widget collection
            PdfFormWidget formWidget = (PdfFormWidget)pdf.Form;
            //Get a specific form field by its name
            PdfField form = formWidget.FieldsWidget["Address"];
            //Get a specific form field by its index
            //PdfField form = formWidget.FieldsWidget.List[2] as PdfField;
            //Flatten the form
            form.Flatten = true;

            //Save the result document
            pdf.SaveToFile("FlattenSpecific.pdf");
        }
    }
}

C#/VB.NET:  Flatten Form Fields in PDF

Flatten All Form Fields in PDF in C# and VB.NET

The following are the steps to flatten all the form fields in a PDF document using Spire.PDF for .NET:

  • Initialize an instance of PdfDocument class.
  • Load a PDF document using PdfDocument.LoadFromFile() method.
  • Flatten all the form fields in the document through PdfDocument.Form.IsFlatten property.
  • Save the result document using PdfDocument.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Pdf;

namespace FlattenAllFormFields
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PdfDocument instance
            PdfDocument pdf = new PdfDocument();
            //Load a PDF document
            pdf.LoadFromFile("Form.pdf");

            //Flatten all the forms in the document
            pdf.Form.IsFlatten = true;

            //Save the result document
            pdf.SaveToFile("FlattenAll.pdf");
        }
    }
}

C#/VB.NET:  Flatten Form Fields in PDF

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.

Fill XFA Form Fields in C#/VB.NET

2017-02-14 07:54:06 Written by Administrator

XFA forms are XML-based forms created by Adobe's LiveCycle Designer tool, which offer enhanced features over the old AcroForms, like changeable text fields and support for running JavaScript. Spire.PDF supports to access the XFA forms in an existing PDF file and fill the fields with data.

Step 1: Initialize an instance of PdfDocument class and load a sample PDF file containing dynamic XFA forms.

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

Step 2: Get all form widgets from the document.

PdfFormWidget formWidget = doc.Form as PdfFormWidget;

Step 3: Get a list of XFA Fields.

List⁢XfaField> xfafields = formWidget.XFAForm.XfaFields;"

Step 4: Traverse each XfaField in the list and judge if it is an XfaTextField, if yes, convert the type of XfaField as an XfaTextField and then assign value to the field based on the field name.

foreach (XfaField xfaField in xfaFields)
{
    if (xfaField is XfaTextField)
    {
        XfaTextField xf = xfaField as XfaTextField;
        switch (xfaField.Name)
        {
            case "EmployeeName":
                xf.Value = "Gary";
                break;
            case "Address":
                xf.Value = "Chengdu, China";
                break;
            case "StateProv":
                xf.Value = "Sichuan Province";
                break;
            case "ZipCode":
                xf.Value = "610093";
                break;
            case "SSNumber":
                xf.Value = "000-00-0000";
                break;
            case "HomePhone":
                xf.Value = "86-028-81705109";
                break;
            case "CellPhone":
                xf.Value = "123456789";
                break;
            case "Comments":
                xf.Value = "This demo shows how to fill XFA forms using Spire.PDF";
                break;
            default:
                break;
        }
    }
}

Step 5: Save the file.

doc.SaveToFile("FillXfaField.pdf",FileFormat.PDF);

Output:

How to Fill XFA Form Fields in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Widget;
using System.Collections;
using System.Collections.Generic;

namespace FillXFAFormFields
{
    class Program
    {
        private static IEnumerable xfaFields;
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("DynamicXFA.pdf");

            PdfFormWidget formWidget = doc.Form as PdfFormWidget;
            List xfafields = formWidget.XFAForm.XfaFields;
            foreach (XfaField xfaField in xfafields)
            {
                if (xfaField is XfaTextField)
                {
                    XfaTextField xf = xfaField as XfaTextField;
                    switch (xfaField.Name)
                    {
                        case "EmployeeName":
                            xf.Value = "Gary";
                            break;
                        case "Address":
                            xf.Value = "Chengdu, China";
                            break;
                        case "StateProv":
                            xf.Value = "Sichuan Province";
                            break;
                        case "ZipCode":
                            xf.Value = "610093";
                            break;
                        case "SSNumber":
                            xf.Value = "000-00-0000";
                            break;
                        case "HomePhone":
                            xf.Value = "86-028-81705109";
                            break;
                        case "CellPhone":
                            xf.Value = "123456789";
                            break;
                        case "Comments":
                            xf.Value = "This demo shows how to fill XFA forms using Spire.PDF";
                            break;
                        default:
                            break;
                    }
                }
            }
            doc.SaveToFile("FillXfaField.pdf", FileFormat.PDF);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Widget
Imports System.Collections.Generic


Namespace FillXFAFormFields
	Class Program
		Private Shared xfaFields As IEnumerable(Of XfaField)
		Private Shared Sub Main(args As String())
			Dim doc As New PdfDocument()
			doc.LoadFromFile("DynamicXFA.pdf")

			Dim formWidget As PdfFormWidget = TryCast(doc.Form, PdfFormWidget)
			Dim xfafields__1 As List(Of XfaField) = formWidget.XFAForm.XfaFields
			For Each xfaField As XfaField In xfaFields
				If TypeOf xfaField Is XfaTextField Then
					Dim xf As XfaTextField = TryCast(xfaField, XfaTextField)
					Select Case xfaField.Name
						Case "EmployeeName"
							xf.Value = "Gary"
							Exit Select
						Case "Address"
							xf.Value = "Chengdu, China"
							Exit Select
						Case "StateProv"
							xf.Value = "Sichuan Province"
							Exit Select
						Case "ZipCode"
							xf.Value = "610093"
							Exit Select
						Case "SSNumber"
							xf.Value = "000-00-0000"
							Exit Select
						Case "HomePhone"
							xf.Value = "86-028-81705109"
							Exit Select
						Case "CellPhone"
							xf.Value = "123456789"
							Exit Select
						Case "Comments"
							xf.Value = "This demo shows how to fill XFA forms using Spire.PDF"
							Exit Select
						Case Else
							Exit Select
					End Select
				End If
			Next
			doc.SaveToFile("FillXfaField.pdf", FileFormat.PDF)
		End Sub
	End Class
End Namespace

C#: Remove Worksheets from a Workbook

2024-07-10 06:09:00 Written by Koohji

Simplifying your Excel workbooks by removing redundant or unused worksheets can be a beneficial organizational practice. This process allows you to eliminate clutter and improve file structure by focusing only on the most relevant data. Removing unneeded worksheets frees up storage space, streamlines navigation, and keeps your workbooks clean and efficient.

In this article, you will learn how to remove worksheets from an Excel workbook in C# by using the Spire.XLS for .NET library.

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

Remove a Worksheet by Its Index from a Workbook in C#

Spire.XLS for .NET provides the WorksheetsCollection.RemoveAt(int index) method, which allows you to remove a specific worksheet by its index from a workbook. Here are the detailed steps:

  • Create a Workbook object.
  • Load an Excel file from a given path.
  • Get the worksheets collection from the document using Workbook.Worksheets property.
  • Remove a worksheet by its index using WorksheetsCollection.RemoveAt(int index) method.
  • Save the workbook to a different Excel document.
  • C#
using Spire.Xls;
using Spire.Xls.Collections;

namespace RemoveWorksheetByIndex
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook wb = new Workbook();

            // Load an Excel file
            wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Input.xlsx");

            // Get the worksheets collection from the document
            WorksheetsCollection worksheets = wb.Worksheets;

            // Remove a specific worksheet by its index
            worksheets.RemoveAt(0);

            // Save the workbook to a different Excel file
            wb.SaveToFile("RemoveByIndex.xlsx", ExcelVersion.Version2016);

            // Dispose resources
            wb.Dispose();
        }
    }
}

Remove a Worksheet by Its Name from a Workbook in C#

If you already know the name of the worksheet that you want to remove, you can do so by using the WorksheetsCollection.Remove(string sheetName) method. The detailed steps are as follows:

  • Create a Workbook object.
  • Load an Excel file from a given path.
  • Get the worksheets collection from the document using Workbook.Worksheets property.
  • Remove a worksheet by its name using WorksheetsCollection.Remove(string sheetName) method.
  • Save the workbook to a different Excel document.
  • C#
using Spire.Xls;
using Spire.Xls.Collections;

namespace RemoveWorksheetByName
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook wb = new Workbook();

            // Load an Excel file
            wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Input.xlsx");

            // Get the worksheets collection from the document
            WorksheetsCollection worksheets = wb.Worksheets;

            // Remove a specific worksheet by its name
            worksheets.Remove("sheet2")

            // Save the workbook to a different Excel file
            wb.SaveToFile("RemoveByName.xlsx", ExcelVersion.Version2016);

            // Dispose resources
            wb.Dispose();
        }
    }
}

Remove All Worksheets from a Workbook at Once in C#

To remove all worksheets at once, you can use the WorksheetsCollection.Clear() method. Here are the detailed steps:

  • Create a Workbook object.
  • Load an Excel file from a given path.
  • Get the worksheets collection from the document using Workbook.Worksheets property.
  • Remove all worksheet at once using WorksheetsCollection.Clear() method.
  • Save the workbook to a different Excel document.
  • C#
using Spire.Xls;
using Spire.Xls.Collections;

namespace RemoveAllWorksheets
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a Workbook object
            Workbook wb = new Workbook();

            // Load an Excel file
            wb.LoadFromFile(@"C:\Users\Administrator\Desktop\Input.xlsx");

            // Get the worksheets collection from the document
            WorksheetsCollection worksheets = wb.Worksheets;

            // Remove all worksheets
            worksheets.Clear();

            // Save the workbook to a different Excel file
            wb.SaveToFile("RemoveAllWorksheets.xlsx", ExcelVersion.Version2016);

            // Dispose resources
            wb.Dispose();
        }
    }
}

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

There is no concept of expiration date defined in the PDF specifications format, however, there is a workaround that we can apply expiration using JavaScript. Spire.PDF supports to add java script actions to PDF files as well. This article presents how to add a JavaScript expiration date to a PDF document using Spire.PDF in C# and VB.NET.

Step 1: Create an object of PdfDocument class and add a blank page to it.

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

Step 2: Define the JavaScript code.

string javaScript = "var rightNow = new Date();"
                    + "var endDate = new Date('October 20, 2016 23:59:59');"
                    + "if(rightNow.getTime() > endDate)"
                    + "app.alert('This Document has expired, please contact us for a new one.',1);"
                    + "this.closeDoc();";

Step 3: Create a PdfJavaScriptAction object that performs the java script action in PDF document.

PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);

Step 4: Set the JavaScript as PDF open action.

doc.AfterOpenAction = js;

Step 5: Save the file.

doc.SaveToFile("ExpiryDate.pdf", FileFormat.PDF);

Output:

How to Add Expiry Date to PDF Files in C#, VB.NET

Full Code:

[C#]
using Spire.Pdf;
using Spire.Pdf.Actions;

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

            string javaScript = "var rightNow = new Date();"
                     + "var endDate = new Date('October 20, 2016 23:59:59');"
                     + "if(rightNow.getTime() > endDate)"
                     + "app.alert('This Document has expired, please contact us for a new one.',1);"
                     + "this.closeDoc();";
            PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);
            doc.AfterOpenAction = js;
            doc.SaveToFile("ExpiryDate.pdf", FileFormat.PDF);
        }
    }
}
[VB.NET]
Imports Spire.Pdf
Imports Spire.Pdf.Actions

Namespace AddExpiryDate
	Class Program
		Private Shared Sub Main(args As String())
			Dim doc As PdfDocument = New PdfDocument()
doc.Pages.Add()
 
String javaScript = "var rightNow = new Date();"
                    + "var endDate = new Date('October 20, 2016 23:59:59');"
                    + "if(rightNow.getTime() > endDate)"
                    + "app.alert('This Document has expired, please contact us for a new one.',1);"
                    Dim "this.closeDoc();" As +
Dim js As PdfJavaScriptAction = New PdfJavaScriptAction(javaScript)
doc.AfterOpenAction = js
doc.SaveToFile("ExpiryDate.pdf", FileFormat.PDF)
		End Sub
	End Class
End Namespace

Spire.XLS supports to protect the whole excel workbook and specified worksheet with password. When we deal with the protected worksheet, sometimes we need to allow users to edit some specified ranges of the excel worksheet. This article will focus on demonstrating how to use the AddAllowEditRange method offered by Spire.XLS to set the specified range on a protected worksheet to be editable by users.

Step 1: Initialize an instance of 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: Define the specified ranges of Excel to allow users to edit while sheet is protected.

sheet.AddAllowEditRange("AAA", sheet.Range["C2:D8"], "");

Step 4: Protect the worksheet.

sheet.Protect("AAA", SheetProtectionType.All);

Step 5: Save the document to file.

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

Effective screenshot of Allow users to edit ranges:

Allow users to edit ranges for the protected Excel worksheet in C#

Full codes:

using Spire.Xls;
namespace EditRanges
{
    class Program
    {

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

            Worksheet sheet = workbook.Worksheets[0];

            sheet.AddAllowEditRange("AAA", sheet.Range["C2:D8"], "");
            sheet.Protect("AAA", SheetProtectionType.All);

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

        }
    }
}

Spire.Xls.CellRange class provides a method named Intersect(CellRange range) that is used to find the intersection of certain ranges. This is very useful when we need to get the common value(s) of two ranges in an excel worksheet.

In below picture, we take range A2:C8 and range B2:D8 as an example. Cells filled in yellow color are the intersection of the two ranges.

How to get the intersection of two ranges in Excel

Now refer to the following detail steps:

Step 1: Instantiate an object of Workbook class and load the Excel document.

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

Step 2: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 3: Get the intersection of the two ranges and print the common values of them.

CellRange range = sheet.Range["A2:C8"].Intersect(sheet.Range["B2:D8"]);
foreach (CellRange r in range)
{
    Console.WriteLine(r.Value);
}

Output:

How to get the intersection of two ranges in Excel

Full code:

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

namespace Get_the_instersection_of_two_ranges
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            CellRange range = sheet.Range["A2:C8"].Intersect(sheet.Range["B2:D8"]);
            foreach (CellRange r in range)
            {
                Console.WriteLine(r.Value);
            }
            Console.ReadKey();
        }
    }
}
[VB.NET]
Imports Spire.Xls

Namespace Get_the_instersection_of_two_ranges
	Class Program
		Private Shared Sub Main(args As String())
			Dim workbook As New Workbook()
			workbook.LoadFromFile("Sample.xlsx")
			Dim sheet As Worksheet = workbook.Worksheets(0)
			Dim range As CellRange = sheet.Range("A2:C8").Intersect(sheet.Range("B2:D8"))
			For Each r As CellRange In range
				Console.WriteLine(r.Value)
			Next
			Console.ReadKey()
		End Sub
	End Class
End Namespace

Animation is a great way to draw viewers' attention to a presentation. We can apply animation effects to text, shapes or any other objects on PowerPoint slides. To make the animations more attractive, we usually set sound effects for them. This article demonstrates how to obtain these sound effects by using Spire.Presentation and C#.

Below shape is set with a fly in animation which has a sound effect named "Applause".

How to obtain object's sound effect in PowerPoint

Refer below steps to get the sound effect from the shape:

Step 1: Load the PowerPoint document.

Presentation ppt = new Presentation(@"test.pptx", FileFormat.Pptx2013);

Step 2: Get the audio in a time node.

ISlide slide = ppt.Slides[0];
TimeNodeAudio audio = slide.Timeline.MainSequence[0].TimeNodeAudios[0];

Step 3: Now we can get the properties of the audio, such as sound name, volume or detect if it's mute.

string soundName = audio.SoundName;
float volume = audio.Volume;
bool isMute = audio.IsMute;

Output:

How to obtain object's sound effect in PowerPoint

Full code:

using System;
using Spire.Presentation;
using Spire.Presentation.Drawing.TimeLine;

namespace Get_Sound_Effect
{
    class Program
    {
        static void Main(string[] args)
        {
            Presentation ppt = new Presentation(@"test.pptx", FileFormat.Pptx2013);
            ISlide slide = ppt.Slides[0];
            TimeNodeAudio audio = slide.Timeline.MainSequence[0].TimeNodeAudios[0];
            string soundName = audio.SoundName;
            float volume = audio.Volume;
            bool isMute = audio.IsMute;
            Console.WriteLine("{0}, {1}, {2}", soundName, volume, isMute);
            Console.ReadKey();
        }
    }
}
page 31