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
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
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?
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
UltraWebGridExcelExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Custom
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
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
oWorkbook.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.Alignment = HorizontalCellAlignment.Center
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.
Junaid.
Why i am not getting the save option in my VB Code
jahmed3 said: 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.
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.
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
End If
If CheckBox1.Checked = True AndAlso CheckBox2.Checked = True Then
owb.Worksheets.Item(0).Columns(1).Width = 6000
owb.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.WrapText = ExcelDefaultableBoolean.True
owb.Worksheets.Item(0).Rows(i).Cells(1).CellFormat.Alignment = HorizontalCellAlignment.Center
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.
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.