Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Excel Export Not Wrapping MergedCellRegions

Last post 08-14-2008 8:42 by Charul. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 02-04-2008 16:20

    Excel Export Not Wrapping MergedCellRegions

    I am attempting to get the following combination of features to work with the Infragistics.Excel component of the ASP.NET suite:
     
    I need to be able to "wrap text" in a cell that has been spanned.
     
    I have been able to get text to wrap in a single cell.  I have also been able to get cell spanning to work by using the MergedCellsRegions.Add() method.
     
    While both features alone are very nice, it is critical that they work together using only your software.
     
    Please let us know what I am missing to get this to work. I have attached an example project showing this issue clearly. If you comment out line 59 of Default.aspx.cs the cells will wrap normally.
    • Post Points: 20
  • 02-05-2008 16:49 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    My compliments for such a concise demonstration of the problem.  I easily reproduced the behavior, but I'm not sure that the configuration you're looking for is possible in Excel.  here's what I did.. through excel, I typed a value into 2 cells and merged them.  Then I clicked on the wrap button, and nothing happened!  I took a closer look, and the merge function not only merges, but centers the text as well.  I'm guessing this means that merging and wrapping inside of excel don't work together.  The exporter is properly setting both conditions, as indicated by the properties of those cells inside of Excel. 

    If you know of a way to get these two conditions working inside of Excel, we can certainly look at adding this as an enhancement to our exporting engine, but as it stands right now, I don't think this is possible.

    -Tony

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 35
  • 02-05-2008 18:03 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    Alright. Given that this is now a known limitation of Excel and no fault of our own (wink wink).... I have come up with a (partial) solution that will work. I just need a little help from you guys following through. In the attached project you can see that I have added a new column. This column is the exact width of both the original column and the column it was to be merged with added together. In other words ColumnA.Width + ColumnB.Width = ColumnC.Width. ColumnC has its formatting and .Value set to exactly that of ColumnA PLUS it is set to wrap.

     This provides me with a row that has the height properly set inside the resulting excel file. One problem is that if you delete ColumnC or the value of ColumnC the row will then revert back to the default height. A working solution for me (at least) would be to be able to set the print area (File->Print Area->Set Print Area  in Excel) and simply not print the unneeded column. I couldn't not find this feature in your Excel Exporter under Print Options or anywhere else.

     If you have any other suggestions I will be glad of the help. Thanks again.

    • Post Points: 5
  • 02-06-2008 12:02 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    Answer

    I have solved the problem for as far as my needs go. I have used the method that I mentioned above but once the row is the correct height I simply hide the dummy column. This is as simple as:

    oWorkbook.ActiveWorksheet.Columns[100].Hidden = true; //where the magic happens

    Viola! I am still interested in a way to limit the printable area but until that exists I will be contented with this method.

    I have attached a final project for anyone who is interested in seeing it. I hope this might help someone in the future.

    • Post Points: 20
  • 02-06-2008 14:15 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    There's currently no control over the printable area, but I'll pass on the request.  Setting the column to hidden sounds like a good approach - glad you were able to find a solution, and thanks for sharing!

    -Tony

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 5
  • 07-02-2008 19:10 In reply to

    • jahmed3
    • Not Ranked
    • Joined on 06-21-2008
    • Points 180

    Re: Excel Export Not Wrapping MergedCellRegions

    Hi,

    The save method of the workbook takes the location where the excel file is to be created. 

    oWorkbook.save("C:\Documents and settings\abc\desktop")

    Instead of hardcoding the location I want the user to select the location of where the excel is to be created. I would appreciate if some replies to my post.

    Thanks,

    Junaid 

    Filed under: ,
    • Post Points: 35
  • 07-09-2008 16:16 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    Junaid,

    If you're working in an ASP.NET application, there's no way for you to dictate where the file will get saved on the client-machine, they will automatically be prompted with a save file dialog.  Are you working in an ASP.NET app or a Windows Forms app? 

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 20
  • 07-09-2008 17:38 In reply to

    • jahmed3
    • Not Ranked
    • Joined on 06-21-2008
    • Points 180

    Re: Excel Export Not Wrapping MergedCellRegions

    Hi Tony,

    1) I am working on a web application. When the excel is generated I am not prompted with an automatic save file dialog. I am providing the code below.

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

    Dim oWorkbook As Workbook = New Infragistics.Excel.Workbook()

    UltraWebGridExcelExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Custom

    oWorkbook.Worksheets.Add(
    "mySheet1")

    Me.UltraWebGridExcelExporter1.Export(Me.UltraWebGrid1, oWorkbook.Worksheets("mySheet1"))

    oWorkbook.Worksheets.Item(0).PrintOptions.CenterHorizontally = True

    oWorkbook.Worksheets.Item(0).DefaultRowHeight = 0

    oWorkbook.Worksheets.Item(0).Columns(0).Width = 4000

    For i As Integer = 0 To UltraWebGrid1.Rows.Count

    oWorkbook.Worksheets.Item(0).Rows(i).Cells(0).CellFormat.WrapText = ExcelDefaultableBoolean.True

    oWorkbook.Worksheets.Item(0).Rows(i).Cells(0).CellFormat.Alignment = HorizontalCellAlignment.Center

    Next

    oWorkbook.Worksheets.Item(0).Columns(1).Width = 1200

    For i As Integer = 0 To UltraWebGrid1.Rows.Count

    oWorkbook.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.Alignment = HorizontalCellAlignment.Center

    Next

    oWorkbook.Save("C:\Documents and Settings\ABC\Desktop\test.xls")

    End Sub

    When the button is clicked the save dialog control does not come up automatically. Can you let me know what code I need to add.

    2) And some of the controls like the ultrabutton, ultraprintdocument, ultraprintpreviewcontrol etc. are disabled. Can you let me know how to enable these controls.

    Thanks,

    Junaid.

    • Post Points: 20
  • 07-10-2008 12:13 In reply to

    • jahmed3
    • Not Ranked
    • Joined on 06-21-2008
    • Points 180

    Re: Excel Export Not Wrapping MergedCellRegions

    Hi,

    A bit of update

     

    Dim filepath As String = "C:\Documents and Settings\ABC\Desktop\test.xls"

    Dim filetodelete As String = "C:\Documents and Settings\ABC\Desktop\test.xls"

    oWorkbook.Save(filepath)

    Response.AppendHeader("content-disposition", "attachment;filename=students.xls")

    Response.ContentType = "application/ms-excel"

    Response.WriteFile(filepath)

    Response.End()

     Using the above code I am able to send the excel file to the client machine but I dont want to save the excel file on the server(specific location) which is done using the save method.

    • Post Points: 20
  • 07-18-2008 11:34 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    The WebGridExcelExporter will automatically stream the file to the client.  The Save method takes either a file name, or it can take a strem.  You want to save to a stream.  You can write to a memory stream, or write directly to the Response.OutputStream. 

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 20
  • 07-22-2008 20:46 In reply to

    • jahmed3
    • Not Ranked
    • Joined on 06-21-2008
    • Points 180

    Re: Excel Export Not Wrapping MergedCellRegions

    Hi Tony,

    Thanks for the last post.

    I have 35 checkboxes on my web page. Based on the selection of the checkboxes the columns are displayed on the ultrawebgrid. Now I want to export these columns to an excel sheet. I am setting the width of each column before creating the excel file. The user may select any number of checkboxes. The problem is that I have to make combinations of what the user selects. For example, there are 3 checkboxes on the page, the user may select only the first checkbox or the second checkbox or the third checkbox or the first and the secodn checkbox ....

    If CheckBox1.Checked = True Then

    owb.Worksheets.Item(0).Columns(0).Width = 2500

    For i As Integer = 0 To UltraWebGrid1.Rows.Count

    owb.Worksheets.Item(0).Rows(i).Cells(0).CellFormat.Alignment = HorizontalCellAlignment.Center

    Next

    End If

    If CheckBox1.Checked = True AndAlso CheckBox2.Checked = True Then

    owb.Worksheets.Item(0).Columns(0).Width = 2500

    For i As Integer = 0 To UltraWebGrid1.Rows.Count

    owb.Worksheets.Item(0).Rows(i).Cells(0).CellFormat.Alignment = HorizontalCellAlignment.Center

    Next

    owb.Worksheets.Item(0).Columns(1).Width = 6000

    For i As Integer = 0 To UltraWebGrid1.Rows.Count

    owb.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.WrapText = ExcelDefaultableBoolean.True

    owb.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.Alignment = HorizontalCellAlignment.Center

    Next

    End If 

     Is there a better way of solving this problem or I have to create all the combinations. I could not find

    owb.Worksheets.Item(0).Columns("mycolumn").Width = 2000  so that I could have set "mycolumn" to some specified width. The columns collection only takes integer.

    Thanks,

    Junaid.

    Filed under:
    • Post Points: 20
  • 07-24-2008 10:19 In reply to

    Re: Excel Export Not Wrapping MergedCellRegions

    jahmed3:
     Is there a better way of solving this problem or I have to create all the combinations. I could not find

    owb.Worksheets.Item(0).Columns("mycolumn").Width = 2000  so that I could have set "mycolumn" to some specified width. The columns collection only takes integer.

    There are no named columns in excel, everything is indexed based - so you are going to have to work with column indexes rather than named keys. 

    There is an alternative - if you use the WebGridExcelExporter, you can handle the InitializeColumn event which will be fired for each WebGrid column.  In that event, you can check for your conditions, and set the column width accordingly. 

     

    Anthony Lombardo
    Lead Technical Evangelist
    Infragistics, Inc.
    Worldwide Evangelism Group

    tonyl@infragistics.com
    blogs.infragistics.com

    • Post Points: 5
  • 08-14-2008 8:40 In reply to

    • Charul
    • Not Ranked
    • Joined on 05-28-2008
    • Points 70

    Re: Excel Export Not Wrapping MergedCellRegions

    why i am not getting the save option

    • Post Points: 5
  • 08-14-2008 8:42 In reply to

    • Charul
    • Not Ranked
    • Joined on 05-28-2008
    • Points 70

    Re: Excel Export Not Wrapping MergedCellRegions

    Why i am not getting the save option in my VB Code

    • Post Points: 5
Page 1 of 1 (14 items)
Powered by Community Server (Commercial Edition), by Telligent Systems