Hi Satish

Example: (included Excel file, place the included file like this: C:\filename.xls)

Source code, look below:

--

static void COMExcelExample(Args _args)
{
    custtable                 customers;

    SysExcelApplication       SysExcelApplication;
    SysExcelWorksheet         SysExcelWorksheet;
    SysExcelWorksheets        SysExcelWorksheets;
    SysExcelWorkbooks         SysExcelWorkbooks;
    SysExcelWorkbook          SysExcelWorkbook;
    SysExcelRange             SysExcelRange;
    SysExcelCell              SysExcelCell;
    SysExcelCells             SysExcelCells;
    COMVariant                COMVariant1;
    #excel

    int                       i = 1, whilecount;

    SysOperationProgress progress = new SysOperationProgress();

    ;

    while select count(RecId) from customers
        WhileCount = customers.RecId;

    sysExcelApplication = SysExcelApplication::construct();
    sysExcelApplication.visible(false);
    sysExcelWorkbooks = sysExcelApplication.workbooks();
    COMVariant1 = new COMVariant();
    COMVariant1.bStr('c:\\filename.xls');
    sysExcelWorkbook = sysExcelWorkbooks.add(COMVariant1);
    SysExcelWorksheets = sysExcelWorkbook.worksheets();
    SysExcelWorksheet = SysExcelWorksheets.itemFromNum(1);
    SysExcelRange = SysExcelWorksheet.cells().range(#ExcelTotalRange);

    progress.setCaption('Progress');
    progress.setText(strfmt('%1 - %2','Exporting customers to Excel','Please wait'));
    progress.setTotal(whileCount);

    while select * from customers
    if (customers)
    {
        i++;
        SysExcelCell = SysExcelWorksheet.cells().item(i,1);
        SysExcelCell.value(customers.AccountNum);
        SysExcelCell = SysExcelWorksheet.cells().item(i,2);
        SysExcelCell.value(customers.Name);

        progress.incCount();
    }

    sysExcelApplication.visible(true);
}

--

Hope you'll find this helpful :-)


Best regards
 
Mikael Dalgaard

-----Oprindelig meddelelse-----
Fra: Mikael Dalgård (GPV International A/S)
Sendt: 23. marts 2006 09:03
Til: '[email protected]'
Emne: SV: SV: [development-axapta] Working with Excel through Axapta

Hi Satish

... xinfo::directory(directoryType::Appl).... is the Axapta appl. path, if you would like to use [C:\] instead, like this: "C:\\satishExcelTest.xls", try to change the COMVariant1 code into:

COMVariant1.bStr('C:\\SatishExcelTest.xls');


Best regards


Mikael Dalgaard
-----Oprindelig meddelelse-----
Fra: [email protected] [mailto:[EMAIL PROTECTED] På vegne af Satish
Sendt: 22. marts 2006 14:19
Til: [email protected]
Emne: Re: SV: [development-axapta] Working with Excel through Axapta

Hi Mikael,

Thanx a lot for ur help!

However, I'm unable to use the COMVariant part of ur code;
especially the part where

COMVariant1.bStr(xinfo::directory(directoryType::Appl)
+ 'C:\\SatishExcelTest.xls);

The compilation of this line was giving a syntax error. I'm really
new to Axapta, so i couldn't get it cleared... :(

Can u suggest a remedy for this? :)

Thanks,
Satish


--- In [email protected], Mikael Dalgård (GPV
International A/S) <[EMAIL PROTECTED]> wrote:
>
> Hi there
>
> Try this :-)
>
>     SysExcelApplication                       SysExcelApplication;
>     SysExcelWorksheet                         SysExcelWorksheet;
>     SysExcelWorksheets                        SysExcelWorksheets;
>     SysExcelWorkbooks                         SysExcelWorkbooks;
>     SysExcelWorkbook                          SysExcelWorkbook;
>     SysExcelRange                             SysExcelRange;
>     SysExcelCell                              SysExcelCell;
>     SysExcelCells                             SysExcelCells;
>     COMVariant                                COMVariant1;
>     #excel
>     ;
>     sysExcelApplication                 =
SysExcelApplication::construct();
>     sysExcelApplication.visible(false);
>     sysExcelWorkbooks                 =
sysExcelApplication.workbooks();
>     COMVariant1                         = new COMVariant();
>     COMVariant1.bStr(xinfo::directory(directoryType::Appl) + 'your
filename.xls');
>     sysExcelWorkbook                    = sysExcelWorkbooks.add
(COMVariant1);
>     SysExcelWorksheets                 =
sysExcelWorkbook.worksheets();
>     SysExcelWorksheet                   =
SysExcelWorksheets.itemFromNum(1);
>     SysExcelRange    =    SysExcelWorksheet.cells().range
(#ExcelTotalRange);
>
>     SysExcelCell    =   SysExcelWorksheet.cells().item(1,1);
>     SysExcelCell.value("put in you value here");
>
>
> Best regards

> Mikael Dalgaard
>
>
> -----Oprindelig meddelelse-----
> Fra: [email protected] [mailto:development-
[EMAIL PROTECTED] På vegne af cod
> Sendt: 20. marts 2006 21:33
> Til: [email protected]
> Emne: Re: [development-axapta] Working with Excel through Axapta
>
> On 20/03/06, Satish <[EMAIL PROTECTED]> wrote:
> >
> > Hi guys,
> >
> > I have a situation where i need to open,edit and save excel files
> > through forms in Axapta.
> >
> > I need to allow Excel to do the processing of the data, and then
store
> > the computed values in Axapta tables.
> >
> > Thanks in anticipation.
>
>
> You can import into AXAPTA external COM object of Excel ... try
with google
> to get example on how invoke excel methods..
>
> cod
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>

> Yahoo! Groups Links
>










Yahoo! Groups Links









[Non-text portions of this message have been removed]





YAHOO! GROUPS LINKS




Reply via email to