css_class_name_prefix property

HtmlSaveOptions.css_class_name_prefix property

Specifies a prefix which is added to all CSS class names. Default value is an empty string and generated CSS class names have no common prefix.

@property
def css_class_name_prefix(self) -> str:
    ...

@css_class_name_prefix.setter
def css_class_name_prefix(self, value: str):
    ...

Exceptions

exceptioncondition
RuntimeError (Proxy error(ArgumentException))The value is not empty and is not a valid CSS identifier.

Remarks

If this value is not empty, all CSS classes generated by Aspose.Words will start with the specified prefix. This might be useful, for example, if you add custom CSS to generated documents and want to prevent class name conflicts.

If the value is not None or empty, it must be a valid CSS identifier.

Examples

Shows how to save a document to HTML, and add a prefix to all of its CSS class names.

doc = aw.Document(MY_DIR + "Paragraphs.docx")

save_options = aw.saving.HtmlSaveOptions()
save_options.css_style_sheet_type = aw.saving.CssStyleSheetType.EXTERNAL
save_options.css_class_name_prefix = "myprefix-"

doc.save(ARTIFACTS_DIR + "HtmlSaveOptions.css_class_name_prefix.html", save_options)

with open(ARTIFACTS_DIR + "HtmlSaveOptions.css_class_name_prefix.html", "rt", encoding="utf-8") as file:
    out_doc_contents = file.read()

self.assertIn("<p class=\"myprefix-Header\">", out_doc_contents)
self.assertIn("<p class=\"myprefix-Footer\">", out_doc_contents)

with open(ARTIFACTS_DIR + "HtmlSaveOptions.css_class_name_prefix.css", "rt", encoding="utf-8") as file:
    out_doc_contents = file.read()

self.assertIn(
    ".myprefix-Footer { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt }\n" +
    ".myprefix-Header { margin-bottom:0pt; line-height:normal; font-family:Arial; font-size:11pt }\n",
    out_doc_contents)

See Also