Reputation: 115
I have to read from a Excel file using X++ Code. Bellow is the some content as part of a large excel file. I would only need to filter list *_BillingCode, *_PSN, AccDistRuleAdvLedgerEntryExt etc on the basis of Public Sector in first column cells.
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)
I searched on google I found following lines of code to read from excel file.
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();
}
It is taking time to understand how could I utilize the above code, in order to meet my requirements. I would be thankful for your help.
Upvotes: 2
Views: 8264
Reputation: 18051
There are better ways to read Excel files, see Axaptapedia (I am the author by the way).
Upvotes: 2