It is possible to perform Word to PDF conversion in Azure apps such as Azure Web apps and Azure Functions apps using Spire.Doc for .NET. In this article, you can see the code example to achieve this function with Spire.Doc for .NET.

The input Word document:

C#, VB.NET Convert Word to PDF in Azure Apps

Step 1: Install Spire.Doc NuGet Package as a reference to your project from NuGet.org.

C#, VB.NET Convert Word to PDF in Azure Apps

Step 2: Add the following code to convert Word to PDF.

C#
//Create a Document instance
Document document = new Document(false);
//Load the Word document
document.LoadFromFile(@"sample.docx");

//Create a ToPdfParameterList instance
ToPdfParameterList ps = new ToPdfParameterList
{
    UsePSCoversion = true
};
//Save Word document to PDF using PS conversion
document.SaveToFile("ToPdf.pdf", ps);
VB.NET
Private Sub SurroundingSub()
    Dim document As Document = New Document(false)
    document.LoadFromFile("sample.docx")
    Dim ps As ToPdfParameterList = New ToPdfParameterList With {
        .UsePSCoversion = True
    }
    document.SaveToFile("ToPdf.pdf", ps)
End Sub

The Output PDF document:

C#, VB.NET Convert Word to PDF in Azure Apps

When merging datasets from different sources or copying data from other worksheets, duplicate rows may appear if the data are not properly matched. These duplicate rows may distort data analysis and calculations, leading to incorrect results. Therefore, removing duplicate rows is a frequently needed task, and this article demonstrates how to accomplish this task programmatically using Spire.XLS for .NET.

Install Spire.XLS for .NET

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

PM> Install-Package Spire.XLS

Remove Duplicate Rows in Excel in C# and VB.NET

Removing duplicate rows manually is a very repetitive and time-consuming task. With Spire.XLS for .NET, you can identify and remove all duplicate rows at once. The following are the detailed steps.

  • Create a Workbook instance.
  • Load a sample Excel document using Workbook.LoadFromFile() method.
  • Get a specified worksheet by its index using Workbook.Worksheets[sheetIndex] property.
  • Specify the cell range where duplicate records need to be deleted using Worksheet.Range property.
  • Get the rows that contain duplicate content in the specified cell range.
  • Loop through all duplicated rows and delete them using Worksheet.DeleteRow() method.
  • Save the result document using Workbook.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Xls;
using System.Linq;

namespace RemoveDuplicateRows
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Workbook instance
            Workbook workbook = new Workbook();

            //Load a sample Excel document
            workbook.LoadFromFile("Test.xlsx");

            //Get the first worksheet
            Worksheet sheet = workbook.Worksheets[0];

            //Specify the cell range where duplicate records need to be deleted
            var range = sheet.Range["A1:A" + sheet.LastRow];

            //Get the duplicate row numbers
            var duplicatedRows = range.Rows
                   .GroupBy(x => x.Columns[0].DisplayedText)
                   .Where(x => x.Count() > 1)
                   .SelectMany(x => x.Skip(1))
                   .Select(x => x.Columns[0].Row)
                   .ToList();

            //Remove the duplicate rows        
            for (int i = 0; i < duplicatedRows.Count; i++)
            {
                sheet.DeleteRow(duplicatedRows[i] - i);
            }

            //Save the result document
            workbook.SaveToFile("RemoveDuplicateRows.xlsx");
        }
    }
}

C#/VB.NET: Remove Duplicate Rows in Excel

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.

A digital signature is a modern alternative to signing documents manually on paper with pen. It uses an advanced mathematical technique to check the authenticity and integrity of digital documents, which guarantees that the contents in a digital document comes from the signer and has not been altered since then. Sometimes PowerPoint documents that contain confidential information may require a signature. In this article, you will learn how to programmatically add or remove digital signatures in PowerPoint 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

Add a Digital Signature to PowerPoint in C# and VB.NET

