SlideShare a Scribd company logo
1 of 4
How to Use C# Insert Comments in Word

This article is mainly telling you how to use C# insert comments in Word.

Comments in MS Word like track changes which used to insert information without overwriting
on original text. Usually comments are for readers to ask author questions or indicate an area that
is unclear. Or comments are for authors to make it easier to understand his/her ideas. It’s very
useful to insert comments in Word.

Insert comments in Word with MS Word can be very easy if you have MS Office installed on your
system. This guide can be found here. Here I want to introduce another solution which is use C#
insert comments in Word. Through C#, there is possible to edit Word without MS Office installed.
Spire.Doc, a .NET Word component can help us use C# insert comments in Word and also can do
other editable jobs.

Download Spire.Doc (or Spire.Office which include Spire.Doc) with .NET Framework 2.0 (or
above) together.

Spire.Doc presents you an easy way to insert a comment into the word document. There are two
forms of the comment in Spire.Doc, simple and complex comments.

Insert Simple Comments
Suppose we have written text in the word document. Now we can specify a position to make a
comment. Also we can set the author and the initial of the comment in comment.Format.Author
and comment.Format.Initial methods. Use the code below to use C# insert comments in Word:

01   using System;
02   using System.Drawing;
03   using Spire.Doc;
04   using Spire.Doc.Documents;
05   using Spire.Doc.Fields;
06
07   namespace MailMerge
08   {
09     class Program
10     {
11        static void Main(string[] args)
12        {
13           //Create a new document
14           Document document = new Document();
15
16          //Create a section
17          Section section = document.AddSection();
18
19         //Add a paragraph
20         Paragraph paragraph = section.AddParagraph();
21
22         //Style
23         ParagraphStyle style = new ParagraphStyle(section.Document);
24         style.Name = "style";
25         style.ApplyBaseStyle(style.Name);
26         style.CharacterFormat.Font = new Font("Arial", 10f);
27         section.Document.Styles.Add(style);
28
29         //Add a text
30         String str = "Science (from the Latin scientia, meaning "knowledge") ";
31         paragraph.AppendText(str);
32
33         //Simple comment
34         Comment comment = paragraph.AppendComment("Not given in this file.");
35         comment.Format.Author = "Harry Hu";
36         comment.Format.Initial = "HH";
37         paragraph.ApplyStyle(style.Name);
38
39         //Save doc file.
40         document.SaveToFile("Sample.doc", FileFormat.Doc);
41
42         //Launching the MS Word file.
43         System.Diagnostics.Process.Start("Sample.doc");
44     }
45   }
46 }



Insert Complex Comments:
To insert complex comments, we need use paragraph.AppendComment("comment text") method
to insert comment into the document. And then, use comment.AddItem(text) to specify the text
which we are making comment for. We can set the author and initial of the comment in
comment.Format.Author and comment.Format.Initial methods. The code below is for you to use
C# insert complex comments.

01   using System;
02   using System.Drawing;
03   using Spire.Doc;
04   using Spire.Doc.Documents;
05   using Spire.Doc.Fields;
06
07   namespace MailMerge
08 {
09     class Program
10     {
11        static void Main(string[] args)
12        {
13           //Create a new document
14           Document document = new Document();
15
16           //Create a section
17           Section section = document.AddSection();
18
19           //Add a paragraph
20           Paragraph paragraph = section.AddParagraph();
21
22           //style
23           ParagraphStyle style = new ParagraphStyle(section.Document);
24           style.Name = "style";
25           style.CharacterFormat.FontName = "Arial";
26           style.CharacterFormat.FontSize = 9;
27           style.ParagraphFormat.LineSpacing = 1.5F * 12F;
28           style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
29           section.Document.Styles.Add(style);
30
31           //Add a paragraph
32           paragraph = section.AddParagraph();
33           paragraph.AppendText("(All text and pictures are from ");
34
35           //Append the text which you want to make comment for
36           TextRange text = paragraph.AppendText("Wikipedia");
37
38           //Make comment
39                                                                Comment     comment   =
paragraph.AppendComment("http://en.wikipedia.org/wiki/Science");
40           comment.AddItem(text);
41           comment.Format.Author = "Harry Hu";
42           comment.Format.Initial = "HH";
43
44           //Continue the paragraph
45           paragraph.AppendText(", the free encyclopedia)");
46           paragraph.ApplyStyle(style.Name);
47
48           //Save doc file.
49           document.SaveToFile("Sample.doc", FileFormat.Doc);
50
51       //Launching the MS Word file.
52       System.Diagnostics.Process.Start("Sample.doc");
53     }
54   }
55 }



