Skip to content

Infragistics Community Forum / Web / Ultimate UI for ASP.NET Web Forms / Wrapping Text in an Excel Spreadsheet

Wrapping Text in an Excel Spreadsheet

New Discussion
Tyler
Tyler asked on Feb 5, 2008 10:14 PM

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();

Sign In to post a reply

Replies

  • 0
    Tyler
    Tyler answered on Jan 25, 2008 5:46 PM

    It turns out that the not wrapping was being caused by this line

    wbk.ActiveWorksheet.MergedCellsRegions.Add(UltraWebGrid1.Rows.Count + 16 + i, 1, UltraWebGrid1.Rows.Count + 16 + i, 3);

    Is is possible to have a MergedCellRegion wrap text AND to have the cell expand vertically to fit the text? Thoughts?

    • 0
      Tyler
      Tyler answered on Feb 5, 2008 10:14 PM
  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Tyler
Favorites
0
Replies
2
Created On
Feb 05, 2008
Last Post
18 years, 8 months ago

Suggested Discussions

Created by

Created on

Feb 5, 2008 10:14 PM

Last activity on

Feb 5, 2008 10:14 PM