locked
Generate a word doc RRS feed

  • Question

  • User1581266955 posted
    Hello

    i try to generate a document word it's working with latin font. But i need to use hebrew and Arabic if you test the page here
    http://www.independza.com/client/exp/generateDOC/generate.aspx
    you could see in the document that it's not working with Hebrew

    public  void HtmlExportToWord(Object obj, EventArgs e){

    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.Buffer =true;
    HttpContext.Current.Response.ContentType="application/msword";
    HttpContext.Current.Response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
    HttpContext.Current.Response.AddHeader("Content-Disposition","attachment;filename=test.doc");
    HttpContext.Current.Response.Charset = "iso-8859-8 "; //UTF8
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1255"); //windows-1250
    HttpContext.Current.Response.Write( FreeTextBox1.Text);
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
    }

    Can you help me ?

    Bolo
    Monday, November 7, 2005 12:27 PM

All replies

  • User1581266955 posted
    Nobody Can help me ?
    Tuesday, November 8, 2005 7:21 AM
  • User-722164976 posted
    Setting the Charset and ContentEncoding to the Response object does not give Word any indicator of what encoding the page needs to be displayed in. Word uses the charset in the meta tag to decide which encoding to display the document in.  Your document is being written out in UTF-8 by default, so you'll need to write out the charset like this:

    HttpContext.Current.Response.Write("<head><meta content=\"text/html; charset=utf-8\" http-equiv=\"content-type\"/></head>");

    Next, the ContentEncoding is set to the local codepage, and unless you've specifically saved the content in that codepage, the data won't be interpreted correctly.  You'll either need to change it to UTF-8, like this:

    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8; 

    or it can be removed altogether and your solution should still work correctly.

    Hope this helps.  

    Tuesday, November 8, 2005 6:17 PM