Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends
iam importing data in excel ,my code is

C#
string attachment = "attachment; filename=Sheet1.xls";
              Response.ClearContent();
              Response.AddHeader("content-disposition", attachment);
              Response.ContentType = "application/vnd.ms-excel";


it is importing fine but i want to set word wrap property, how can i do that
Posted
Updated 10-Mar-12 0:48am
v2
Comments
Aniket Yadav 11-Mar-12 8:44am    
from where are you exporting the data to excel?

1 solution

If you are exporting the data from gridview then use the following

On Export Button Click Event

C#
//Before exporting you can wrap the words by making cell.wrap = true

  For Each Row In GridView1.Rows
      For Each Cell In Row.Cells
       Cell.Wrap = True
      Next
    Next
 
Share this answer
 
v2
Comments
srilekhamenon 12-Mar-12 3:01am    
Your solution is good but iam using datatable my code is

protected void btnclose0_Click(object sender, EventArgs e)
{
try
{

DataTable dt = c1.SelectDT("SELECT row_number() over (order by p_id)Sno,Tbl_ProductsuperCategory.ProductsuperCategory,Tbl_ProductCategory.ProductCategory,product_details.p_id as ProductId,product_details.pr_img as ProductImage,product_details.pr_cat as ProductCategoryId,product_details.pr_name as ProductName,product_details.dealer_price as DealerPrice,product_details.retailer_price as RetailerPrice,product_details.special_price as SpecialPrice,product_details.featured as Featured,product_details.special as Special,product_details.new as New,product_details.date as Dte,product_details.p_time as Tme,product_details.pr_item_code as Itemcode,product_details.pr_age_range as AgeRange,product_details.pr_series as Series,product_details.pr_author_name as AuthName,product_details.pr_author_desc as AuthDesc,product_details.pr_book_field as BookField,product_details.pr_related_code as RelatedCode,product_details.pr_searchable_keywords as SearchKey,product_details.pr_ebp as EBP,product_details.pr_gst as GST,product_details.pr_des as ProductDesc FROM product_details left outer JOIN Tbl_ProductCategory ON Tbl_ProductCategory.ProductCategoryId = product_details.pr_cat left outer JOIN Tbl_ProductsuperCategory ON Tbl_ProductsuperCategory.ProductsuperCategoryId = Tbl_ProductCategory.ProductsuperCategoryId", "s");
if (dt.Rows.Count == 0)
{
Response.Write("<script>alert('There Is No Product Details to be Exported'); window.location='ExportXls.aspx';</script>");
}
else
{
string attachment = "attachment; filename=Sheet1.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();

}
}
catch (Exception er)
{ }

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900