I need to construct a template such that it will contain both static and dynamic fields. For instance we can think of a employee registration form
----------------------------------
First Name: Friend1_Name
Last Name: Friend1_Surname
.
.
so on
-----------------------------------
As you see left part (first Name, Last Name, Phone No) is static, so
always the same, but the right portion of the stickers are filled by the
data that comes from the database.
Is there a way to implement it
=> Administrators will construct the template, put some graphics in a
Word Template and, somehow, specify the dynamic parts of the template. After
constructing the tamplate admin will upload the template to a web directory.
I will write an C#.NET code in order to connect to database
and create a Word document from the template that is uplaoded.
How may i fill the dynamic fields programmatically at the web server?
Just tell me away to solve this problem in c#, a I need an answer.here is my code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Configuration;
using System.Web.Security;
using System.Globalization;
using System.IO;
using Word;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Web.DynamicData;
using System.Web.SessionState;
using Microsoft.Office.Core;
protected void Button2_Click(object sender, EventArgs e)
{
string sql = ("Insert into regis ( first_name, last_name, date_of_birth, sex, addres, suburb, postcode, transport, telephone, mobile, other, health, english_fluency, heighest_level_edu, bank, account_type, branch_number, account_number, company_name, company_address, company_postcode, company_from, company_to, referee_name_title, referee_phone, position_duties, reason_for_leaving, company_name1, company_address1, company_from1, company_to1, referee_name_title1, referee_phone1, position_duties1, reason_for_leaving1 ) values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox5.Text + "','" + DropDownList1.SelectedValue + "','" + TextBox4.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "','" + DropDownList3.SelectedValue + "','" + DropDownList2.SelectedValue + "','" + TextBox10.Text + "','" + TextBox15.Text + "','" + TextBox16.Text + "','" + TextBox17.Text + "','" + TextBox18.Text + "','" + TextBox20.Text + "','" + TextBox21.Text + "','" + TextBox22.Text + "','" + TextBox30.Text + "','" + TextBox31.Text + "','" + TextBox24.Text + "','" + TextBox25.Text + "','" + TextBox23.Text + "','" + TextBox26.Text + "','" + TextBox32.Text + "','" + TextBox33.Text + "','" + TextBox35.Text + "','" + TextBox36.Text + "','" + TextBox37.Text + "','" + TextBox38.Text + "','" + TextBox39.Text + "','" + TextBox40.Text + "')");
string constr = "server=SQLPROD; uid=fb; password=Cato123; database=registration";
SqlConnection conn = new SqlConnection(constr);
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
//Response.Redirect("Default1.aspx");
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox5.Text = "";
DropDownList1.SelectedValue = "false";
TextBox4.Text = "";
TextBox7.Text = "";
TextBox8.Text = "";
TextBox9.Text = "";
TextBox12.Text = "";
TextBox13.Text = "";
TextBox14.Text = "";
DropDownList3.SelectedValue = "false";
DropDownList2.SelectedValue = "false";
TextBox10.Text = "";
TextBox15.Text = "";
TextBox16.Text = "";
TextBox17.Text = "";
TextBox18.Text = "";
TextBox20.Text = "";
TextBox21.Text = "";
TextBox22.Text = "";
TextBox30.Text = "";
TextBox31.Text = "";
TextBox24.Text = "";
TextBox25.Text = "";
TextBox23.Text = "";
TextBox26.Text = "";
TextBox32.Text = "";
TextBox33.Text = "";
TextBox35.Text = "";
TextBox36.Text = "";
TextBox37.Text = "";
TextBox38.Text = "";
TextBox39.Text = "";
}
protected void Button3_Click(object sender, EventArgs e)
{
/*
Word.Application wrdApp;
Word_.Document wrdDoc;
Object oMissing = System.Reflection.Missing.Value;
Object oFalse = false;
Object oTrue = true;
Object oTemplate = "C:\\Users\\sdevi\\Documents\\Visual Studio 2010\\WebSites\australian staffing agency\\Application For Employment.dot";
Object oFileName = "C:\\Users\\sdevi\\Documents\\Visual Studio 2010\\WebSites\australian staffing agency\\Application For Employment.doc";
try
{
System.IO.File.Delete("Application For Employment.doc");
System.IO.File.Create("Application For Employment.doc");
}
catch(Exception ex)
{
}
wrdApp = new Word.Application( );
wrdApp.Visible = true;
wrdDoc = wrdApp.Documents.Add(ref oTemplate,ref oMissing,ref oMissing,ref oMissing);
foreach(Word.FormField frmField in wrdDoc.FormFields)
{
frmField.Result = "2";
}
wrdDoc.SaveAs(ref oFileName ,ref oMissing ,ref oTrue ,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oMissing,ref oTru,ref oTrue,ref
oMissing);
wrdDoc.Close(ref oTrue,ref oFalse,ref oMissing);
wrdDoc = null;
wrdApp = null;
}
*/
}
}