To add a digital signature, you'll need to have a valid signature certificate first. Then you can digitally sign a PowerPoint document with the certificate using Presentation.AddDigitalSignature (X509Certificate2 certificate, string comments, DateTime signTime) method. The detailed steps are as follows.

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Initializes an instance of X509Certificate2 class with the certificate file name and password.
  • Add a digital signature to the PowerPoint document using Presentation.AddDigitalSignature (X509Certificate2 certificate, string comments, DateTime signTime) method.
  • Save result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;
using System;

namespace AddDigitalSignature
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
			
	    //Load a PowerPoint document
            ppt.LoadFromFile("Input.pptx");

            //Add a digital signature
            ppt.AddDigitalSignature("gary.pfx", "e-iceblue", "test", DateTime.Now);

            //Save the result document
            ppt.SaveToFile("AddDigitalSignature_result.pptx", FileFormat.Pptx2010);
            System.Diagnostics.Process.Start("AddDigitalSignature_result.pptx");

            //Dispose
            ppt.Dispose();			
        }
    }
}

C#/VB.NET: Add or Remove Digital Signatures in PowerPoint

Remove All Digital Signatures from PowerPoint in C# and VB.NET

At some point you may need to remove the digital signatures from a PowerPoint document. Spire.Presentation for .NET provides the Presentation.RemoveAllDigitalSignatures() method to remove all digital signatures at once. The detailed steps are as follows:

  • Create a Presentation instance.
  • Load a sample PowerPoint document using Presentation.LoadFromFile() method.
  • Determine if the document contains digital signatures using Presentation.IsDigitallySigned property.
  • Remove all digital signatures from the document using Presentation.RemoveAllDigitalSignatures() method.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

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

            //Load a PowerPoint document 
            ppt.LoadFromFile("AddDigitalSignature.pptx");

            //Detect if the document is digitally signed
            if (ppt.IsDigitallySigned == true)
            {
                //Remove all digital signatures
                ppt.RemoveAllDigitalSignatures();
            }

            //Save the result document
            ppt.SaveToFile("RemoveDigitalSignature.pptx", FileFormat.Pptx2013);

        }
    }
}

C#/VB.NET: Add or Remove Digital Signatures 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.

This article shows you how to download a PDF document from an URL using Spire.PDF with C# and VB.NET.

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

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

            //Create a WebClient object
            WebClient webClient = new WebClient();

            //Download data from URL and save as memory stream
            using (MemoryStream ms = new MemoryStream(webClient.DownloadData("https://www.e-iceblue.com/article/toDownload.pdf")))
            {
                //Load the stream
                doc.LoadFromStream(ms);
            }

            //Save to PDF file
            doc.SaveToFile("result.pdf", FileFormat.PDF);
        }
    }
}
VB.NET
Imports System.IO
Imports System.Net
Imports Spire.Pdf

Namespace DownloadPdfFromUrl
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a PdfDocument object
            Dim doc As PdfDocument = New PdfDocument()

            'Create a WebClient object
            Dim webClient As WebClient = New WebClient()

           'Download data from URL and save as memory stream
           Dim pdfData As Byte() = webClient.DownloadData(""https://www.e-iceblue.com/article/toDownload.pdf"")
           Using ms As New MemoryStream(pdfData)
           'Load the stream
           doc.LoadFromStream(ms)
 End Using

 'Save to PDF file
 doc.SaveToFile(""result.pdf"", FileFormat.PDF)
        End Sub
    End Class
End Namespace

Download PDF Document from URL in C#, VB.NET

This article shows you how to create a hyperlink to a bookmark within the same Word document by using Spire.Doc with C# and VB.NET.

C#
using Spire.Doc;
using Spire.Doc.Documents;

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

            //Add two sections
            Section section1 = doc.AddSection();
            Section section2 = doc.AddSection();

            //Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it
            Paragraph bookmarkParagrapg = section2.AddParagraph();
            bookmarkParagrapg.AppendText("Here is a bookmark");
            BookmarkStart start = bookmarkParagrapg.AppendBookmarkStart("myBookmark");
            bookmarkParagrapg.Items.Insert(0, start);
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark");

            //Link to the bookmark
            Paragraph paragraph = section1.AddParagraph();
            paragraph.AppendText("Link to a bookmark: ");
            paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark);

            //Save to file
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013);
        }
    }
}
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents

