Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Aug 08, 2020 8:49 pm

How can I go about deleting a custom style from Document.Styles?
The StyleCollection has an Add method but no Remove or Delete method.

Spire.Doc version: 7.9.9

weijenchen84
 
Posts: 2
Joined: Thu Oct 04, 2018 3:39 pm

Mon Aug 10, 2020 7:33 am

Hi

Thanks for your post.
Sorry that our Spire.Doc does not support removing custom styles at present. We will consider adding it as a new feature into our upgrade list. Once this feature is done, I will inform you.

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Tue Aug 11, 2020 3:28 am

Thank you for your reply. Please do let us know when the feature becomes available.

weijenchen84
 
Posts: 2
Joined: Thu Oct 04, 2018 3:39 pm

Tue Aug 11, 2020 5:57 am

Hi

Thanks for your feedback.
Sure, I will keep you informed once there is any meaningful progress. Wish you a nice day!

Sincerely,
Lynn
E-iceblue support team
User avatar

lynn.zhang
 
Posts: 57
Joined: Mon Jul 27, 2020 2:27 am

Tue Sep 30, 2025 7:51 am

Hello,

Thanks for your patient waiting.
I'm glad to inform you that the feature has been finished. Welcome to download and test [Spire.Doc Pack(hot fix) Version:13.9.10].
Our website link: https://www.e-iceblue.com/Download/download-word-for-net-now.html
NuGet links:
https://www.nuget.org/packages/Spire.Doc/13.9.10
https://www.nuget.org/packages/Spire.Docfor.NETStandard/13.9.10

Sample code:
Code: Select all
string pStyleName = "testStyle";
Document document = new Document();
ParagraphStyle pStyle = (ParagraphStyle)document.Styles.Add(StyleType.ParagraphStyle, pStyleName);
pStyle.CharacterFormat.FontName = "Calibri";
pStyle.CharacterFormat.FontSize = 16;
pStyle.CharacterFormat.Bold = true;
pStyle.CharacterFormat.TextColor = Color.DarkRed;
Section section = document.AddSection();
Paragraph para = section.AddParagraph();
para.ApplyStyle(pStyle);
para.AppendText("Hello world!");
Style firstParaStyle = document.FirstSection.Body.FirstParagraph.Format.Style;
document.SaveToFile(outputDocxFile1, FileFormat.Docx);
document.Styles[pStyleName].RemoveSelf();
document.SaveToFile(outputDocxFile2, FileFormat.Docx);


If you have any questions, please let us know.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc