Tuesday, 24 March 2015

Print Report in MS word using StringBuilder in c# without using MS word dll



Step 1- Create a fileupload dialogue to set path of the file


Step 2- Write code on print button Click event

private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append("<h1 title='Header' align='Center'>Writing To Word File using windows form in c#</h1> ".ToString());
            strBuilder.Append("<br>".ToString());
            strBuilder.Append("<table border='1' align='Center'>".ToString());
            strBuilder.Append("<tr>".ToString());
            strBuilder.Append("<td style='width:100px;color:green'><b>amiT</b></td>".ToString());
            strBuilder.Append("<td style='width:100px;color:red'>India</td>".ToString());
            strBuilder.Append("</tr>".ToString());
            strBuilder.Append("</table>".ToString());
            string strPath =textBox1.Text+"Test"+DateTime.Now.ToString("hhmmss")+".doc";
            FileStream fStream = File.Create(strPath);
            fStream.Close();
            StreamWriter sWriter = new StreamWriter(strPath);
            sWriter.Write(strBuilder);
            sWriter.Close();

        }

//Result


No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...