Namespace LinkToBookmark
    Class Program
        Shared  Sub Main(ByVal args() As String)
            'Create a Document object
            Document doc = New Document()
 
            'Add two sections
            Dim section1 As Section = doc.AddSection()
            Dim section2 As Section = doc.AddSection()
 
            'Insert a paragraph in section 2 and add a bookmark named "myBookmark" to it
            Dim bookmarkParagrapg As Paragraph = section2.AddParagraph()
            bookmarkParagrapg.AppendText("Here is a bookmark")
            Dim start As BookmarkStart = bookmarkParagrapg.AppendBookmarkStart("myBookmark")
            bookmarkParagrapg.Items.Insert(0, start)
            bookmarkParagrapg.AppendBookmarkEnd("myBookmark")
 
            'Link to the bookmark
            Dim paragraph As Paragraph = section1.AddParagraph()
            paragraph.AppendText("Link to a bookmark: ")
            paragraph.AppendHyperlink("myBookmark", "Jump to a location in this document", HyperlinkType.Bookmark)
 
            'Save to file
            doc.SaveToFile("LinkToBookmark.docx", FileFormat.Docx2013)
        End Sub
    End Class
End Namespace

Link to a Bookmark in a Word Document in C#/VB.NET

Spire.Presentation supports to insert text watermark and image watermark to PowerPoint document. This article will show you how to use Spire.Presentation to add multiple watermarks to the presentation slides in C#/VB.NET.

C#
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System;
using System.Drawing;
using System.Windows.Forms;

namespace WatermarkDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a PPT document and load file
            Presentation presentation = new Presentation();
            presentation.LoadFromFile("Sample.pptx");

            //Get the size of the watermark string
            Font font = new Font("Arial", 20);
            String watermarkText = "E-iceblue";
            SizeF size = TextRenderer.MeasureText("E-iceblue", font);
            float x = 30;
            float y = 80;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //Define a rectangle range
                    RectangleF rect = new RectangleF(x, y, size.Width, size.Height);

                    //Add a rectangle shape with a defined range
                    IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect);

                    //Set the style of the shape
                    shape.Fill.FillType = FillFormatType.None;
                    shape.ShapeStyle.LineColor.Color = Color.White;
                    shape.Rotation = -45;
                    shape.Locking.SelectionProtection = true;
                    shape.Line.FillType = FillFormatType.None;

                    //Add text to the shape
                    shape.TextFrame.Text = watermarkText;
                    TextRange textRange = shape.TextFrame.TextRange;
                    //Set the style of the text range
                    textRange.Fill.FillType = FillFormatType.Solid;
                    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink);
                    textRange.EastAsianFont = new TextFont(font.Name);
                    textRange.FontHeight = font.Size;

                    x += (100 + size.Width);
                }
                x = 30;
                y += (100 + size.Height);
            }

            //Save the document
            presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010);

        }
    }
}
VB.NET
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace WatermarkDemo
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Create a PPT document and load file
            Dim presentation As Presentation = New Presentation
            presentation.LoadFromFile("Sample.pptx")
            'Get the size of the watermark string
            Dim font As Font = New Font("Arial", 20)
            Dim watermarkText As String = "E-iceblue"
            Dim size As SizeF = TextRenderer.MeasureText("E-iceblue", font)
            Dim x As Single = 30
            Dim y As Single = 80
            Dim i As Integer = 0
            Do While (i < 3)
                Dim j As Integer = 0
                Do While (j < 3)
                    'Define a rectangle range
                    Dim rect As RectangleF = New RectangleF(x, y, size.Width, size.Height)
                    'Add a rectangle shape with a defined range
                    Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(Spire.Presentation.ShapeType.Rectangle, rect)
                    'Set the style of the shape
                    shape.Fill.FillType = FillFormatType.None
                    shape.ShapeStyle.LineColor.Color = Color.White
                    shape.Rotation = -45
                    shape.Locking.SelectionProtection = true
                    shape.Line.FillType = FillFormatType.None
                    'Add text to the shape
                    shape.TextFrame.Text = watermarkText
                    Dim textRange As TextRange = shape.TextFrame.TextRange
                    'Set the style of the text range
                    textRange.Fill.FillType = FillFormatType.Solid
                    textRange.Fill.SolidColor.Color = Color.FromArgb(120, Color.HotPink)
                    textRange.EastAsianFont = New TextFont(font.Name)
                    textRange.FontHeight = font.Size
                    x = (x + (100 + size.Width))
                    j = (j + 1)
                Loop
                
                x = 30
                y = (y + (100 + size.Height))
                i = (i + 1)
            Loop
            
            'Save the document
            presentation.SaveToFile("Watermark_result.pptx", FileFormat.Pptx2010)
        End Sub
    End Class
