how to export data from datagrid to word??

G

Guest

I am having one grid..i want to export that grid to word..after doing only
two fields r coming ie serial no: and total..product name, quantity and
unitcost r not coming into the word...those three r from databasee...How can
i bring those three to the word...

the code looks like this...


object fileName = "C:\\Inetpub\\wwwroot\\eBilling\\jijo.doc";
object readOnly = false;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\StartOfDoc";
object oCurrentCell="\\Cell" ;
Word.ApplicationClass oWordApp = new Word.ApplicationClass();
try
{

Word.Document oWordDoc = oWordApp.Documents.Open(ref fileName,ref
missing,ref readOnly,ref missing, ref missing, ref missing,ref missing, ref
missing, ref missing,ref missing, ref missing, ref isVisible, ref missing,ref
missing,ref missing);


oWordDoc.Activate();

oWordApp.Selection.TypeParagraph();
oWordDoc.Content.Delete(ref missing,ref missing);
Word.Table oTable;
Word.Range wrdRng =oWordDoc.Bookmarks.Item(ref oEndOfDoc).Range;

oTable = oWordDoc.Tables.Add(wrdRng, DataGrid1.Items.Count, 5, ref missing,
ref missing);
oTable.Range.ParagraphFormat.SpaceAfter = 6;



int i,j;


for(i=0;i {
for(j=0;j<5;j++)
{

oTable.Cell(i+1,j+1).Range.Text=DataGrid1.Items.Cells[j].Text;


}
}



oWordDoc.DisableFeatures=true;
oWordDoc.Save();
oWordDoc.Close(ref missing,ref missing,ref missing);

Response.Redirect("C:\\Inetpub\\wwwroot\\eBilling\\jijo.doc");



}
catch(Exception ex)
{

oWordApp.Application.Quit(ref missing, ref missing, ref missing);
}
Response.Redirect("C:\\Inetpub\\wwwroot\\eBilling\\jijo.doc");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top