0

Scenario: Select a cell, and after pressing the left button from the mouse and moving (dragging) to another cell it changes all the traversing cell's borders.

Expected behavior: We do not need the default borders of cells when dragging one cell to another cell. We need only the source cell border and the destination cell border. (we can do this by changing border property)

Question: How can remove the source to destination full cells range borders?

For more clarification please see this image.

enter image description here

enter image description here

Khalid Farhan
  • 435
  • 1
  • 3
  • 19

1 Answers1

0

Updated Answer

If you are asking whether you can alter the selection border (e.g., the blue border the WorkbookView renders in your screenshot) to only surround the top-left and bottom-rightmost cells (e.g., C3 and E5 only in your example) instead of surrounding the entire range selection (e.g., all of C3:E5), no, the behavior of how this range selection border is rendered cannot be modified in this manner.

If you are asking, apart from the range selection border, if you yourself can apply a cell border (via IRange.Borders APIs) to just these top-left / bottom-right cells, then this is possible:

IRange rangeSelection = workbookView.RangeSelection;
if (rangeSelection.CellCount > 1)
{
    // Get size of range selection
    int numRows = rangeSelection.RowCount;
    int numCols = rangeSelection.ColumnCount;

    // Create a new IRange representing only the top-left and bottom-right cells
    // of the range selection.
    IRange cornerCells = rangeSelection[0, 0]
        .Union(rangeSelection[numRows - 1, numCols - 1]);

    // Add a border to these cells.
    cornerCells.Borders.Weight = BorderWeight.Medium;
}

Original answer based off original question

SpreadsheetGear supports an IRange.Subtract(...) method that will remove the specified range from another range. Example:

IRange range = worksheet.Cells["A1:B2"].Subtract(worksheet.Cells["B2"]);
Console.WriteLine(range.Address);
// OUTPUT: $A$1:$B$1,$A$2

That answers your direct question, though your description and diagrams might indicate you are asking for something beyond this but I cannot tell for sure. If so, it would help if you can update your question to use a more concrete example, providing perhaps actual screenshots of the WorkbookView or "before" and desired "after" ranges for your use-case (e.g., A1:B2 is selected and I want to change this to "..."), any actions / features in Microsoft Excel itself that provide the behavior you are looking for (which my help in determining if the same is possible in SpreadsheetGear), etc.

Tim Andersen
  • 3,014
  • 1
  • 15
  • 11