2012-08-29 101 views
2

我必須使用X ++代碼從Excel文件中讀取數據。貝婁是一些大型Excel文件的一部分。我只需要在第一列單元格的公共部門的基礎上過濾列表* _BillingCode,* _PSN,AccDistRuleAdvLedgerEntryExt等。如何從Excel文件讀取?

Public Sector SL1 *_BillingCode 
Public Sector SL1 *_PSN 
Public Sector SL1 AccDistRuleAdvLedgerEntryExt (Class) 
Public Sector SL1 AccJourRuleAdvLedgerEntryExt 
Public Sector SL1 AccountantActivities 
Public Sector SL1 AccountingManagerActivities 
Public Sector SL1 AdvancedLedgerEntry (Class) 
Public Sector SL1 AdvLedgerEntry (Prefix) 
Public Sector SL1 AxAdvancedLedgerEntry (Prefix) 
Public Sector SL1 AxdAdvancedLedgerEntry 
Public Sector SL1 AxdCustomerTransaction (Class) 
Public Sector SL1 BudgetAccountDetail (Prefix) 

我在谷歌搜索我發現下面的代碼行從Excel文件讀取。

static void ReadFromExcel(Args _args) 
    { 
    SysExcelApplication application; 
    SysExcelWorkbooks workbooks; 
    SysExcelWorkbook workbook; 
    SysExcelWorksheets worksheets; 
    SysExcelWorksheet worksheet; 
    SysExcelCells cells; 
    COMVariantType type; 
    int row; 
    CustAccount account; 
    CustName name; 
    #define.Filename('C:\\X++ Ownership.xls') 
    ; 
    application = SysExcelApplication::construct(); 
    workbooks = application.workbooks(); 
    try 
    { 
    workbooks.open(#Filename); 
    } 
    catch (Exception::Error) 
    { 
    throw error("File cannot be opened."); 
    } 
    workbook = workbooks.item(1); 
    worksheets = workbook.worksheets(); 
    worksheet = worksheets.itemFromNum(1); 
    cells = worksheet.cells(); 
    do 
    { 
    row++; 
    account = cells.item(row, 1).value().bStr(); 
    name = cells.item(row, 2).value().bStr(); 
    info(strfmt('%1 - %2', account, name)); 
    type = cells.item(row+1, 1).value().variantType(); 
    } 
    while (type != COMVariantType::VT_EMPTY); 
    application.quit(); 
    } 

爲了滿足我的要求,我需要花時間瞭解如何利用上述代碼。我會感謝你的幫助。

+0

你可以將文件保存爲.CSV,如果有的話我可以幫你解決。 –

回答

2

有更好的方法來讀取Excel文件,請參閱Axaptapedia(我是作者的方式)。