Galera,
I have a dataGridView that I used the following code snippet to break the text:
dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns[1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
In the grid is working correctly, example of the string I am receiving:
"To the morning sun \ r \ n a drop of dew \ r \ n precious diamond."
When exporting to excel does not break text in the "SAME" cell and yes to the bottom line.
ExportcodeforExcel
privatevoidbutton2_Click(objectsender,EventArgse){copyAlltoClipboard();Microsoft.Office.Interop.Excel.Applicationxlexcel;Microsoft.Office.Interop.Excel.WorkbookxlWorkBook;Microsoft.Office.Interop.Excel.WorksheetxlWorkSheet;objectmisValue=System.Reflection.Missing.Value;xlexcel=newMicrosoft.Office.Interop.Excel.Application();xlexcel.Visible=true;xlWorkBook=xlexcel.Workbooks.Add(misValue);xlWorkSheet=(Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);Microsoft.Office.Interop.Excel.RangeCR=(Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[1,1];//Qubradelinha//xlWorkSheet.Range["B1:B500"].Cells.WrapText = true;
xlWorkSheet.Columns[2].Cells.WrapText = true;
xlWorkSheet.Columns[2].ColumnWidth += 15;
//xlWorkSheet.Columns[2].AutoFit();
xlWorkSheet.Columns[2].Cells.WrapText = true;
xlWorkSheet.Columns[2].Style.WrapText = true;
xlWorkSheet.Cells[8, 2].Style.WrapText = true;
xlWorkSheet.Cells[9, 2].Style.WrapText = true;
xlWorkSheet.Cells[10, 2].Style.WrapText = true;
xlWorkSheet.Columns[2].WrapText = true;
//Set Text-Wrap for all rows true//
xlWorkSheet.Rows.WrapText = true;
CR.Select();
xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
}
As you can see when breaking text to excel, it is not broken within the same cell but rather for new rows. How can I resolve this?