Riya Mahanty

Riya Mahanty

  • NA
  • 64
  • 682

how to export datatable data to ms word with image in window

Apr 24 2017 4:41 AM
How to export datatable data to ms word in window application .
in the datatable i have some field with some image path , image come from server
i am trying this
string st = startdate.Text;
string ed = enddate.Text;
string strquery = "select a.[tital],a.[description],a.[facebook],a.[twitter],a.[linkedin],a.[website],a.[offerdetails], " +
",logo=(select ( case when ThumbnailImage='' then '0' else ThumbnailImage end)as ThumbnailImage from [dbo].[ImageLinks] b where b.Id=a.[image]),bannerimage=(select ( case when ThumbnailImage='' then '0' else ThumbnailImage end)as ThumbnailImage from [dbo].[ImageLinks] b where b.Id=a.bannerimageID)," +
"productimage=(select ( case when ThumbnailImage='' then '0' else ThumbnailImage end)as ThumbnailImage from [dbo].[ImageLinks] b where b.Id=a.productimageID),serviceimage=(select ( case when ThumbnailImage='' then '0' else ThumbnailImage end)as ThumbnailImage from [dbo].[ImageLinks] b where b.Id=a.serviceimageID)from [dbo].[ADs]" +
" a where (CASE WHEN LEFT(CreatedAt, 1) LIKE '[0-9]' THEN CONVERT(VARCHAR(10), CONVERT(datetime, CreatedAt, 1), 101) ELSE CONVERT(VARCHAR(10), CONVERT(datetime, CreatedAt, 109), 101) END)" +
"between (convert(varchar(15),'" + st + "',106)) and (convert(varchar(15),'" + ed + "',106)) order by a.[type] desc";
SqlDataAdapter da = new SqlDataAdapter(strquery, Properties.Settings.Default.MompreneursIndiaContext);
DataSet ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
string csv = string.Empty;
//Add the Header row for CSV file.
foreach (DataGridViewColumn column in dataGridView1.Columns)
{
csv += column.HeaderText + ',';
}
//Add new line.
csv += "\r\n";
//Adding the Rows
foreach (DataGridViewRow row in dataGridView1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
//Add the Data rows.
if (cell.Value != null)
{
csv += cell.Value.ToString().Replace(",", ";") + ',';
}
}
//Add new line.
csv += "\r\n";
}
//Exporting to CSV.
string folderPath = "C:\\CSV\\";
File.WriteAllText(folderPath + "DataGridViewExport.csv", csv);
In this code export my datatable date to word but not in a suitable format.
but only the text field.
i am new in window application. Can anyone help me please

Answers (1)