We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Excel exporting line break

Hello everybody.

I have a problem.

I have a code snippet:
---------------------------------------------------------------
this.GridGroupingControl1.DataSource = DATATABLE;

GridExcelExport excel = new GridExcelExport(this.GridGroupingControl1, "Namefile.xls");

excel.ExportNestedTable = true;
excel.Export();


---------------------------------------------------------------
I have syncfusion version 6.4.0.15.
I'M USING VISUAL STUDIO 2008 C#.

GridGroupingControl1 is a Syncfusion Control
(Syncfusion.Web.UI.WebControls.Grid.Grouping.GridGroupingControl)

In that syncfusion grid I have a row with information with a line break ( the image about it is attached file) but when EXPORTING to Excel ( in the image says IMPORTING, sorry) doesn't respect the line break in the XLS file.

I don't know if in syncfusion exists a WRAPTEXT property for XLS sheet, or in SQL I must save in a register an ALT-ENTER key combination to make the line break( Actually I don't know how to do this), so this is my request for you.

Best Regards, hope you can help me.






line break_a174f768_c0596675.zip

2 Replies

VE victor elizondo August 11, 2011 01:09 AM UTC

I've founded a solution to my problem I want to share it.

----------------------------------------------------------------

ExcelEngine engine = new ExcelEngine();
IApplication application = engine.Excel;
IWorkbook workbook = application.Workbooks.Create();
IWorksheet sheet = workbook.Worksheets[0];

//This is for showing the datatable dtExcel HEADER in the excel
//sheet
char Numero = '1';
char Letra = 'A';

for (int g = 0; g < dtExcel.Columns.Count; g++)
{
string cell = Letra.ToString() + Numero.ToString();
sheet.Range[cell].Text = dtExcel.Columns[g].ColumnName.Replace("
", "");
sheet.Range[cell].CellStyle.WrapText = true;
sheet.Range[cell].CellStyle.Color = System.Drawing.Color.MediumSeaGreen;
sheet.Range[cell].CellStyle.Font.Bold = true;
sheet.Range[cell].CellStyle.Font.FontName = "Verdana";
sheet.Range[cell].CellStyle.Font.Size = 8;
Letra++;
}

//This is for showing the datatable dtExcel in the excel
//sheet
Numero = '2';
for (int i = 0; i < dtExcel.Rows.Count; i++)
{

Letra = 'A';
for (int j = 0; j < dtExcel.Columns.Count; j++)
{
string cell = Letra.ToString() + Numero.ToString();
sheet.Range[cell].Text = dtExcel.Rows[i][j].ToString().Replace("
", "");
sheet.Range[cell].CellStyle.WrapText = true;
sheet.Range[cell].CellStyle.Font.FontName = "Verdana";
sheet.Range[cell].CellStyle.Font.Size = 8;

if (dtExcel.Rows[i][j].ToString().Length >= 20 && dtExcel.Rows[i][j].ToString().Length <= 50)
sheet.Range[cell].ColumnWidth = 15;

if (dtExcel.Rows[i][j].ToString().Length >= 50 && dtExcel.Rows[i][j].ToString().Length <= 100)
sheet.Range[cell].ColumnWidth = 20;

if (dtExcel.Rows[i][j].ToString().Length >= 100)
sheet.Range[cell].ColumnWidth = 50;

//Increasing the ABC letters
Letra++;
}
//Increasing the numbers (1,2,3,4...)
Numero++;
}

workbook.SaveAs(Request.PhysicalApplicationPath + @"FileName.xls");

workbook.Close();
engine.ThrowNotSavedOnDestroy = true;
engine.Dispose();
System.Diagnostics.Process.Start(Request.PhysicalApplicationPath + @"FileName.xls");

----------------------------------------------------------------

BEST REGARDS.




SR Sridhar Syncfusion Team August 11, 2011 07:21 AM UTC

Hi victor,

Thank you very much for using Syncfusion products.

We are very happy to see that your problem is solved at your side specified in your previous update. Please let us know if you require any further clarifications , get back to us with the required sample file and we are happy to help you out.

Thanks,
Sridhar.S


Loader.
Live Chat Icon For mobile
Up arrow icon