Hi,
simple question:
How to a create a border around a range of cells ?
For instance, if I want to have a border around a range from A1 to C10, how to achieve this ?
Thanks
I've tried this :
WorksheetMergedCellsRegion merge = sheet.MergedCellsRegions.Add(4, 4, 15, 15); merge.CellFormat.BottomBorderStyle = CellBorderLineStyle.Double; merge.CellFormat.TopBorderStyle = CellBorderLineStyle.Double; merge.CellFormat.LeftBorderStyle = CellBorderLineStyle.Double; merge.CellFormat.RightBorderStyle = CellBorderLineStyle.Double;
sheet.MergedCellsRegions.Remove(merge);
Seems to provide the correct result..
Is there another way to do this ?
Hello,
Creating a WorksheetMergedCellsRegion seems like the correct way to go as it exposes the CellFormat for you to style the cells as you wish. Let me know if you have any other issues with this approach.
Thanks,
Chris
This approach is ok but I don't like it because generally, what you do is :
Fill the cells with value then format the cells...
With the merge collections, I MUST do :
Merge Cells (meaning I should know before the process what to merge)
Format the merged cells
Unmerge to keep the format
Set cells values...
Because If I set first the values, after the merge, values are lost.... (even after "unmerge")...
Am I correct or is there another way to do this ?
Now I see the dilemma, the WorksheetMergedCellsRegion will take the value of the first cell for the region, and the rest of the cell values are lost. Unfortunately, in order to set the cell format on a region of cells, you will have to set the CellFormat on each of the cells around the border of the region. Something similar to the following should work:
for (int i = firstRow; i <= lastRow; i++) { sheet.Rows[i].Cells[firstColumn].CellFormat.LeftBorderStyle = CellBorderLineStyle.Double; sheet.Rows[i].Cells[lastColumn].CellFormat.RightBorderStyle = CellBorderLineStyle.Double; }
for (int i = firstColumn; i <= lastColumn; i++) { sheet.Rows[firstRow].Cells[i].CellFormat.TopBorderStyle = CellBorderLineStyle.Double; sheet.Rows[lastRow].Cells[i].CellFormat.BottomBorderStyle = CellBorderLineStyle.Double; }
Ideally, there would be a CellFormat property on the WorksheetRegion class similar to that of the WorksheetMergedCellRegion, that would allow you to style the cells within the region without merging the cell values. It appears that this is a new product idea which can be suggested for future versions at http://ideas.infragistics.com.
Submitting your idea will allow you to communicate directly with our product management team, track the progress of your idea at any time, see how many votes it got, read comments from other developers in the community, and see if someone from the product team has additional questions for you.
Remember when submitting your idea to explain the context in which a feature would be used and why it is needed as well as anything that would prevent you from accomplishing this today. You can even add screenshots to build a stronger case. Remember that for your suggestion to be successful, you need other members of the community to vote for it. You can also link back to this thread for additional details.
Hopefully the snippet of code I provided helps to achieve the desired results. Let me know if you have any other questions.