AX2009 copy cell value with format & formula from one sheet to another sheet

AX2009 copy cell value with format & formula from one sheet to another sheet

This question is answered

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!

Verified Answer
  • 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....

All Replies
  • 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....