End Namespace

Output:

Add multiple watermarks in presentation slides

Password protection is a widely used security feature in PDFs to restrict access and prevent unauthorized modifications. Before working with a PDF, it is essential to determine whether it is password-protected. If protection is enabled, verifying the correct password allows you to unlock the document, ensuring smooth access for viewing, editing, or extracting its contents.

In this article, we will guide you through the process of checking whether a PDF is password-protected and how to verify the correct password using C# and the Spire.PDF for .NET library.

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

Check Whether a PDF is Password Protected in C#

Spire.PDF for .NET provides the PdfDocument.IsPasswordProtected(string fileName) method to determine whether a PDF file is password-protected. The detailed steps are as follows.

  • Specify the input and output file paths.
  • Use the PdfDocument.IsPasswordProtected(string fileName) method to check whether the PDF is password protected.
  • Save the verification result to a text file.
  • C#
using Spire.Pdf;
using System.IO;

namespace CheckIfPdfIsProtected
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Specify the input and output file paths
            string pdfPath = "sample.pdf";
            string resultFilePath = "verification_results.txt";

            // Check whether the PDF file is password-protected
            bool isProtected = PdfDocument.IsPasswordProtected(pdfPath);

            // Create a StreamWriter to write the result to a text file
            using (StreamWriter writer = new StreamWriter(resultFilePath))
            {
                // Write the verification result to the text file
                string resultMessage = isProtected ? "The PDF is password-protected." : "The PDF is not password-protected.";
                writer.WriteLine(resultMessage);
            }
        }
    }
}

Check Whether a PDF is Password Protected in C#

Determine the Correct Password of a PDF in C#

Spire.PDF for .NET does not have a direct method to verify if a password is correct, but this can be done by attempting to open the file with the given password. If the password is incorrect, an exception will be thrown. The detailed steps are as follows.

  • Specify the input and output file paths.
  • Check whether the PDF file is password-protected using the PdfDocument.IsPasswordProtected(string fileName) method.
  • Create an array of potential passwords to test.
  • Iterate through the array, and load the PDF with each password using the PdfDocument.LoadFromFile(string filename, string password) method.
  • If no exception is thrown, the password is correct. Otherwise, the password is incorrect.
  • Save the verification result to a text file.
  • C#
using Spire.Pdf;
using System;
using System.IO;

