I am exporting an UltraWebGrid to Excel using Infragistic's UltraWebGridExcelExporter, and I am having difficulty getting the cells in the spreadsheet to wrap their text. Below is some sample code in the click event in which I am exporting the grid. The row will not expand to the size of the wrapped text inside. Any insight into this will be appreciated.
Infragistics.Excel.Workbook wbk = new Infragistics.Excel.Workbook(); UltraWebGridExcelExporter1.ExcelStartRow = 10;UltraWebGridExcelExporter1.ExportMode = Infragistics.WebUI.UltraWebGrid.ExcelExport.ExportMode.Custom; wbk.Worksheets.Add("SpreadSheetName");this.UltraWebGridExcelExporter1.Export(this.UltraWebGrid1, wbk.Worksheets["SpreadSheetName"]);this.UltraWebGridExcelExporter1.Export(this.UltraWebGrid2, wbk.Worksheets["SpreadSheetName"], UltraWebGrid1.Rows.Count + 15, 0); wbk.ActiveWorksheet.Columns[1].Width = 10 * 256; //expand the "notes" column in the legend to be all long and lengthy-like wbk.ActiveWorksheet.MergedCellsRegions.Add(UltraWebGrid1.Rows.Count + 15, 1, UltraWebGrid1.Rows.Count + 15, 3);for (int i = 0; i < UltraWebGrid2.Rows.Count; i++) { wbk.ActiveWorksheet.Columns[1].Width = 30 * 256;wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].CellFormat.WrapText = Infragistics.Excel.ExcelDefaultableBoolean.True; wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].Cells[1].Value = "Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur ";wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].CellFormat.VerticalAlignment = Infragistics.Excel.VerticalCellAlignment.Top; //wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].Height = 35 * 20; wbk.ActiveWorksheet.MergedCellsRegions.Add(UltraWebGrid1.Rows.Count + 16 + i, 1, UltraWebGrid1.Rows.Count + 16 + i, 3); }wbk.ActiveWorksheet = wbk.Worksheets["SpreadSheetName"]; MemoryStream stream = new MemoryStream();Infragistics.Excel.BIFF8Writer.WriteWorkbookToStream(wbk, stream);Byte[ bytearray = (Byte[)Array.CreateInstance(typeof(byte), stream.Length); stream.Position = 0;stream.Read(bytearray, 0, (int)stream.Length); stream.Close(); Response.Clear();Response.AddHeader("content-disposition", "attachment; filename=SpreadSheetName.xls"); Response.BinaryWrite(bytearray); Response.End();
UltraWebGridExcelExporter1.ExcelStartRow = 10;
wbk.Worksheets.Add("SpreadSheetName");
wbk.ActiveWorksheet.Columns[1].Width = 10 * 256;
//expand the "notes" column in the legend to be all long and lengthy-like
wbk.ActiveWorksheet.MergedCellsRegions.Add(UltraWebGrid1.Rows.Count + 15, 1, UltraWebGrid1.Rows.Count + 15, 3);
{
wbk.ActiveWorksheet.Columns[1].Width = 30 * 256;
wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].Cells[1].Value = "Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur Lorem ipsum dolor sit amet, consectetur ";
//wbk.ActiveWorksheet.Rows[UltraWebGrid1.Rows.Count + 16 + i].Height = 35 * 20;
wbk.ActiveWorksheet.MergedCellsRegions.Add(UltraWebGrid1.Rows.Count + 16 + i, 1, UltraWebGrid1.Rows.Count + 16 + i, 3);
}
MemoryStream stream = new MemoryStream();
stream.Position = 0;
stream.Close();
Response.Clear();
Response.BinaryWrite(bytearray);
Response.End();
It turns out that the not wrapping was being caused by this line
Is is possible to have a MergedCellRegion wrap text AND to have the cell expand vertically to fit the text? Thoughts?
Please refer to this link for more information on this issue:
https://ko.infragistics.com/community/forums/f/ultimate-ui-for-asp-net/16332/ultrawebtab-websplitter-and-webdatagrid-jscript-error#16332