Supporting Range.CopyData and Range.CopyFormula

Hi,



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.



-Steve

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.

Ex1:

Workbook workbook = new Workbook();
workbook.Open("d:\\test\\test_rangecopy.xls");
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);
wkb.Save("d:\\test\\test_copyvaluesonly.xls");

Ex2:

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
sheet2.Cells.ImportArray(arr,0,0);
//Save the excel file
workbook.Save("d:\\test\\testbook.xls");

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.