namespace DetermineTheCorrectPasswordOfPdf
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Specify the input and output file paths
            string pdfPath = "sample.pdf";
            string resultFilePath = "verification_results.txt";

            // Check whether the PDF file is password-protected
            bool isProtected = PdfDocument.IsPasswordProtected(pdfPath);

            // Create an array of potential passwords to test
            string[] passwords = new string[5] { "password1", "password2", "password3", "admin123", "test" };

            // Create a StreamWriter to write results to a text file
            using (StreamWriter writer = new StreamWriter(resultFilePath))
            {
                // If the PDF is protected, start testing passwords
                if (isProtected)
                {
                    // Iterate through each password in the array
                    for (int passwordcount = 0; passwordcount < passwords.Length; passwordcount++)
                    {
                        try
                        {
                            // Create a new PdfDocument object and try loading the document with the current password
                            PdfDocument doc = new PdfDocument();
                            doc.LoadFromFile(pdfPath, passwords[passwordcount]);

                            // If successful, write that the password is correct to the text file
                            writer.WriteLine("Password " + passwords[passwordcount] + " is correct");
                        }
                        catch
                        {
                            // If an exception occurs, write that the password is not correct to the text file
                            writer.WriteLine("Password " + passwords[passwordcount] + " is not correct");
                        }
                    }
                }
                else
                {
                    // If the PDF is not password protected, note this in the text file
                    writer.WriteLine("The PDF is not password protected.");
                }
            }

            Console.WriteLine("Verification results have been saved to: " + resultFilePath);
            Console.ReadKey();
        }
    }
}

Determine the Correct Password of a PDF in C#

Get a Free License

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

This article demonstrates how to add line numbers before chunks of text in a PDF page by using Spire.PDF for .NET.

Below is a screenshot of the input document.

Add Line Numbers to a PDF in C#, VB.NET

C#
using Spire.Pdf;
using Spire.Pdf.General.Find;
using Spire.Pdf.Graphics;
using System.Drawing;

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

     //Load PDF document
     doc.LoadFromFile(@"C:\Users\Administrator\Desktop\input.pdf");

     //Get the first page
     PdfPageBase page = doc.Pages[0];

     //Find specified text in the first line
     PdfTextFinder finder = new PdfTextFinder(page);
     finder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
     PdfTextFragment topLine = finder.Find("C# (pronounced See Sharp)")[0];

     //Get line height
     float lineHeight = topLine.Bounds[0].Height;

     //Get a Y coordinate for the starting position of line numbers
     float y = topLine.Bounds[0].Location.Y - 2;

     //Find specified text in the second line
     PdfTextFinder secondfinder = new PdfTextFinder(page);
     secondfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
     PdfTextFragment secondLine = secondfinder.Find("language. C#")[0];

     //Calculate line spacing
     float lineSpacing = secondLine.Bounds[0].Top - topLine.Bounds[0].Bottom;

     //Find specified text in the last line
     PdfTextFinder bottomfinder = new PdfTextFinder(page);
     bottomfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord;
     PdfTextFragment bottomLine = bottomfinder.Find("allocation of objects")[0];

     //Get the bottom Y coordinate of the last line, which is the height of the line number area
     float height = bottomLine.Bounds[0].Bottom;

     //Create a font with the same size as the text in the PDF
     PdfFont font = new PdfFont(PdfFontFamily.TimesRoman, 11f);

     int i = 1;
     while (y < height)
     {
         //Draw line numbers at the beginning of each line
         page.Canvas.DrawString(i.ToString(), font, PdfBrushes.Black, new PointF(15, y));
         y += lineHeight + lineSpacing;
         i++;
     }

     //Save the document
     doc.SaveToFile("result.pdf");
        }
    }
}
VB.NET
Imports Spire.Pdf
Imports Spire.Pdf.General.Find
Imports Spire.Pdf.Graphics
Imports System.Drawing
 
