Sqlserver to excel,Create excel file in read only

Posted by Raja_89 under C# on 3/7/2013 | Points: 10 | Views : 1356 | Status : [Member] | Replies : 3
Hai Techie
How can i create a excel file with read only option and also if possible the data in the cell is visible from the following code



SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Iwens_Database;User ID=a;Password=abc;Integrated Security=SSPI;");
sqlquery = "SELECT E_id, E_Name, E_Address, E_Contact_No, E_Email, DOEn, E_noi, E_coursename, E_year, E_companyname, E_others, E_design, E_Selected, E_Followup FROM dbo.Enquiry_table";
SqlDataAdapter sda = new SqlDataAdapter(sqlquery, con);
DataTable dt = new DataTable();
sda.Fill(dt);
string attachment = "attachment; filename=enquiryed.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");

int i;
foreach (DataRow dr in dt.Rows)
{
tab = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}



Regards




Responses

Posted by: Sakthi.Singaravel on: 3/7/2013 [Member] Silver | Points: 25

Up
0
Down
http://csharp.net-informations.com/excel/csharp-excel-export.htm

Regards,
Singaravel M

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja_89 on: 3/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hai
Thanks
If it possible to edit the above code to fulfill the condition


Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 3/8/2013 [Member] Silver | Points: 25

Up
0
Down
just change the connection string and query...
That's all...

Regards,
Singaravel M

Raja_89, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response