Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm to generate word document using HTML i need help in arranging the margins and change the page orientation to landscape.

I have used following method to generate word document :

What I have tried:

C#
 Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename= "+_Labelname.Text+".doc");
        Response.Charset = "";
        Response.ContentType = "application/vnd.ms-word ";
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        string HTMLdata = "<HTML><HEAD></HEAD><BODY><BR><BR><BR><BR><BR>"+
        "<p style=\"text-align: right;\"><span style=\"font-size:12px;\"><span style=\"font-family:Calibri (Body),serif;\">SGH-" + _Labelvouno.Text + "</span></span></p>" +
        
        "<p style=\"text-align: center;\"><span style=\"font-size:22px;\"><span style=\"font-family:Lucida Calligraphy,serif;\">Voucher for him</span></span></p>" +
       "<BR><BR>" +
       "<tr><Center><span style=\"font-size:25px;\"><span style=\"font-family:Book Antiqua,serif;\">We are pleased to issue a discount voucher to<BR/> Mr. " + _Labelname.Text + " Mobile " + _Labelmobile.Text + ".<BR> " +
       "<Center><span style=\"font-size:25px;\"><span style=\"font-family:Book Antiqua,serif;\">Under this voucher he is entitled to get " + _Labeldisc.Text + " Discount on<BR>" +
       "<Center><span style=\"font-size:25px;\"><span style=\"font-family:Book Antiqua,serif;\">" + _Labelcamp.Text + "<BR><BR>" +
"<Center><span style=\"font-size:15px;\"><span style=\"font-family:Lucida Calligraphy,serif;\">For your appointment<BR>" +
 "</B></BODY></HTML>";
        hw.Write(HTMLdata);
        Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
Posted
Updated 1-Mar-16 16:01pm
Comments
ZurdoDev 29-Feb-16 9:36am    
You haven't created a word document. You've created an html document. If you want to make a word document I believe many people use OpenXML.
Member 11746885 29-Feb-16 9:54am    
I'm new to C#, can you give me some tips of doing so
ZurdoDev 29-Feb-16 9:57am    
This may help, http://www.codeproject.com/Articles/20998/Basics-of-OpenXML-Word-for-Beginners
Member 11746885 8-Mar-16 5:24am    
Thanks this helped me a lot, but the issue now which i'm facing is that wordprocessingdcoument is saving on server i want it to be saved on client machine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900