Export DataGrid to Excel - Set column width at certain Excel column

Hi,

 I am working on a function of exporting DataGrid to excel with following coding:

protected override void Render(HtmlTextWriter writer)

{

Response.ContentType =
"application/ms-excel";

Response.AddHeader("Content-Disposition", "inline;filename=test.xls");

DataTable dt = new DataTable();

...

DataGrid2.DataSource = dt;

DataGrid2.DataBind();

DataGrid2.RenderControl(writer);

}

I would like to set the column width at certain Excel column. However, the width cannot be controlled by setting the column width of DataGrid. Any methods to this?

 

0
Keimond
10/31/2007 9:10:16 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

1 Replies
838 Views

Similar Articles

[PageSpeed] 6

Hello, 

I think Excel is automatically expanding the size of the column to fit the largest data value.

Regards,

Louis

0
louisdegrazia
10/31/2007 1:25:54 PM
Reply:

Similar Artilces:

Export Datagrid to excel, bound column names not showing in excel file
 the bound column of the datagrid are not showing in the excel file I have exported a datagrid to excel, everthing show except the bound column However if the columns are not bound , then there is no problem and column names will show in the excel file The text of the html code that the datagrid.rendercotrol function generate, does not contain the bound column names I had to do work around ,alter the html code text and add the column  names.   My Code : Response.ContentType = "application/vnd.xls"Dim stringWrite As New System.IO.StringWriterDim htm...

Exporting in Excel without cells or excel columns merging for one column of data table(need sorting, data filters perfectly)
 Hi,   I have an issue with the excel exporting of the report using ssrs.  I am using only the body section for exporting to excel.  Here in the body i have an Image, Textbox(for Title), textbox2(for dates from,to) and below it i have a table having the columns used for showing the data.  The report gets generated but when i exported to excel, All the columns and rows in the excels sheets come close and its like there is no uniformity.  Few columsn of excel are covered under a single columsn of the data table.  So its making users feel uncomfortab...

Add dynamically column to dataGrid ==> problem with "Export dataGrid to Excel"
hi all users! i have a problem! please help me! i add dynamically column (itemTemplate) to dataGrid with code. i use this code: http://www.syncfusion.com//FAQ/aspnet/WEB_c4c.aspx#q379q then i use this code for exporting dataGrid info to Excel: http://www.dotnetjunkies.com/WebLog/stefandemetz/archive/2004/10/01/27337.aspx BUT i have problem! when i export dataGrid info to excel without dynamically column in dataGrid, it shows Excel file correctly. when i use dynamically column, it can't export to excel file correctly! please help me! kind regards Hi all programme...

Selecting columns from DataGrid for export to excel
Don't know if this can be done, but does anyone know if thru the datagrid you can choose the columns to export to excel? I know a datagrid can export to excel, but you get all the columns. If it cannot be done thru the datagrid, does anyone know how to do it outside???? Thanks Have you tried hiding the column before attempting to export?Bug [MCSD]...

export specific datagrid columns to excel
Hi All,            I have a datagrid which has 5 columns.Is there a way to export only the first 2 columns to excel.I have found tutorials which exports all the columns.But i need to export only the first 2 cloumns in the datagrid since those 2 only contain text and remaining are images and hyperlinks which i dont require.please help.Its very urgent.Thanks a lot. Regards, .netuser On your button click event to export to excel. Hide the columns you don't want, rebind the grid, then export to excel.Please remember to Mark As Answer if ...

