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

Free Support Forum - aspose.com

Supporting Range.CopyData and Range.CopyFormula


Would it be possble for Aspose.Cells in .NET to support the CopyData and CopyFormula for the Range class?

As the name suggests, CopyData and CopyFormua only copies data/formula respectively to the target range.

This is similar to the Range.CopyStyle method that already exists.


Hi Steve,

Well, currently you may try to fill an array using Cells.ExportArray() method and then use Cells.ImportTwoDimensionArray() to copy data at your desired location of the sheet. Althernatively, you may also fill a multi dimentional array based on some range of data and later you can use Cells.ImportArray() method to copy the data to your desired range of cells.

Could you consult the following examples.


Workbook workbook = new Workbook();
Worksheet oSheetSource = workbook.Worksheets[0];
Range oRange = oSheetSource.Cells.CreateRange("A1", "D2");
//Retrieve the data from the range.
object[,] oExcelRangeValues;
oExcelRangeValues = (System.Object[,])oRange.Worksheet.Cells.ExportArray(0, 0, 2, 4);
//Copy the values to the required worksheet in the Result Workbook
Workbook wkb = new Workbook();
Worksheet oWorksheet = wkb.Worksheets[0];
oWorksheet.Cells.ImportTwoDimensionArray(oExcelRangeValues, 5, 2);


Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
//putting data into the cells A1:D4 (4*4)
for (int i = 0;i<4;i++)
for(int j = 0;j<4;j++)
cells[i,j].PutValue(i.ToString() + "," +j.ToString());

string[,] arr = new string[4,4];
//Now accessing data from the matrix and save it to an array
for (int i = 0;i<4;i++)
for(int j = 0;j<4;j++)
arr[i,j]= cells[i,j].StringValue;

//Add a new worksheet.
int index = workbook.Worksheets.Add();
Worksheet sheet2 = workbook.Worksheets[index];
// Pasting data into the second worksheet
//Save the excel file

For copying formulas in a range of cells, you may similarly iterate throught cells and fill an array with formulas using Cell.Formula property and then import the array to set the formulas to the cells in the worksheet.

And we may consider to add your desired functions after checking its feasibility.

Thank you.

Hi Steve,

Please try the fix in http://www.aspose.com/community/forums/135224/support-for-range-intersect/showthread.aspx#135224.

We add two methods in the fix.

Range.CopyData(): Copy data and formula of the range.

Range.CopyValue(): Copy data and formula value of the range.