0

i am converting aspx web page into ms word , its converting properly, but i am highlighting some text in my web page but its not reflecting in word. How can i get the proper text with yellow color highlight in word format after convert.

        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition",
        "attachment;filename=Text.doc");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        Page.DataBind();
        //Page.RenderControl(hw);
        Response.Output.Write(sw.ToString());
        Response.Flush();
  • Word files have a `docx` extension. not `doc, since 2007`. Your code doesn't generate any kind of Word file though, just an HTML page with a fake (and obsolete) content type. Find a library that creates *real* Word files instead – Panagiotis Kanavos Dec 02 '19 at 12:58
  • You'll find the [Open XML SDK here](https://github.com/OfficeDev/Open-XML-SDK). The docs [are here](https://learn.microsoft.com/en-us/office/open-xml/open-xml-sdk?redirectedfrom=MSDN). In the docs, the [getting started example](https://learn.microsoft.com/en-us/office/open-xml/structure-of-a-wordprocessingml-document#open-xml-sdk-code-example) shows how to create a simple document. The [How To](https://learn.microsoft.com/en-us/office/open-xml/word-processing) section on Word Processing shows how to perform various tasks like adding tables, formatting etc. – Panagiotis Kanavos Dec 02 '19 at 13:05

1 Answers1

0

Use Microsoft Office library, Microsoft.Office.Interop.Word; open the file and do the necessary formatting

.CharacterFormat.HighlightColor = Color.Yellow;
Paiseh99
  • 11
  • 2
  • This requires Word to run on the server. It actually starts and controls Word through OLE Automation. This simply *can't* be used on a server – Panagiotis Kanavos Dec 02 '19 at 13:01