Jump to content

dubeysou

Member
  • Posts

    1
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United Kingdom

About dubeysou

dubeysou's Achievements

0

Reputation

  1. Hi, I have a ASP.Net DataGrid in which individual cells have a subject and a Description, for which I have used \r\n for the carriage return. I am exporting the data in the Grid to Excel. The problem is that the carriage return character is shown as a square box in the Excel cells and everything is in a single line within a cell. I know that Alt + ENter key introduces a carriage return in the Excel cell, but how do i do it programmatically? I am using this to create an Excel workbook: objClassType = Type.GetTypeFromProgID("Excel.Application"); objApp_Late = Activator.CreateInstance(objClassType); //Get the workbooks collection. objBooks_Late = objApp_Late.GetType().InvokeMember( "Workbooks", BindingFlags.GetProperty, null, objApp_Late, null ); //Add a new workbook. objBook_Late = objBooks_Late.GetType().InvokeMember( "Add", BindingFlags.InvokeMethod, null, objBooks_Late, null ); Then, I am creating the column headers using the DataGrid's GridColumnStyle. After that, I am using the following code to create rows in Excel: // Create rows int rowIndex=0; foreach(DataRow row in table.Rows) { rowIndex++; ColumnIndex=0; foreach (DataGridColumnStyle cs in ts.GridColumnStyles) { // PAS00002056: Do not include column if it's not actually in the table, even if it's found in user prefs if (table.Columns.Contains(cs.MappingName)) { DataColumn col = table.Columns[cs.MappingName]; // Get true/false value for 'ExcelExport' tag from userpreferences if ((bool)up.GetGridColumnValue(pasUserPreferenceName, cs.MappingName, "ExcelExport")) { ColumnIndex++; objApp_Late.GetType().InvokeMember("Cells",BindingFlags.SetProperty,null,objApp_Late,new object[] {rowIndex+1,ColumnIndex, row[col.ColumnName].ToString()}); } } } } ----------------------------------------------------------------------------------------------------------------------------------------------------------------- Thanks in advance
×
×
  • Create New...