Full Demo



More about Spire.Doc
Download Spire.Doc
Purchase Spire.Doc

More Related Content

Similar to C# insert comments in word

PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7iText Group nv
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210Mahmoud Samir Fayed
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxssuser454af01
 
Library management system
Library management systemLibrary management system
Library management systemsiddiqui241993
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and pluginsStephanie Wells
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010vchircu
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxemelyvalg9
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity FrameworksRich Helton
 
The Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxThe Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxjmindy
 
Microsoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellMicrosoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellAditya Sharma
 
Unit 1.3 Introduction to Programming (Part 1)
Unit 1.3 Introduction to Programming (Part 1)Unit 1.3 Introduction to Programming (Part 1)
Unit 1.3 Introduction to Programming (Part 1)Intan Jameel
 

Similar to C# insert comments in word (20)

PDF made easy with iText 7
PDF made easy with iText 7PDF made easy with iText 7
PDF made easy with iText 7
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210
 
FileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docxFileWrite.javaFileWrite.java  To change this license header.docx
FileWrite.javaFileWrite.java  To change this license header.docx
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
Library management system
Library management systemLibrary management system
Library management system
 
Soa lab
Soa lab   Soa lab
Soa lab
 
srgoc
srgocsrgoc
srgoc
 
T4 / Code Generation
T4 / Code GenerationT4 / Code Generation
T4 / Code Generation
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and plugins
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
Creating web form
Creating web formCreating web form
Creating web form
 
Creating web form
Creating web formCreating web form
Creating web form
 
Student NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docxStudent NameClassDateVBScript IP File ReportIn the space provide.docx
Student NameClassDateVBScript IP File ReportIn the space provide.docx
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
Sql Injection and Entity Frameworks
Sql Injection and Entity FrameworksSql Injection and Entity Frameworks
Sql Injection and Entity Frameworks
 
The Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docxThe Lab assignment will be graded out of 100 points.  There are .docx
The Lab assignment will be graded out of 100 points.  There are .docx
 
Microsoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShellMicrosoft Information Protection Implementation using C# and PowerShell
Microsoft Information Protection Implementation using C# and PowerShell
 
Unit 1.3 Introduction to Programming (Part 1)
Unit 1.3 Introduction to Programming (Part 1)Unit 1.3 Introduction to Programming (Part 1)
Unit 1.3 Introduction to Programming (Part 1)
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 

More from Chen Stephen

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersChen Stephen
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenChen Stephen
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenChen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2Chen Stephen
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rotChen Stephen
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web appsChen Stephen
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8Chen Stephen
 
C# excel set excel number style
C# excel   set excel number styleC# excel   set excel number style
C# excel set excel number styleChen Stephen
 
C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chartChen Stephen
 

More from Chen Stephen (11)

Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of BlockbustersUpcoming Film Year of 2014 Highlights - A Year of Blockbusters
Upcoming Film Year of 2014 Highlights - A Year of Blockbusters
 
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 HalloweenTop 10 Horror Thriller Movies to Watch in 2013 Halloween
Top 10 Horror Thriller Movies to Watch in 2013 Halloween
 
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be ForgottenTop 10 Classic Valentine's Day Movies that Should NOT be Forgotten
Top 10 Classic Valentine's Day Movies that Should NOT be Forgotten
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
A nightmare on elm street 2
A nightmare on elm street 2A nightmare on elm street 2
A nightmare on elm street 2
 
How to prevent code rot
How to prevent code rotHow to prevent code rot
How to prevent code rot
 
5 ui tips for web apps
5 ui tips for web apps5 ui tips for web apps
5 ui tips for web apps
 
A developer's first impressions for windows 8
A developer's first impressions for windows 8A developer's first impressions for windows 8
A developer's first impressions for windows 8
 
C# excel set excel number style
C# excel   set excel number styleC# excel   set excel number style
C# excel set excel number style
 
C# excel bar chart
C# excel bar chartC# excel bar chart
C# excel bar chart
 
Listview to dif
Listview to difListview to dif
Listview to dif
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringWSO2
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)Samir Dash
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceIES VE
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaWSO2
 

