Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Cant able to read the Data from Excel Sheet

Posted on by 434

Hi,

I have to read the Data from Excel sheet. Here below is my Excel sheet.The First item id i cant able to read the Second row i able to read. Any Suggestions please. I have tried formatting Cells but it hasn't help for me.

pastedimage1582867997747v1.png

Regards,

Ram.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Cant able to read the Data from Excel Sheet

    And do you get some error when you run it? What error? What line of code causes the error?

  • Ram Kumar Profile Picture
    Ram Kumar 434 on at
    RE: Cant able to read the Data from Excel Sheet

    Hi Ziyao,

    Here is my code to read the Item id from Excel sheet.

    static void ReadingExcel(Args _args)
    {
    SalesTable                             salesTable;
    SalesLine                              salesLine;
    NumberSeq                              numberSeq;
    SalesFormLetter                        salesFormLetter;
    SalesFormLetter_PickingList            salesFormLetterpick;
    SalesId                                salesId;
    InventDim                              inventdim;
    Dialog                                  dialog;
    DialogField                             file;
    SysExcelApplication                     application,application1;
    SysExcelWorkbooks                       workbooks,workbooks1;
    SysExcelWorkbook                        workbook,workbook1;
    SysExcelWorksheets                      worksheets,worksheets1;
    SysExcelWorksheet                       worksheet,worksheet1;
    SysExcelCells                           cells,cells1;
    SysExcelCell                            cell1;
    SysExcelFont                            font;
    COMVariantType                          type,type1;
    FileName                                filename,filename1;
    str Custaccount,itemno,salesunit;
    real quantity;
    real salesprice;
    
    int row=1;
    int row1 = 2;
    dialog = new Dialog("Please select the file to load");
        dialog.addText("Select file:");
        file   = dialog.addField(ExtendedTypeStr("FilenameOpen"));
        dialog.run();
    
        if (dialog.closedOK())
        {
            info(file.value());
    
            application = SysExcelApplication::construct();
            workbooks = application.workbooks();
            //specify the file path that you want to read
            filename =file.value(); //ExcelSheet File Name
            try
            {
                workbooks.open(filename);
            }
    
            catch (Exception::Error)
            {
    
                throw error('File cannot be opened');
    
            }
    
            workbook = workbooks.item(1);
            worksheets = workbook.worksheets();
            worksheet = worksheets.itemFromNum(1); //Here 1 is the worksheet Number
            cells = worksheet.cells();
            do
            {
            row  ;
            itemno = any2str(cells.item(row,2).value().bStr());
            info(itemno);
            type = cells.item(row 1, 1).value().variantType();
            }
            while (type != COMVariantType::VT_EMPTY);
    
            workbooks.close();
            application.quit();
    
            info("Done!");
    
        }
    }

    Regards,

    Ram.

  • nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Cant able to read the Data from Excel Sheet

    Can you share with us any details about how you are reading data from Excel sheet? Seems you forgot to mention it.

    Are you using one of the out of the box functionalities (defintion groups, DIXF) or did you write some own code?

  • Ziyao Profile Picture
    Ziyao on at
    RE: Cant able to read the Data from Excel Sheet

    Is this a customized import function or it's a standard build in import function? If it is a build in standard function, could you please indicate where it exactly placed?

  • Ram Kumar Profile Picture
    Ram Kumar 434 on at
    RE: Cant able to read the Data from Excel Sheet

    Hi Ziyao,

    My code can't able to read the only integer values(Eg:1000), but it can able to read the Values which is Suffixed with String (Eg: "D001"). that's what the issue i am facing now. can you able to understand my issue.

    Regards,

    Ram.

  • Suggested answer
    Ziyao Profile Picture
    Ziyao on at
    RE: Cant able to read the Data from Excel Sheet

    Hi Ram, normally the first and send row in excel stores header and template information, try to start your first item on Row 3.

    For build in import by excel function, you need to copy paste your data to the excel template exported and then import by system, if this import by excel function is customized, please check your code.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans