C#/VB.NET How to Accept or Reject Tracked Changes in Excel?
The revision function can track all the revisions of the document and understand the revision process, which is a very useful function for the team to collaborate on document editing and review. When sending the workbook to others for review, we can enable the revision function. After the shared workbook is modified, the user can choose to accept or reject the data information modified by others when viewing the document. This article will introduce you in detail how to accept or reject revisions in Excel.
- Accept All Tracked Changes in a Workbook
- Reject All Tracked Changes in a Workbook
Programming Environment
In this test, Free Spire.XLS for
.NET is introduced into the program. The Spire.XLS.dll file can be referenced
by:
Method 1: Download Free
Spire.XLS for .NET locally,
unzip it, and install it. After the installation is complete, find
Spire.XLS.dll in the BIN folder under the installation path. Then open the
"Solution Explorer" in Visual Studio, right-click
"References", "Add Reference", and add a reference to the
dll file in the BIN folder of the local path to the program.
Method 2: Install via NuGet. It can be installed by the following 2 methods:
(1) You can open the
"Solution Explorer" in Visual Studio, right-click
"References", "Manage NuGet Packages", then search for
"Free Spire.XLS", and click "Install". Wait for the program
installation to complete.
(2) Copy the following content
to the PM console installation.
Install-Package FreeSpire.XLS
-Version 12.7
Accept All Tracked Changes in a Workbook
- Create a Workbook object.
- Load a sample Excel document using Workbook.LoadFromFile() method.
- Determine if the workbook has tracked changes using Workbook.HasTrackedChanges property.
- Accept all tracked changes in the workbook using Workbook.AcceptAllTrackedChanges() method.
- Save the result document using Workbook.SaveToFile() method.
Full Code
using Spire.Xls;
namespace AcceptTrackedChanges
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook object
Workbook workbook = new Workbook();
//Load a sample Excel document
workbook.LoadFromFile("Sample.xlsx");
//Determine if the workbook has tracked
changes
if (workbook.HasTrackedChanges)
{
//Accept all tracked changes in the workbook
workbook.AcceptAllTrackedChanges();
}
//Save the result document
workbook.SaveToFile("AcceptChanges.xlsx", FileFormat.Version2013);
}
}
}
Imports Spire.Xls
Namespace AcceptTrackedChanges
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a Workbook object
Dim workbook As Workbook = New Workbook()
'Load a sample Excel document
workbook.LoadFromFile("Sample.xlsx")
'Determine if the workbook has tracked
changes
If workbook.HasTrackedChanges Then
'Accept all tracked changes in the workbook
workbook.AcceptAllTrackedChanges()
End If
'Save the result document
workbook.SaveToFile("AcceptChanges.xlsx", FileFormat.Version2013)
End Sub
End Class
End Namespace
Effective Shot
Reject All Tracked Changes in a Workbook
- Create a Workbook object.
- Load a sample Excel document using Workbook.LoadFromFile() method.
- Determine if the workbook has tracked changes using Workbook.HasTrackedChanges property.
- Reject all tracked changes in the workbook using Workbook.RejectAllTrackedChanges() method.
- Save the result document using Workbook.SaveToFile() method.
Full Code
using Spire.Xls;
namespace AcceptTrackedChanges
{
class Program
{
static void Main(string[] args)
{
//Create a Workbook object
Workbook workbook = new Workbook();
//Load a sample Excel document
workbook.LoadFromFile("Sample.xlsx");
//Determine if the workbook has tracked
changes
if (workbook.HasTrackedChanges)
{
//Reject
all tracked changes in the workbook
workbook.RejectAllTrackedChanges();
}
//Save the result document
workbook.SaveToFile("RejectChanges.xlsx", FileFormat.Version2013);
}
}
}
Imports Spire.Xls
Namespace AcceptTrackedChanges
Friend Class Program
Private Shared Sub Main(ByVal args As String())
'Create a Workbook object
Dim workbook As Workbook = New Workbook()
'Load a sample Excel document
workbook.LoadFromFile("Sample.xlsx")
'Determine if the workbook has tracked
changes
If workbook.HasTrackedChanges Then
'Reject all tracked changes in the workbook
workbook.RejectAllTrackedChanges()
End If
'Save the result document
workbook.SaveToFile("RejectChanges.xlsx", FileFormat.Version2013)
End Sub
End Class
End Namespace
Effective Shot
Conclusion:
In this post, you have learned how to accept or reject tracked changes in Excel
in C#/VB.NET. Not only that, we also have other functions, such as, C#/VB.NET:
Split Excel Sheets into Separate Files, Insert
HTML-Formatted Rich Text into Excel Cell
and so on. Apart from that, if you'd like to learn more, you can visit this link to explore more about for
Spire.XLS for .NET.
Comments
Post a Comment