Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Read from Excel file in SP2013

$
0
0

Hi,

I have a requirement to read data from a formatted Excel file which is located in a document library, and put the contents in a List via code. This functionality should check - if he record exists  update the list item, if not create a new list item.

I have installed the PIA assemblies and have referenced the excel iterop services dll from

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Visual Studio Tools for Office\PIA\Office15\Microsoft.Office.Interop.Excel.dll

 

I am trying to use the excel interop services but getting the below error :

  public void readexcelfromExcelOp()
        {
             using (ClientContext clientContext = new ClientContext("http://development002/"))
                {
                    List docList = clientContext.Web.Lists.GetByTitle("MDRDocuments");
                    lblstatus.Text = " got the document library ";
                    Excel.Application xlApp = new Excel.Application();
                    Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:/C.xlsx");
                    Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
                    Excel.Range xlRange = xlWorksheet.UsedRange;

                    int rowCount = xlRange.Rows.Count;
                    int colCount = xlRange.Columns.Count;

                    for (int i = 1; i <= rowCount; i++)
                    {
                        for (int j = 1; j <= colCount; j++)
                        {
                            lblExcel.Text = xlRange.Cells[i, j].Value2.ToString();
                        }
                    }
        }

        }

 Error 1 at the above highlighted section of the code -  One or more types required to compile a dynamic expression cannot be found. Are you missing a reference? 

Pallavi Sharma http://letsgetalittletechnical.blogspot.com/


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>