Discussion Infoapath Code Editor to Read and Write Excel data

  • Wednesday, March 07, 2012 4:59 AM
     
     

    Hi

       I need to Create an Infopath form 2010(say XXX)  whic will fetch data from Microsoft Excel Spreadsheet and populate it into  created(same XXX) Infopath form using Infopath code editor developing environment.

     How to achieve this??

All Replies

  • Wednesday, March 14, 2012 9:08 AM
     
     

    Hi,

         I achieve this by including Microsoft.Office.Interop.Excel refereence dll  in my Infopath code Editor and added below Code,

    ApplicationClass xlsApp = new ApplicationClass();

    WorkbookClass xlsWrkBook = (WorkbookClass)xlsApp.Workbooks.Open(("XXX.xlsx", 0, false, 5, "", "", true,XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

    Worksheet xlsWrkSht = (Worksheet)xlsWrkBook.Worksheets.get_Item(i);

    Range ExcelCellReadData1 = (Range)xlsWrkSht.Cells[x, y];

    string del1 = ExcelCellReadData1.Text.ToString();

    LocalFormData.SelectSingleNode("XXX", this.NamespaceManager).SetValue(del1);

    xlsWrkBook.Save();
    xlsWrkBook.Close(0, 0, 0);

    It works for me to fetch data from Excel and Populate it into Infopath Form.

    Regards,

    Sivakumar G


    • Edited by Siva_SREC Wednesday, March 14, 2012 9:09 AM
    •