Question Status

Verified
AX Lover asked a question on 26 Mar 2013 7:28 PM

In AX2009,

i want to copy some rows from sheet1 to sheet2, say from row 1 to row 9

in row 1 to row 9 , some cell has formula & formatting, after copyed, i want to keep the formula & formatting

Could someone give me some X++ sample code?

Thanks so much in advance!

Reply
Verified Answer
AX Lover responded on 26 Mar 2013 8:41 PM

Woo...i resolve this problem by myself, share a test job here

first add one new method in class 'SysExcelRange'

public SysExcelRange copy(SysExcelRange _range)

{

   SysExcelRange ret;

;

   ret = SysExcelRange::construct(version, Range.copy(_range.comObject()));

   return ret;

}

job for copy:

static void excelCopyTesting(Args _args)

{

   #Excel

   SysExcelApplication     excel;

   SysExcelWorksheets      worksheets;

   SysExcelWorksheet       worksheet,  copyToSheet;

   SysExcelRange           excelRange, copyToRange, copyToOtherSheetRange;

   ;

   excel = SysExcelApplication::construct();

   if (! excel.workbooks().open(@"D:\test.xlsx"))

      throw error("");

   worksheets = excel.worksheets();

   worksheet = worksheets.itemFromName("Sheet1");

   copyToSheet = worksheets.itemFromName("Sheet2");

   excelRange = worksheet.range("A3:C5");

   copyToRange = worksheet.range("A9:C11");

   copyToOtherSheetRange = copyToSheet.range("A1");

   excelRange.copy(copyToRange);

   excelRange.copy(copyToOtherSheetRange);

   excel.visible(true);

}

Injoy DaXing....

Reply
Verified Answer
AX Lover responded on 26 Mar 2013 8:41 PM

Woo...i resolve this problem by myself, share a test job here

first add one new method in class 'SysExcelRange'

public SysExcelRange copy(SysExcelRange _range)

{

   SysExcelRange ret;

;

   ret = SysExcelRange::construct(version, Range.copy(_range.comObject()));

   return ret;

}

job for copy:

static void excelCopyTesting(Args _args)

{

   #Excel

   SysExcelApplication     excel;

   SysExcelWorksheets      worksheets;

   SysExcelWorksheet       worksheet,  copyToSheet;

   SysExcelRange           excelRange, copyToRange, copyToOtherSheetRange;

   ;

   excel = SysExcelApplication::construct();

   if (! excel.workbooks().open(@"D:\test.xlsx"))

      throw error("");

   worksheets = excel.worksheets();

   worksheet = worksheets.itemFromName("Sheet1");

   copyToSheet = worksheets.itemFromName("Sheet2");

   excelRange = worksheet.range("A3:C5");

   copyToRange = worksheet.range("A9:C11");

   copyToOtherSheetRange = copyToSheet.range("A1");

   excelRange.copy(copyToRange);

   excelRange.copy(copyToOtherSheetRange);

   excel.visible(true);

}

Injoy DaXing....

Reply