Exporting datagrid with template columns to Excel
HI everyone, please help meI am trying to export a datagrid to excel and it breaks on "RenderControl" and i think its because my datagrid has template columns(because they are not literalControls) here is my code:         dgClients.DataBind()        Response.Clear()        Response.AddHeader("content-disposition", "attachment;filename=filename.xls")        Response.Charset = ""        Response.Cache.SetCacheability(Ht...

excel which is exported from datagrid not displaying columns
Hi All,            Might be a small pbm but as i am new to dot net i am facing this.I have exported data successfully to an excel sheet from the datagrid.But what i see is if there are 2 columns of data only that data is getting columns and all the remaining sheet looks completely white. I am pasting the code i have written below. The following code is in a link click event Response.Clear()Response.AddHeader("content-disposition", "attachment;filename=experiences.xls") Response.Charset = "" Response.Cache.S...

Binding excel sheet first column to datagrid first column.
Can any body help to resolve this problem. I need to bind my excel sheet first column value to datagrid first column and second column to datagrid sec col. ...etc. Excel col1=datagrid col , excel col2 =datagrid col2 and so on...  Frederic JohnsonSr. Software Engineer  hi plz create a test.xls in c drive and add some data in columns then paste below codethen .aspx cod is -----> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...

Table column width and export to PDF / Excel
When you set the TableColumn width for all the columns in your table in *.rdlc to 0in or 0cm, the reportviewer renders the columns with a "random" chosen width. This render output i would like to export to PDF and/or Excel, because we are generating reports on the fly, so have always dynamic data. On exporting the output gives no data (theoratically this is right, the columns are 0in). Is this a bug, if so and if not, does anyone a simple proper workaround or solution for me? HI, Ramr0m: After testing it, it does render with a certian with when you set the width to be 0. I supp...

Export gridview to Excel while omitting certain columns.
Hello, I use the following code to export a gridview to an Excel document:  1 public override void VerifyRenderingInServerForm(Control GridView1) 2 { 3 // Confirms that an HtmlForm control is rendered for the 4 // specified ASP.NET server control at run time. 5 // No code required here. 6 } 7 8 9 protected void btnReport_Click(object sender, EventArgs e) 10 { 11 ExportToExcel("Report.xls", GridView1); 12 } 13 14 protected void ExportToExcel(string strFileName, GridVi...

Handling control columns when exporting a GridView to Excel
Hi, I'm using this well published code to export the contents of a gridview to excel i nresponse to a button click, but in all nearly examples I've seen it gives the 'Must be between TAGS' error messege if there are any controls in the grid, my particular problem is there's tickbox's - here's the code =========================================================   Protected Sub ExportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim stringWrite As New System.IO.StringWriter Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite) 'This works as long as t...

Export to Excel Currency Format and Column Widths
Hi everyone.  I have a page which is set to open in Excel using the contenttype param.  It works just fine and opens up the page which contains a dynamically built asp:Table with all of the formulas populated in the right places, etc.I have 2 issues however.  First, the negative currency numbers are showing as the Excel standard red parentheses surrounded ( $ 4,2342.00) , I need it to have the negative sign and be black.  Is there a few settings I can throw into the codebehind to make this work, or perhaps in the cell where the formula exists?Second, no matter what I size...

Export Datagrid to Excel without the Template column
Hi, I want to export my datagrid to excell. This worked until I added a template column to my datagrid. The template column contains a link button that delets a row. When I try to export to exel I get a runtime error.Here is the code I'm using for excel and it does work as long as I don't add any template columns.        Response.Clear()        Response.Buffer = True        Response.ContentType = "application/vnd.ms-excel"        Response.ContentEncoding...

Exporting to Excel the datagrid content in c# , the width is not consisitent for excel cell.
 I am using datagrid , it contains rows and cells like grouped format. But i am exporting to excel, the width of the excel cell is not correctly fit the content of the cell. So how to solve it.Time and Tide never waits for none. Hi azhagu_02, You can set the style in css and export css with DataGrid. Have a look at this link about how to export css with GridView: http://www.socalmp.com/blog/template_permalink.asp?id=94 Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

when export to excel, how can i not export some columns?
i use ReportViewer control in .aspx page.  when export to excel, i don't want to export some columns.  how can i do that? I appreciate your help.LynnPlease mark replies that have helped you as answers. Hi,Based on my experience, we couldn't achieve it. In this scenario, I suggest to export the data from the dataset to the excel directly. Please check the following link.http://sunilksaini.blogspot.com/2007/07/export-dataset-to-excel.html Best regards,Hunters. ...

Web resources about - Export DataGrid to Excel - Set column width at certain Excel column - asp.net.presentation-controls

Want to preview our new DataGrid for Xamarin.Forms?
tl;dr Zumero.DataGrid is a Xamarin.Forms control for displaying data in rows and columns. If you would be interested in testing and previewing ...

Mad King DataGrid
This post is about scrolling in WPF and the egocentric DataGrid control. I’ll give the project background but if all you’re interested in is ...

Stack Overflow
Stack Exchange log in - careers - chat - meta - about - faq Questions Tags Users Badges Unanswered Ask Question Top Questions interesting 295 ...

Microsoft Silverlight - Wikipedia, the free encyclopedia
Microsoft Silverlight is an application framework for writing and running rich Internet applications , with features and purposes similar to ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Casaba Security » Products » X5s Testing Tool For Finding XSS Vulnerabilities
Security analysis, consulting, development and testing partners who understand your business strategy.

CodeGuru - Microsoft developers related ideas, articles, tips, tricks, comments, downloads, and so much ...
CodeGuru is where developers can come to share ideas, articles, questions, answers, tips, tricks, comments, downloads, and so much more related ...

Caliburn Micro: WPF, Silverlight, WP7 and WinRT/Metro made easy.
A small, yet powerful framework designed for WPF, Silverlight and WP7. It implements a variety of UI patterns for solving real-world problems. ...

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 11 Jul 2012

license-discuss@opensource.org: 11636: first draft of license proliferation committee report
FYI,the first draft report of the OSI's License Proliferation Committee.To join the OSI's license proliferation discuss email list, send anemail ...

Resources last updated: 12/23/2015 11:20:25 PM