Namespace AddLineNumber
    Class Program
        Shared  Sub Main(ByVal args() As String)
        'Create a PdfDocument object
        Dim doc As New PdfDocument()

        'Load PDF document
        doc.LoadFromFile("C:\Users\Administrator\Desktop\input.pdf")

        'Get the first page
        Dim page As PdfPageBase = doc.Pages(0)

        'Find specified text in the first line
        Dim finder As New PdfTextFinder(page)
        finder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord
        Dim topLine As PdfTextFragment = finder.Find("C# (pronounced See Sharp)")(0)

        'Get line height
        Dim lineHeight As Single = topLine.Bounds(0).Height

        'Get a Y coordinate for the starting position of line numbers
        Dim y As Single = topLine.Bounds(0).Location.Y - 2

        'Find specified text in the second line
        Dim secondfinder As New PdfTextFinder(page)
        secondfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord
        Dim secondLine As PdfTextFragment = secondfinder.Find("language. C#")(0)

        'Calculate line spacing
        Dim lineSpacing As Single = secondLine.Bounds(0).Top - topLine.Bounds(0).Bottom

        'Find specified text in the last line
        Dim bottomfinder As New PdfTextFinder(page)
        bottomfinder.Options.Parameter = Spire.Pdf.Texts.TextFindParameter.WholeWord
        Dim bottomLine As PdfTextFragment = bottomfinder.Find("allocation of objects")(0)

        'Get the bottom Y coordinate of the last line, which is the height of the line number area
        Dim height As Single = bottomLine.Bounds(0).Bottom

        'Create a font with the same size as the text in the PDF
        Dim font As PdfFont = New PdfFont(PdfFontFamily.TimesRoman, 11.0F)

        Dim i As Integer = 1
        While y < height
            'Draw line numbers at the beginning of each line
            page.Canvas.DrawString(i.ToString(), font, PdfBrushes.Black, New PointF(15, y))
            y += lineHeight + lineSpacing
            i += 1
        End While

        'Save the document
        doc.SaveToFile("result.pdf")

        End Sub
    End Class
End Namespace

Output

Add Line Numbers to a PDF in C#, VB.NET

We have introduced how to compare two Word documents in C# and VB.NET. From Spire.Doc V8.12.14, it supports to get the differences between two Word documents in a structure list. This article will show you how to use Spire.Doc to get the differences by comparing two Word documents.

C#
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Formatting.Revisions;
using System;

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

        {
            //Load the first Word document
            Document doc1 = new Document();
            doc1.LoadFromFile("Sample1.docx");

            //Load the second Word document
            Document doc2 = new Document();
            doc2.LoadFromFile("Sample2.docx");

            //Compare the two Word documents
            doc1.Compare(doc2, "Author");

            foreach (Section sec in doc1.Sections)
            {
                foreach (DocumentObject docItem in sec.Body.ChildObjects)
                {
                    if (docItem is Paragraph)
{
                        Paragraph para = docItem as Paragraph;
                        if (para.IsInsertRevision)
                        { 
                            EditRevision insRevison = para.InsertRevision;
                            EditRevisionType insType = insRevison.Type; 
                            string insAuthor = insRevison.Author; 
                            DateTime insDateTime = insRevison.DateTime; 
                        }

                        else if (para.IsDeleteRevision)
                        { 
                            EditRevision delRevison = para.DeleteRevision; 
                            EditRevisionType delType = delRevison.Type; 
                            string delAuthor = delRevison.Author; 
                            DateTime delDateTime = delRevison.DateTime; 
                        }

                        foreach (ParagraphBase paraItem in para.ChildObjects)
                        {
                            if (paraItem.IsInsertRevision)
                            { 
                                EditRevision insRevison = paraItem.InsertRevision; 
                                EditRevisionType insType = insRevison.Type; 
                                string insAuthor = insRevison.Author; 
                                DateTime insDateTime = insRevison.DateTime; 
                            }

                            else if (paraItem.IsDeleteRevision)
                            { 
                                EditRevision delRevison = paraItem.DeleteRevision; 
                                EditRevisionType delType = delRevison.Type; 
                                string delAuthor = delRevison.Author; 
                                DateTime delDateTime = delRevison.DateTime; 
                            }

                        }
                    }
                }
            }

            //Get the difference about revisions
            DifferRevisions differRevisions = new DifferRevisions(doc1);
            var insetRevisionsList = differRevisions.InsertRevisions;
            var deletRevisionsList = differRevisions.DeleteRevisions;      
        }
    }
 }
VB.NET
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Formatting.Revisions
Imports System

