When demonstrating an excel report, you may also want to share information from other external files or websites. In Excel, we can add both URL hyperlinks and external files by right-clicking on cells, selecting hyperlink and then adding URL address or choosing files from disk. This article is aimed to explain how to add hyperlinks to external files in excel programmatically using Spire.XLS for WPF. To add URL hyperlinks, please refer to this article: How to Insert Hyperlink in Excel for WPF Applications.

Please see the effective screenshot below after adding hyperlinks to external files:

How to add hyperlinks to external files in Excel for WPF Applications

Code Snippets:

Use the following namespace:

using System.Windows;
using Spire.Xls;

Step 1: Initialize a new Workbook object, load the sample excel file and get its first worksheet.

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

Step 2: Get the cell/cell range that you want to add hyperlink to, then call the sheet.HyperLinks.Add(CellRange range) method to add the hyperlink to the cell/cell range.

CellRange range1 = sheet.Range["D18"];
HyperLink hyperlink1 = sheet.HyperLinks.Add(range1); 

Step 3: Specify the hyperlink style and the hyperlink target, here we set its style to file and target to an external excel file.

hyperlink1.Type = HyperLinkType.File;
hyperlink1.Address = "SalesInfo.xlsx";

Step 4: Repeat step 2 and step 3 to add a hyperlink to another specific cell, set the hyperlink style to file and set its target to a word file.

CellRange range2 = sheet.Range["E18"];
HyperLink hyperlink2 = sheet.HyperLinks.Add(range2);
hyperlink2.Type = HyperLinkType.File;
hyperlink2.Address = "Report.doc";

Step 5: Save and launch the file.

workbook.SaveToFile("LinktoFile.xlsx", FileFormat.Version2010);
System.Diagnostics.Process.Start("LinktoFile.xlsx");

Full Codes:

C#
using Spire.Xls;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Vendors Information.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            HyperLink Link = sheet.HyperLinks.Add(sheet.Range["A5"]);
            Link.TextToDisplay = sheet.Range["A5"].Text;
            Link.Type = HyperLinkType.Url;
            Link.Address = "https://en.wikipedia.org/wiki/Canada";

            HyperLink NewLink = sheet.HyperLinks.Add(sheet.Range["D13"]);
            NewLink.TextToDisplay = "https://www.google.com";
            NewLink.Type = HyperLinkType.Url;
            NewLink.Address = "https://www.google.com";

            workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010);
            System.Diagnostics.Process.Start("Hyperlink.xlsx");
        }
    }
}
VB.NET
Imports Spire.Xls
Imports System.Windows

Namespace WpfApplication1
	Public Partial Class MainWindow
		Inherits Window
		Public Sub New()
			InitializeComponent()
		End Sub
		Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
			Dim workbook As New Workbook()
			workbook.LoadFromFile("Vendors Information.xlsx")
			Dim sheet As Worksheet = workbook.Worksheets(0)

			Dim Link As HyperLink = sheet.HyperLinks.Add(sheet.Range("A5"))
			Link.TextToDisplay = sheet.Range("A5").Text
			Link.Type = HyperLinkType.Url
			Link.Address = "https://en.wikipedia.org/wiki/Canada"

			Dim NewLink As HyperLink = sheet.HyperLinks.Add(sheet.Range("D13"))
			NewLink.TextToDisplay = "https://www.google.com"
			NewLink.Type = HyperLinkType.Url
			NewLink.Address = "https://www.google.com"

			workbook.SaveToFile("Hyperlink.xlsx", ExcelVersion.Version2010)
			System.Diagnostics.Process.Start("Hyperlink.xlsx")
		End Sub
	End Class
End Namespace

In order to change the look of a shape, users can add a solid, gradient, pattern or picture fill to it. Spire.Presentation supports all fill types listed. This article will introduce how to add a picture fill to a shape in C# and VB.NET.

Code Snippets:

Step 1: Initialize an instance of Presentation class.

Presentation ppt = new Presentation();

Step 2: Add a shape to the first slide.

IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));

Step 3: Set the FillType as picture and fill the shape with an image.

string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
shape.Fill.FillType = FillFormatType.Picture;               
shape.Fill.PictureFill.Picture.Url = picUrl;

Step 4: Set the picture fill mode to stretch.

shape.Fill.PictureFill.FillType = PictureFillType.Stretch;

Step 5: Save to file.

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

Output:

How to fill shape with picture in PowerPoint in C#

Full Code:

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

namespace FillShape
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation ppt = new Presentation();

            IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));
            string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
            shape.Fill.FillType = FillFormatType.Picture;
            shape.Fill.PictureFill.Picture.Url = picUrl;
            shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
            shape.ShapeStyle.LineColor.Color = Color.Transparent;

            ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("shape.pptx");
        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing

Namespace FillShape

	Class Program

		Private Shared Sub Main(args As String())
			Dim ppt As New Presentation()

			Dim shape As IAutoShape = DirectCast(ppt.Slides(0).Shapes.AppendShape(ShapeType.DoubleWave, New RectangleF(100, 100, 400, 200)), IAutoShape)
			Dim picUrl As String = "C:\Users\Administrator\Desktop\image.jpg"
			shape.Fill.FillType = FillFormatType.Picture
			shape.Fill.PictureFill.Picture.Url = picUrl
			shape.Fill.PictureFill.FillType = PictureFillType.Stretch
			shape.ShapeStyle.LineColor.Color = Color.Transparent

			ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010)
			System.Diagnostics.Process.Start("shape.pptx")
		End Sub
	End Class
End Namespace

Capitals are quite suitable for stressing texts in Word. A paragraph written with capitalized letters is easy to notice, and capitalized letters imply the importance of the paragraph. This article teaches you the method of changing the case of existing text to all capitals with Spire.Doc for .NET by programming.

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

Change the Case of a Specified Paragraph to All Capitals

The detailed steps are as follows:

  • Create an object of Document and load a sample Word document from file using Document.LoadFromFile() method.
  • Get the second paragraph using Document.Sections[].Paragraph[] property and set its characters to AllCaps through TextRange.CharacterFormat.AllCaps property.
  • Get the third paragraph using Document.Sections[].Paragraph[] property and set its characters to IsSmallCaps by TextRange.CharacterFormat.IsSmallCaps property.
  • Save the document to a new Word file using Document.SaveToFile() method.

Note: AllCaps means to capitalize all the letters and set them to the same size, and IsSmallCaps means to capitalize all the letters but set the original majuscules bigger than the minuscules.

  • C#
  • VB.NET
using System;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace changecase
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new document and load from file
            string input = @"D:\testp\test.docx"; ;
            Document doc = new Document();
            doc.LoadFromFile(input);
            TextRange textRange;
            //Get the second paragraph and set its characters to AllCaps
            Paragraph para1 = doc.Sections[0].Paragraphs[2];

            foreach (DocumentObject obj in para1.ChildObjects)
            {
                if (obj is TextRange)
                {
                    textRange = obj as TextRange;
                    textRange.CharacterFormat.AllCaps = true;
                }
            }

            //Get the third paragraph and set its characters to IsSmallCaps
            Paragraph para2 = doc.Sections[0].Paragraphs[3];
            foreach (DocumentObject obj in para2.ChildObjects)
            {
                if (obj is TextRange)
                {
                    textRange = obj as TextRange;
                    textRange.CharacterFormat.IsSmallCaps = true;
                }
            }

            //Save the document to a new Word file
            string output = "ChangeCase.docx";
            doc.SaveToFile(output, FileFormat.Docx2013);
        }
    }
}

C#/VB.NET: Change Text Case to All Capitals 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.

page 218