Certain Style names not preserved while converting dox to html and then back to docx

If the user creates custom style with the Name “#ABC Heading 1” during round trip from docx to html and back to docx then name is changed to ABCHeading1 or sometime ABCHeading1_0 instead of “#ABC Heading 1”

@cyrusdaru1 MS Word allows whitespaces and hash # characters in the style name, HTML does not, so these characters are trimmed. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Style style = doc.Styles.Add(StyleType.Paragraph, "#ABC Style1");
style.Font.Bold = true;

builder.ParagraphFormat.Style = style;
builder.Write("This is a test paragraph");

doc.Save(@"C:\Temp\out.docx");

HtmlSaveOptions options = new HtmlSaveOptions();
options.PrettyFormat = true;
options.CssStyleSheetType = CssStyleSheetType.Embedded;
doc.Save(@"C:\Temp\out.html", options);

In MS Word output document style name will be #ABC Style1, but HTML will look like this:

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="Content-Style-Type" content="text/css" />
		<meta name="generator" content="Aspose.Words for .NET 22.11.0" />
		<title>
		</title>
		<style type="text/css">
			body { font-family:'Times New Roman'; font-size:12pt }
			p { margin:0pt }
			.ABCStyle1 { font-weight:bold }
		</style>
	</head>
	<body>
		<div>
			<p class="ABCStyle1" style="font-size:10pt">
				<span>This is a test paragraph</span>
			</p>
		</div>
	</body>
</html>

And class name will be ABCStyle1.

Also, please, note that HTML and MS Word documents models are quite different, this makes it difficult and sometimes impossible to get 100% fidelity after Word->HTML->Word roundtrip.

Hi, I need to preserve the styles in round trip can u please share with me what logic aspose uses to name the styles while generating the html . For sure u are not using the styleid that is available in word xml . Once I have the logic I can write the code to preserve the style

@cyrusdaru1 Actually, you are right, Aspose.Words uses the same name for class in CSS as it uses for styleId in styles.xml. It is generated by replacing all characters except -, A-Z, a-z, 0-9 and checking for duplicates in the style ids map, in case of duplicate name number is appended to the style id.