We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cut Row/Column Feature

Is there any API to cut Row/Column?

I am trying to build a cut paste feature. I want to cut the selected Row/Column and paste into another selected Row/Column. How do I do that.

One way I can copy, delete the previous and then insert new row there but that new insert will take the formatting from above/left rows/colums.

I need a way either to remove all the content including formatting from row/columns or cut feature which does this.

Between I haven’t came through any API which clears the content of rows/Columns.

Regards,
Azhar

Hi Azhar,

Thanks for your posting and using Aspose.Cells.

You can try one of these methods for your needs which will enable you to clear contents and formatting.

These methods can be accessed using Worksheet.getCells() e.g Worksheet.getCells().clearContents()

void clearContents(CellArea range)
Clears contents of a range.
void clearContents(int startRow, int startColumn, int endRow, int endColumn)
Clears contents of a range.
void clearFormats(CellArea range)
Clears formatting of a range.
void clearFormats(int startRow, int startColumn, int endRow, int endColumn)
Clears formatting of a range.
void clearRange(CellArea range)
Clears contents and formatting of a range.
void clearRange(int startRow, int startColumn, int endRow, int endColumn)
Clears contents and formatting of a range.

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

clearRange


public void clearRange(CellArea range)
Clears contents and formatting of a range.
Parameters:
range - Range to be cleared.

clearRange


public void clearRange(int startRow, int startColumn, int endRow, int endColumn)
Clears contents and formatting of a range.
Parameters:
startRow - Start row index.
startColumn - Start column index.
endRow - End row index.
endColumn - End column index.

clearContents


public void clearContents(CellArea range)
Clears contents of a range.
Parameters:
range - Range to be cleared.

clearContents


public void clearContents(int startRow, int startColumn, int endRow, int endColumn)
Clears contents of a range.
Parameters:
startRow - Start row index.
startColumn - Start column index.
endRow - End row index.
endColumn - End column index.

clearFormats


public void clearFormats(CellArea range)
Clears formatting of a range.
Parameters:
range - Range to be cleared.

clearFormats


public void clearFormats(int startRow, int startColumn, int endRow, int endColumn)
Clears formatting of a range.
Parameters:
startRow - Start row index.
startColumn - Start column index.
endRow - End row index.
endColumn - End column index

Thanks. that worked.

How can i cut/copy the selection range?

Regards,
Azhar

Hi Azhar,

Thanks for using Aspose.Cells.

There is no direct way of cut and paste range. However, you can first copy the source range into destination range and then clear the source range.

Please see the following sample code for your needs. I have attached the source and output xlsx files and screenshot for your reference. As you can see, B2:D4 has been cut/pasted to other location.

Java


String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);


Worksheet worksheet = workbook.getWorksheets().get(0);


//Copy the source range into a destination range

Range srcRange = worksheet.getCells().createRange(“B2:D4”);


Range dstRange = worksheet.getCells().createRange(6, 6, srcRange.getRowCount(), srcRange.getColumnCount());


dstRange.copy(srcRange);


//Clear the source range

CellArea area = new CellArea();

area.StartRow = srcRange.getFirstRow();

area.EndRow = srcRange.getFirstRow() + srcRange.getRowCount()-1;

area.StartColumn = srcRange.getFirstColumn();

area.EndColumn = srcRange.getFirstColumn() + srcRange.getColumnCount()-1;


worksheet.getCells().clearRange(area);


workbook.save(filePath + “.out.xlsx”);


Thanks… that worked

Regards,
Azhar

Hi,


Good to know that it sorts out your needs. Feel free to contact us any time if you have further queries or have some issue, we will be happy to assist you soon.

Thank you.