Hi All,
I want to cut cell “A1” in worksheet “sheet1” and past selected cell to worksheet “sheet2”.
Is it possible to do that ? Could you give me the sample code to do please ?
Thanks,
Kimny.
Hi,
Please see the code below. It copies first row from sheet1 to sheet2.
I have attached both the input and output files. You can modify this code to suit your requirements.
C#
string path = @“F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(path);
Worksheet sheet1 = workbook.Worksheets[0];
Worksheet sheet2 = workbook.Worksheets[1];
//Copy the first row from sheet1 to sheet2
sheet2.Cells.CopyRows(sheet1.Cells, 0, 0, 1);
workbook.Save(path + “.out.xlsx”);
Hi Kimny,
Hello All,
Actually I want to cut and pasts cells from Sheet1 to Shee2 as the same way I do in Microsoft Excel. Cut and pasts functionality should be like this:
1. Copy selected cell
2. Pasts the selected to destination cell
3. Remove the original selected cell.
Could we do like this ?
Thanks and Best Regards,
Kimny.
Hi,
Hi Amjad Sahi,
Cells.ClearRange() and Cells.DeleteRange() method will remove the selected cell range without reference to new cell. You can see if you click Ctrl + X in Microsoft Excel, and pasts to another cell, the selected cell will be cut and reference to new cell.
For example, If I have A1,A2,A3,A4 with the value.
A1 = 10
A2 = 20
A3 = 30
A4 = Sum(A1:A3)
I want to cut A1:A3 from sheet1 to sheet2. So I should have data in Sheet2 like this:
A1 = 10
A2 = 20
A3 = 30
Sheet1 should have data:
A4 = Sum(Sheet2!A1:A3)
Can you help me to solve this issue please ?
Thanks & Regards,
Kimny.
Hi,
Thank you, I will look forward to see the new enhancement.
I really need to move range in another worksheet to make cut and pasts functionality the same as Microsoft Excel one.
Hi,
Please try the following code:
C#
// Create a Workbook.
Workbook excel = new Workbook();
// Create a Cells object obtaining all the cells of the first
// (default)Worksheet.
Cells cells = excel.Worksheets[0].Cells;
// Create a Cell object and get the A1 cell.
Aspose.Cells.Cell cell = cells[0, 0];
// Put values to the cells A1:A3.
cell.PutValue(10);
cell = cells[“A2”];
cell.PutValue(20);
cell = cells[“A3”];
cell.PutValue(30);
cell = cells[“A4”];
//Set formula to A4 cell.
cell.Formula = “=Sum(A1:A3)”;
Range range1 = cells.CreateRange(“A1:A4”);
//Adding another sheet.
Worksheet sheet2 = excel.Worksheets[excel.Worksheets.Add()];
sheet2.Name = “MySheet2”;
// Get cells in the second sheet.
Aspose.Cells.Cells cells2 = sheet2.Cells;
Range range2 = cells2.CreateRange(“A1:A4”);
CellArea ca = new CellArea();
ca.StartRow = 0;
ca.StartColumn = 0;
ca.EndRow = 2;
ca.EndColumn = 0;
range2.Copy(range1);
range1.Value = null;
// Save the excel file.
excel.Save(@“D:\FileTemp\dest.xls”);
Hi,
Hi Amjad Sahi,
Thank you for your support, now you understand my problem well.
Now I think I should wait for your solution rather than I have to update formula manually.
Thanks & Regards,
Kimny.