Namespace GetWordDifferences
    
    Class Program
        
        Private Shared Sub Main(ByVal args() As String)
            'Load the first Word document
            Dim doc1 As Document = New Document
            doc1.LoadFromFile("Sample1.docx")
            'Load the second Word document
            Dim doc2 As Document = New Document
            doc2.LoadFromFile("Sample2.docx")
            'Compare the two Word documents
            doc1.Compare(doc2, "Author")
            For Each sec As Section In doc1.Sections
                For Each docItem As DocumentObject In sec.Body.ChildObjects
                    If (TypeOf docItem Is Paragraph) Then
                        Dim para As Paragraph = CType(docItem,Paragraph)
                        If para.IsInsertRevision Then
                            Dim insRevison As EditRevision = para.InsertRevision
                            Dim insType As EditRevisionType = insRevison.Type
                            Dim insAuthor As String = insRevison.Author
                            Dim insDateTime As DateTime = insRevison.DateTime
                        ElseIf para.IsDeleteRevision Then
                            Dim delRevison As EditRevision = para.DeleteRevision
                            Dim delType As EditRevisionType = delRevison.Type
                            Dim delAuthor As String = delRevison.Author
                            Dim delDateTime As DateTime = delRevison.DateTime
                        End If
                        
                        For Each paraItem As ParagraphBase In para.ChildObjects
                            If paraItem.IsInsertRevision Then
                                Dim insRevison As EditRevision = paraItem.InsertRevision
                                Dim insType As EditRevisionType = insRevison.Type
                                Dim insAuthor As String = insRevison.Author
                                Dim insDateTime As DateTime = insRevison.DateTime
                            ElseIf paraItem.IsDeleteRevision Then
                                Dim delRevison As EditRevision = paraItem.DeleteRevision
                                Dim delType As EditRevisionType = delRevison.Type
                                Dim delAuthor As String = delRevison.Author
                                Dim delDateTime As DateTime = delRevison.DateTime
                            End If
                            
                        Next
                    End If
                    
                Next
            Next
            'Get the difference about revisions
            Dim differRevisions As DifferRevisions = New DifferRevisions(doc1)
            Dim insetRevisionsList = differRevisions.InsertRevisions
            Dim deletRevisionsList = differRevisions.DeleteRevisions
        End Sub
    End Class
End Namespace

A workbook containing multiple worksheets helps to centrally manage relevant information, but sometimes we have to split the worksheets into separate Excel files so that individual worksheets can be distributed without disclosing other information. In this article, you will learn how to split Excel worksheets into separate workbooks in C# and VB.NET using Spire.XLS for .NET.

Install Spire.XLS for .NET

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

PM> Install-Package Spire.XLS

Split Excel Sheets into Separate Files

The following are the main steps to split Excel sheets into separate workbooks using Spire.XLS for .NET.

  • Create a Workbook object
  • Load a sample Excel file using Workbook.LoadFromFile() method.
  • Declare a new Workbook variable, which is used to create new Excel workbooks.
  • Loop through the worksheets in the source document.
  • Initialize the Workbook object, and add the copy of a specific worksheet of source document into it.
  • Save the workbook to an Excel file using Workbook.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Xls;
using System;

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

            //Load an Excel document
            wb.LoadFromFile("C:\\Users\\Administrator\\Desktop\\data.xlsx");

            //Declare a new Workbook variable
            Workbook newWb;

            //Declare a String variable
            String sheetName;

            //Specify the folder path which is used to store the generated Excel files
            String folderPath = "C:\\Users\\Administrator\\Desktop\\Output\\";

            //Loop through the worksheets in the source file
            for (int i = 0; i < wb.Worksheets.Count; i++)
            {

                //Initialize the Workbook object
                newWb = new Workbook();

                //Remove the default sheets
                newWb.Worksheets.Clear();

                //Add the specific worksheet of the source document to the new workbook
                newWb.Worksheets.AddCopy(wb.Worksheets[i]);

                //Get the worksheet name
                sheetName = wb.Worksheets[i].Name;

                //Save the new workbook to the specified folder
                newWb.SaveToFile(folderPath + sheetName + ".xlsx", ExcelVersion.Version2013);
            }
        }
    }
}

C#/VB.NET: Split Excel Sheets into Separate Files

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 10 of 95
page 10