Select a sheet using Excel automation

HanenHanen Member Posts: 281
edited 2011-06-07 in Navision Attain
I have a problem, how can I activate an existing worksheet it's a kind of selection or activation of a sheet in a workbook to fill with the write data. :-k

Example:

Sheet 1: if The payment is by check
Sheet 2: If the payment is by cash
Sheet 3: if the payment is by transfer
Sheet 4:...................................

Thanks for help. :oops:
Regards

Hanen TALBI

Comments

  • geronimogeronimo Member Posts: 90
    You can have a look at the functions in the excel buffer table. I think it was called selectsheetsname.
  • bbrownbbrown Member Posts: 3,268
    The Sheetname can be passed to the OpenBook function as the second parameter.
    There are no bugs - only undocumented features.
  • HanenHanen Member Posts: 281
    Can you give me examples please? :oops:
    Regards

    Hanen TALBI
  • bbrownbbrown Member Posts: 3,268
    Hanen wrote:
    Can you give me examples please? :oops:

    Here's an example from some code I did a few years back:
    ProcessSetup.GET;
    ImportFile := ProcessSetup."Excel Import Path" + '\*.*';
    ImportFile := CommDiag.OpenFile('Select Excel WorkBook', ImportFile, 2, '', 0);
    
    ExcelBuf2.OpenBook(ImportFile, ExcelBuf2.SelectSheetsName(ImportFile));
    ExcelBuf2.ReadSheet;
    AnalyzeData;
    FIND('-');
    

    The user is first prompted to select a Workbook file. Then the standard function SelectSheetsName presents a list of the available Worksheets from which the user chooses. AnalyzeData is custom finction to process data based on customer's needs.
    There are no bugs - only undocumented features.
  • HanenHanen Member Posts: 281
    I want to do an export not an import.
    Regards

    Hanen TALBI
  • geronimogeronimo Member Posts: 90
    Hanen wrote:
    I want to do an export not an import.
    All you need to do is replace the readsheet function with your own write function.

    this line of code in the above example just opens the file and selects a sheet
    ExcelBuf2.OpenBook(ImportFile, ExcelBuf2.SelectSheetsName(ImportFile));
    

    Then you have your sheet selected and all you need to do is write data to it.
  • HanenHanen Member Posts: 281
    Hi,

    I'm using only one dataitem and I want to export to three excel sheets using filters soomething like if rec1.Field = 'A' then Data will be exported into sheet1 else if rec1.Field='B' then data will be exported to sheet2 else exported to sheet3 :-k
    Help!!!! :oops:
    Regards

    Hanen TALBI
  • geronimogeronimo Member Posts: 90
    Hanen wrote:
    Hi,

    I'm using only one dataitem and I want to export to three excel sheets using filters soomething like if rec1.Field = 'A' then Data will be exported into sheet1 else if rec1.Field='B' then data will be exported to sheet2 else exported to sheet3 :-k
    Help!!!! :oops:

    all you need to do is replace the part below with sheet1 or sheet2 or sheet3 and then write your values to the correct cells.
    ExcelBuf2.SelectSheetsName(ImportFile)
    
Sign In or Register to comment.