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.
Unfortunately, activation email could not send to your email. Please try again.

Marge cells in SfSpreadsheet

Thread ID:

Created:

Updated:

Platform:

Replies:

123297 Mar 4,2016 05:38 AM Mar 18,2016 08:39 AM WPF 8
loading
Tags: SfSpreadsheet
Berezkin Gena
Asked On March 4, 2016 05:38 AM

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.

Berezkin Gena
Replied On March 4, 2016 05:41 AM

+

Attachment: CS_8449270b.rar

Kanimozhi Bharathi [Syncfusion]
Replied On March 7, 2016 07:08 AM

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


Berezkin Gena
Replied On March 9, 2016 06:16 AM

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

Kanimozhi Bharathi [Syncfusion]
Replied On March 10, 2016 12:26 PM

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

Berezkin Gena
Replied On March 16, 2016 10:51 AM

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.

Kanimozhi Bharathi [Syncfusion]
Replied On March 17, 2016 07:17 AM

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


Berezkin Gena
Replied On March 17, 2016 10:10 AM

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.


Kanimozhi Bharathi [Syncfusion]
Replied On March 18, 2016 08:39 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;