Recently uploaded (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 

C# insert comments in word

  • 1. How to Use C# Insert Comments in Word This article is mainly telling you how to use C# insert comments in Word. Comments in MS Word like track changes which used to insert information without overwriting on original text. Usually comments are for readers to ask author questions or indicate an area that is unclear. Or comments are for authors to make it easier to understand his/her ideas. It’s very useful to insert comments in Word. Insert comments in Word with MS Word can be very easy if you have MS Office installed on your system. This guide can be found here. Here I want to introduce another solution which is use C# insert comments in Word. Through C#, there is possible to edit Word without MS Office installed. Spire.Doc, a .NET Word component can help us use C# insert comments in Word and also can do other editable jobs. Download Spire.Doc (or Spire.Office which include Spire.Doc) with .NET Framework 2.0 (or above) together. Spire.Doc presents you an easy way to insert a comment into the word document. There are two forms of the comment in Spire.Doc, simple and complex comments. Insert Simple Comments Suppose we have written text in the word document. Now we can specify a position to make a comment. Also we can set the author and the initial of the comment in comment.Format.Author and comment.Format.Initial methods. Use the code below to use C# insert comments in Word: 01 using System; 02 using System.Drawing; 03 using Spire.Doc; 04 using Spire.Doc.Documents; 05 using Spire.Doc.Fields; 06 07 namespace MailMerge 08 { 09 class Program 10 { 11 static void Main(string[] args) 12 { 13 //Create a new document 14 Document document = new Document(); 15 16 //Create a section 17 Section section = document.AddSection(); 18
  • 2. 19 //Add a paragraph 20 Paragraph paragraph = section.AddParagraph(); 21 22 //Style 23 ParagraphStyle style = new ParagraphStyle(section.Document); 24 style.Name = "style"; 25 style.ApplyBaseStyle(style.Name); 26 style.CharacterFormat.Font = new Font("Arial", 10f); 27 section.Document.Styles.Add(style); 28 29 //Add a text 30 String str = "Science (from the Latin scientia, meaning "knowledge") "; 31 paragraph.AppendText(str); 32 33 //Simple comment 34 Comment comment = paragraph.AppendComment("Not given in this file."); 35 comment.Format.Author = "Harry Hu"; 36 comment.Format.Initial = "HH"; 37 paragraph.ApplyStyle(style.Name); 38 39 //Save doc file. 40 document.SaveToFile("Sample.doc", FileFormat.Doc); 41 42 //Launching the MS Word file. 43 System.Diagnostics.Process.Start("Sample.doc"); 44 } 45 } 46 } Insert Complex Comments: To insert complex comments, we need use paragraph.AppendComment("comment text") method to insert comment into the document. And then, use comment.AddItem(text) to specify the text which we are making comment for. We can set the author and initial of the comment in comment.Format.Author and comment.Format.Initial methods. The code below is for you to use C# insert complex comments. 01 using System; 02 using System.Drawing; 03 using Spire.Doc; 04 using Spire.Doc.Documents; 05 using Spire.Doc.Fields; 06 07 namespace MailMerge
  • 3. 08 { 09 class Program 10 { 11 static void Main(string[] args) 12 { 13 //Create a new document 14 Document document = new Document(); 15 16 //Create a section 17 Section section = document.AddSection(); 18 19 //Add a paragraph 20 Paragraph paragraph = section.AddParagraph(); 21 22 //style 23 ParagraphStyle style = new ParagraphStyle(section.Document); 24 style.Name = "style"; 25 style.CharacterFormat.FontName = "Arial"; 26 style.CharacterFormat.FontSize = 9; 27 style.ParagraphFormat.LineSpacing = 1.5F * 12F; 28 style.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple; 29 section.Document.Styles.Add(style); 30 31 //Add a paragraph 32 paragraph = section.AddParagraph(); 33 paragraph.AppendText("(All text and pictures are from "); 34 35 //Append the text which you want to make comment for 36 TextRange text = paragraph.AppendText("Wikipedia"); 37 38 //Make comment 39 Comment comment = paragraph.AppendComment("http://en.wikipedia.org/wiki/Science"); 40 comment.AddItem(text); 41 comment.Format.Author = "Harry Hu"; 42 comment.Format.Initial = "HH"; 43 44 //Continue the paragraph 45 paragraph.AppendText(", the free encyclopedia)"); 46 paragraph.ApplyStyle(style.Name); 47 48 //Save doc file. 49 document.SaveToFile("Sample.doc", FileFormat.Doc); 50
  • 4. 51 //Launching the MS Word file. 52 System.Diagnostics.Process.Start("Sample.doc"); 53 } 54 } 55 } Full Demo More about Spire.Doc Download Spire.Doc Purchase Spire.Doc