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

Marge cells in SfSpreadsheet

Hello, Syncfusion support!

I ran into problems with the formation of a dynamic Excel-files in the Spreadsheet.
It does not work Merge () function. Merge Cells follows:

            var sh = this.AssociatedObject;
            var wb = sh.Workbook;
            var ws = wb.Worksheets[0];

            var cell = ws.Range[1, 1, 2, 2];
            cell.Merge();
            cell.Value2 = "test test test";

(namespace Printing.Behavior, class ImportBehavior, void AssociatedObject_Loaded())

Example attached.

8 Replies

BG Berezkin Gena March 4, 2016 10:41 AM UTC

+

Attachment: CS_8449270b.rar


KB Kanimozhi Bharathi Syncfusion Team March 7, 2016 12:08 PM UTC

Hi Berezkin Gena,

Thank you for contacting Syncfusion Support.

For merging the cells, you need to add the coveredcellinfo  into Coveredcells collection of SpreadsheetGrid and merge the range using Merge method in XlsIO. We have modified your code example below,


var sh = this.AssociatedObject;

var wb = sh.Workbook;

var ws = wb.Worksheets[0];

var coveredcell = new CoveredCellInfo(1, 1, 2, 2);

sh.ActiveGrid.CoveredCells.Add(coveredcell);

var cell = ws.Range[1, 1, 2, 2];

cell.Merge();

cell.Value2 = "test test test";
sh.ActiveGrid.InvalidateCell(GridRangeInfo.Cells(1, 1, 2, 2), true);



We have modified the sample based on your requirement. Please find the link below

Sample:
 
http://www.syncfusion.com/downloads/support/directtrac/general/ze/CS1986002482

Please refer the UG link to know more about Merge cells: 

http://help.syncfusion.com/wpf/sfspreadsheet/formatting#merge-cells

Regards
Kanimozhi B



BG Berezkin Gena March 9, 2016 11:16 AM UTC

Thank you!

I looked online documentation, but did not find examples of working with Borders.

I draw the boundaries as follows:
                    cell.CellStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = Syncfusion.XlsIO.ExcelLineStyle.Thin;
                    cell.CellStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = Syncfusion.XlsIO.ExcelLineStyle.Thick;
                    cell.CellStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = Syncfusion.XlsIO.ExcelLineStyle.Medium;
                    cell.CellStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = Syncfusion.XlsIO.ExcelLineStyle.Hair;

But this method has a performance problem. Are there other ways to render the Borders?

Attachment: Example_4c1c3d57.rar


KB Kanimozhi Bharathi Syncfusion Team March 10, 2016 05:26 PM UTC

Hi Berezkin Gena,

 

We have analyzed your issue with the sample. We could find that the cells of the worksheet[“ws.Cells[]”] which you get for applying merge cells and line style takes more time, hence we have modified the sample by looping the UsedRange of the IWorksheet and add that specific style to the range which meets your requirement.

 

Please find the attached modified sample

 

Regards

Kanimozhi B


Attachment: CS_3d4f586b.zip


BG Berezkin Gena March 16, 2016 02:51 PM UTC

Hello.

I tested your example and found it acceptable.

But I have some questions.

1. Is it possible to change the style of the cell in the following way?
cell.CellStyle = cell2.CellStyle
2. How to change the height of the cell?
I'm trying to use cell.RowHeight property, but height does not change.


KB Kanimozhi Bharathi Syncfusion Team March 17, 2016 11:17 AM UTC

Hi Berezkin Gena,


Query
Response

 Is it possible to change the style of the cell in the following way?

cell.CellStyle = cell2.CellStyle

You can change the style of the cell by assigning CellStyleName as like below,


var ws = spreadsheet.Workbook.Worksheets[0];

var borderStyle = spreadsheet.Workbook.Styles.Add("BorderStyle");

borderStyle.ColorIndex = ExcelKnownColors.Green;

borderStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = Syncfusion.XlsIO.ExcelLineStyle.Thick;

var cell = ws.Range[2,2,3,5];

cell.CellStyleName = "BorderStyle";

var cell1 = ws.Range[5,6,6,7];
cell1.CellStyleName = cell.CellStyleName;



How to change the height of the cell?


Please refer the below UG link to change the height and width of the cell,

http://help.syncfusion.com/wpf/sfspreadsheet/rows-and-columns#row-height-and-column-width


Regards
Kanimozhi B



BG Berezkin Gena March 17, 2016 02:10 PM UTC

1. I am wondering how I can programmatically copy the style of one cell to another? At the same time, I do not know what will be the style in both cells. If I use the CellStyleName property, a piece of information about setting up the cell may be lost.

2. I tried to use:
 spreadsheet.ActiveGrid.SetRowHeight(4, 4, 30);
 spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Row(4), true);
But the value passed SetRowHeight () is set incorrectly. For example, if I set value 30 (spreadsheet.ActiveGrid.SetRowHeight (4, 4, 30)), the assigned value will be equal to 22.5.



KB Kanimozhi Bharathi Syncfusion Team March 18, 2016 12:39 PM UTC

Hi Berezkin Gena,

Please find the details below,

Query
Response
 am wondering how I can programmatically copy the style of one cell to another? At the same time, I do not know what will be the style in both cells. If I use the CellStyleName property, a piece of information about setting up the cell may be lost.

You can achieve your requirement like the below code example


var cell = sh.Workbook.ActiveSheet.Range[2, 3];

var cell1 = sh.Workbook.ActiveSheet.Range[4, 5];

cell.CopyTo(cell1, ExcelCopyRangeOptions.All);


But the value passed SetRowHeight () is set incorrectly. For example, if I set value 30 (spreadsheet.ActiveGrid.SetRowHeight (4, 4, 30)), the assigned value will be equal to 22.5
The value “30” which you set in SetRowHeight() function is in Pixels, whereas the assigned value “22.5” is in terms of Points.

In Excel, the pixel size “30” equals to “22.5” points.


Regards
Kanimozhi B

Loader.
Live Chat Icon For mobile
Up arrow icon