Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Change column width during Excel export

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Lester  Mosley - 25 Mar 2008 19:25 GMT
I am having trouble adjusting the column width when exporting from an
ASP.net web page.

I don't really want to have a sotred formated excel page and prefer to
do it by code within the display page. (When user enters the data and
requests report to run, it brings back a new page, then the user can
clcik on a button to export to excel)

I have achieved in formatting the header to a different color, as well
as adding a header with what report they have run, or add dates if it
was a custom date range. using the lower code

Response.Write("<font size=4><center>" & "Report: " & lbl_title.Text &
" " & Now.Date & "</center></font>")    ' Adds title to Excel Sheet

dg_Report.HeaderStyle.BackColor = Drawing.Color.LightSkyBlue  ' Colors
header row in grid and not sheet.

dg_Report.ItemStyle.VerticalAlign = VerticalAlign.Top

However I am unable to make a column width wider at all.. is there any
suggestions?
I have tried the below code with out success: (and yes I know they are
commented out at the moment, I just copied direct from code..

'dg_Report.Columns(9).ItemStyle.Width.Pixel(450) ' -- Won't work
'dg_Report.HeaderStyle.Width.Equals(20) ' -- Won't Work
'dg_Report.Columns("Description").HeaderStyle.Width =
System.Web.UI.WebControls.Unit.Pixel(100) ' -- Won't Work
'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work
Masudur - 25 Mar 2008 20:13 GMT
> I am having trouble adjusting the column width when exporting from an
> ASP.net web page.
[quoted text clipped - 27 lines]
>  'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
>  'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work

Hi..

how about traverse the rows of datagrid and manually generate the
report using a html table...

http://aspalliance.com/725_CodeSnip_Export_a_DataGrid_to_a_Formatted_Excel_Sprea
dsheet


and set the html table's cell that is <TD> is width to a specific
width...

Not sure though cause i found a post that says its not going to
happen...

http://www.velocityreviews.com/forums/t112076-export-to-excel-from-aspnet.html

Thanks
Masudur
bruce barker - 25 Mar 2008 22:47 GMT
if you want to specify columns withds, multiple sheets, sheet name, etc. you
shoudl be producing an xml work book. the xml is easy, and you can specifiy
all the properties. a simple wookbook:

<?xml version="1.0"?>
<ss:Workbook xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
   <ss:Worksheet ss:Name="MySheet">
       <ss:Table>
           <ss:Column ss:Width="80"/>
          <ss:Column ss:Width="80"/>
           <ss:Row>
               <ss:Cell>
                   <ss:Data ss:Type="String">Hello</ss:Data>
               </ss:Cell>
               <ss:Cell>
                   <ss:Data ss:Type="String">World</ss:Data>
               </ss:Cell>
           </ss:Row>
       </ss:Table>
   </ss:Worksheet>
</ss:Workbook>

-- bruce (sqlwork.com)

> I am having trouble adjusting the column width when exporting from an
> ASP.net web page.
[quoted text clipped - 27 lines]
>  'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
>  'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work
rote - 26 Mar 2008 23:50 GMT
Bruce i'm just curious i would you tell excel to use this xml when
exporting?
Thanks in advance

> if you want to specify columns withds, multiple sheets, sheet name, etc.
> you
[quoted text clipped - 53 lines]
>>  'dg_Report.Columns(0).ItemStyle.Wrap = True ' -- Won't work
>>  'dg_Report.Columns(9).ItemStyle.Width.Pixel(90) ' --Won't work

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.