On excel sheet upload read the workbook and populate data to sharepoint list

Requirement in my current project:
In a document library when I upload an excel sheet, a specific workbook has to be read and the contents have to be uploaded to a sharepoint custom list.
The approach followed was create an event receiver and register as a feature. Following is the code for event receiver.
public override void ItemAdded(SPItemEventProperties properties)
            base.ItemAdded(properties);
            var list = getSPList("{150301BF-D0BD-452C-90D7-2D6CD082A247}");          
            SPListItem doc = properties.ListItem;
            doc["Msg"] = "items deleted from req list";
            doc.Update();
            string excelname=doc.File.Name;
            System.Diagnostics.EventLog.WriteEntry("ExcelUpload", "calling read excel");
            string filepath = doc.File.Url.ToString();
            doc["Msg"] = "excel name" + excelname + filepath;
            doc.Update();
            readExcel(excelname,filepath);
        private static SPList getSPList(String SPListGuid)
           // SPSite Site = SPContext.Current.Site;
            SPSite Site = new SPSite("http://omistestsrv:32252/sites/OMD");
            SPWeb web = Site.OpenWeb();
            Guid listid = new Guid(SPListGuid);
            web.AllowUnsafeUpdates = true;
            SPList List = web.Lists[listid];
            return List;
        private void readExcel(string excelname,string filepath)
            try
                SPSecurity.RunWithElevatedPrivileges(delegate()
                    using (SPSite Site = new SPSite("http://omistestsrv:32252/sites/OMD"))
                        SPWeb web = Site.OpenWeb();
                        string workbookpath = web.Url + "/" + filepath;
                        web.AllowUnsafeUpdates = true;
                        var _excelApp = new Microsoft.Office.Interop.Excel.Application();
                        System.Diagnostics.EventLog.WriteEntry("ExcelUpload", "iside read excel");
    //my code breaks or fails when cursor reaches this statement. I am not able to open the excel sheet, there is no    //problem related to the permission. same code snippet works in a console application. but when tried as an
event    //handler in sharepoint it breaks. can anyone help me to resolve the problem
                        workBook = _excelApp.Workbooks.Open(workbookpath, Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing,
Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing, Type.Missing, Type.Missing,Type.Missing, Type.Missing);
                        System.Diagnostics.EventLog.WriteEntry("ExcelUpload", "after excel open");
                            int numSheets = workBook.Sheets.Count;
                            // Iterate through the sheets. They are indexed starting at 1.
                            System.Diagnostics.EventLog.WriteEntry("ExcelUpload", numSheets.ToString());
                            for (int sheetNum = 12; sheetNum < 13; sheetNum++)
                                System.Diagnostics.EventLog.WriteEntry("ExcelUpload", "inside first for
loop");
                                Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Sheets[sheetNum];
                                Microsoft.Office.Interop.Excel.Range excelRange = sheet.get_Range("A13",
"P89") as Microsoft.Office.Interop.Excel.Range;
                                object[,] valueArray = (object[,])excelRange.get_Value(
                                    Microsoft.Office.Interop.Excel.XlRangeValueDataType.xlRangeValueDefault);
                                var list = getSPList("{150301BF-D0BD-452C-90D7-2D6CD082A247}");
                                for (int L = 1; L <= excelRange.Rows.Count; L++)
                                    string stringVal = valueArray[L, 1] as string;
                                    if ((valueArray[L, 1] != null) && (!string.IsNullOrEmpty(stringVal)))
                                        System.Diagnostics.EventLog.WriteEntry("ExcelUpload",
"inside second for loop");
                                        SPListItemCollection
listItems = list.Items;
                                        SPListItem item = listItems.Add();
                                        item["Product"] = valueArray[L,
1];
                                        item["App"] = valueArray[L,
2];
                                        web.AllowUnsafeUpdates
= true;
                                        item.Update();
                            web.AllowUnsafeUpdates = false;
                            //Or Another Method with valueArray Object like "ProcessObjects(valueArray);"
                            _excelApp.Workbooks.Close();
                //workBook.Close(false, excelname, null);
                //Marshal.ReleaseComObject(workBook);
            catch (Exception e)
                System.Diagnostics.EventLog.WriteEntry("ExcelUpload", e.Message.ToString());
            finally
                System.Diagnostics.EventLog.WriteEntry("ExcelUpload", "finally block");
Is this the only approach to meet this requirement or is there any other way to crack it. sharepoint techies please help me.

as you described the scenario of the event that it should happen when user upload excel to a document library. Event Receiver is your best bet. However if you would have a requirement that users can send excel files any time to a network file location and
you want to pick it, read it and create list items etc. You would write a sharepoint timer job that would run every 10 minute to check for file and if available on the network drive, perform the operation etc. so that users who send excel file does not need
to come to the sharepoint etc. You can see that you have Event Receivcer option or Timer job option OR you would write a console application to trigger the code at a scheduled time on sharepoint server etc. so you are using the event receiver in the correct
scenario.
Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)

Similar Messages

  • How to create an Excel sheet in side the Studio, and wirte somethiing

    actually i want to create one excel sheet and in that i want to place some data.
    can anybody help me..?

    Hi,
    In addition to the post I made on http://forums.bea.com/bea//thread.jspa?forumID=600000022&threadID=300003034 to add a template that has the header and formatting information you want you could use logic like this:
    templateName as String = "C:/Student/Excel/InvoiceTemplate.xls"
    newFileName as String = "C:/Order" + orderNumber + ".xls"
    // *** Warning ***
    // This next statement makes Excel visible
    // and should only be done for testing
    // purposes. Normally, this would be
    // run on the server with no human
    // interaction
    xl.visible = true
    // To open an existing Workbook use this syntax:
    workBookTemplate = open(xl.workbooks, filename : templateName)
    // Save as the filename you want. Including the orderNumber
    // variable simply ensures that the invoice is unique by the order
    // number.
    saveCopyAs workBookTemplate
    using filename = newFileName
    // Now open the new Workbook that you just created
    workbookNew = open(excel.workbooks, filename : newFileName)
    Hope this gets you going,
    Dan
    Edited by datwood at 04/29/2008 7:56 AM

  • Display Excel on browser & read the edited Excel sheet

    Hi,
    Till now i was using POI api to create Excel sheet and add data to the sheet. Now we had a requirement to display Excel sheet on browser. User can edit the Excel and on click of Save button, we need to read the data and save it to Database. If i use frames i can display Excel on browser. But once user edits the Excel, how to read the Excel sheet which is displayed on browser.

    It sounds like what you're trying to do is write an Excel<-->HTML converter, no? If you want it editable through a browser (presumably with no Excel installed) but stored in the native format?

  • Access excel sheet uploaded in library on sharepoint using sharepoint development

    Hi,
    I have an excel sheet which i have uploaded on sharepoint site as a library.
    now i want to access this excel sheet using sharepoint development(c#).
    Is it possible?
    I have one another query- I want to read excel sheet using sharepoint 2010 development.
    Please help to solve both issues.
    Thanks in advance!
    Regards
    rajni

    Hi rajni,
    According to your description, my understanding is that you want to access the excel files uploaded in a library and read the worksheet data by C#.
    You can read excel file using Excel Services. The Excel Services REST API is a new feature of Excel Services that enables you to access Microsoft Excel workbook data by using a uniform resource locator (URL) address. Using the REST API, you can retrieve
    resources such as ranges, charts, tables, and PivotTables from workbooks stored on SharePoint Server 2010. More inforamtion, please refer to the link below:
    http://msdn.microsoft.com/en-us/library/hh124646(v=office.14).aspx
    There are other useful links about accessing and reading excel file in library, please take a look at:
    http://www.sharepointwithattitude.com/archives/61
    http://www.c-sharpcorner.com/uploadfile/vivekbritish/how-to-downloadread-excel-file-from-sharepoint-library-using-excel-services/
    http://stackoverflow.com/questions/14496608/read-excel-file-stored-in-sharepoint-document-library
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • How to get data from excel sheet present in the client(local) system?

    hi,
    I have to upload the data from an excel sheet present in the local system(not on the server) to the table using webdynpro.
    i donot want to upload the excel file
    if it is necessary to upload the file then it should be on temporary basis and it should be deleted automatically.
    i can get the data from excel sheet which is present in the km using HSSF api but how to do the same if it is in local system?
    if anyone has the sample application of this type please give me the link.
    thanks

    You can use the FM ALSM_EXCEL_TO_INTERNAL_TABLE with Web Dynpro ABAP.

  • How to update a custom list when there is a changes in excel sheet uploaded in document library

     
    I have created a document library in which m uploading a excel sheet with values in it and i have created a custom list with same no.of.rows and columns in the excel sheet given the same name of columns. Now i have to make sure that whatever changes i do
    in the excel sheet should automatically gets updated in custom list in sharepoint

    You'll need to create an event receiver for when you add/update a document on the source library (http://msdn.microsoft.com/en-us/library/office/gg749858(v=office.14).aspx)
    Then, with code open the excel file and count the rows. You can use the OpenXmlSDK to do that (http://www.microsoft.com/en-us/download/details.aspx?id=5124)
    Good luck ;)

  • Download date into excel sheet without changing the properties of column

    Hi All,
    I am trying to download a date field from SAP to Excel sheet. But the date is getting downloaded successfully, but the format of the column is getting changed to DATE. Is there any way to restrict it?
    I am using GUI_DOWNLOAD for downloading the data.
    I have declared the date field as CHAR10  Eg (09/13/2011) and moving the data into excel.
    Result i need : data should be downlaoded as 09/13/2011 but format of the cell should not be changed.
    Regards
    Eswar.

    Hi Eswar,
    Change the date format type dats instead of char format or any standards like erdat from vbak.Then you can in proper format.
    Regards,
    Madhu.

  • XML page cannot be displayed cannot view XML input using XSL style sheet Please correct the error and then click the REfresh

    XML page cannot be displayed cannot view XML input using XSL style sheet Please correct the error and then click the REfresh

    Is the error message displayed in Firefox or in IE, or in a customized window that doesn't identify the browser?
    ''If it displays in Firefox:''
    It's possible that the Troubleshooter doesn't work correctly unless IE is your default browser. You could test that possibility by having IE make itself the default and testing the Troubleshooter again.
    ''If it displays in IE or embedded in another Microsoft application:''
    In a web search I found these suggestions:
    (1) Reset your Internet Explorer settings, according to http://answers.microsoft.com/en-us/ie/forum/ie8-windows_7/cannot-view-xml-using-xsl-style-sheet/ccfe80c6-c0db-4594-a7e3-475f9eac0e85
    (2) Try the System File Checker, according to http://ask-leo.com/why_do_i_get_the_xml_page_cannot_be_displayed_after_running_a_microsoft_troubleshooter.html
    Any luck?

  • I am trying to send photos to the cloud from my phone to my iPad but they are not appearing in the stream. I have read the instructions and I think I am doing it right or am I missing a part of the process?

    I am trying to send photos to the cloud from my phone to my iPad but they are not appearing in the stream. I have read the instructions and I think I am doing it right or am I missing a part of the process?

    HI,
    Have you done this before ? And if so, is photo stream turned on on your iphone and ipad. and as Alfred DeRose pointed out they must both on the same icloud account.
    If you're new to this, you might want to do some research. Photo stream is different from camera roll and albums. Many have been on this sight looking for their photos stored in icloud after restore, etc. and they're not there. Also, after thirty days icloud deletes your photos from photo stream.
    So if you're not aware, you might want to google your question. We're using the camera connection kit soon and I am learning about it. From all I've read, I'm also not the biggest icloud fan. I use dropbox. We plan to put photos taken on ipad with a camera/iphones into albums on the ipad. We'll keep all on the sd card until (and after) they can be uploaded to a computer.
    An example of an article we can learn from -
    http://www.macobserver.com/tmo/article/how-to-understand-and-work-with-your-iclo ud-photo-stream
    Hope this helps.

  • After reinstalling game, the achievements from Game Center doesn't uploaded to the game and starts from the beginning . All the achievements are seen in the Game Center . How could I upload the last progress into the game?

    After reinstalling game, the achievements from Game Center doesn't uploaded to the game and starts from the beginning . All the achievements are seen in the Game Center . How could I upload the last progress into the game?

    Hello there, Elena Lyubina.
    The following Knowledge Base article offers up some great steps for troubleshooting issues with an application not functioning as expected:
    iOS: An app you installed unexpectedly quits, stops responding, or won’t open
    http://support.apple.com/kb/ts1702
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • How to Get the excel sheet formula from the server side into the j2me app?

    How to Get the excel sheet formula from the server side into the j2me application?
    Here the excel sheet is in server side.i want to do get the excel sheet values (only some part of the excel sheet based on some conditions) from server side into j2me.In j2me I want to done some client side validation based on the formula of excel sheet.Then i resend the new updated data to the server.
    But here deosn't know any mehtod to get the excel sheet formula from server side.So kindly help me to get the excel sheet formula from the server.
    So how to get the excel sheet formula frome the server side into j2me Application...
    Plz guide me to solve this issue...
    thanks & regards, Sivakumar.J

    You should not post a thread more than once. You've crossposted this question to another forum. I have deleted that one.

  • When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?!

    When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?! and then I'd like to erase the original files since the space requirement is huge!!!! Why is upgrading software iPhoto such a pain. I've gotta get a presentation done and all I get for my money is roadblock!!!

    hello, it sounds like the library is damaged.
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. 

  • I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem-.thanks

    I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem….thanks

    If you are having the same problem, i.e. a disk permission problem, open your favorite search engine and search on, "change disk permissions", and I think you'll find plenty of information on how to fix the problem. This is a Lightroom forum. Your problem is with your operating system. There is no sense in rewriting instructions that are already available if you do a simple search.

  • Hi. I use Adobe Acrobat XI pro to make a PDF ebook embedded with audio. It works really well on my computer-I can read the book and hear the auto play mp3. The problem is, when I send it to my customers, they have difficulty hearing the audio. A few of th

    Hi. I use Adobe Acrobat XI pro to make a PDF ebook embedded with audio. It works really well on my computer-I can read the book and hear the auto play mp3. The problem is, when I send it to my customers, they have difficulty hearing the audio. A few of them say they have Flash player on their PC and somehow they still can't hear, some say their Google Chrome browser tells them they've already got one flash player while they try to download one. For me, I had to download two versions of Flash player to be able to access to the audio. I don't know what the problem is, is it because it's the latest version of Adobe Acrobat XI pro that people with older version of Adobe reader or flash player can't open it properly? Or is it something else? How can I make sure every customer with different system can access to my books? Hope to hear from you ASAP! Thank you very much.

    And how are the customers accessing the PDFs?
    What devices are they using?
    What program or apps with versions are they using?
    I this age of other then PDF eBooks formats and reader program and apss for computers and mobile devices for these formats I would look at creating the books in one or more of the eBook formats.
    Google Chrome and FireFox both have their own version of a PDF reader plug-in and they are well known to be less capable than Adobe Reader. It is possible to configure these products to use Adobe Reader.

  • How do I send an iMessage, a step by step answer. I have read the manual and it doesnt explain how

    Can someone explain how you send an iMessage. I know how to send texts and emails but I only want to use the iMessage so that my company bill doesnt show text numbers called. I have got iMessage turned on in settings. I have read the manual and it says you can do it but it doesnt say how.

    Thanks for your response. It helps a little. I now dont know how to change the send button from green to blue. What determines how the message is sent?
    I know in the settings I can turn off "send as sms" so that should stop text messages being sent. I went through my contact list and selected a few people at random and noticed the send button was green for some and blue for others so I am thinking it may be either something they do to let me iMessage them or it is something I have to do in my contact list.
    Do you know?

Maybe you are looking for

  • How can I create a Tree with Color Picker icons?

    I'm a newbie to Flex. I want to create a tree which has color picker icons. As an analogy for the Mac users out there, I envision a control like the Calendars section in iCal, where you can specify the color for each individual node. These colors are

  • Link between Delivery schedule line counter from PO and the material docume

    Dear Gurus, I have one PO with single line item having delivery schedule - Material 1 - delivery schedule 01.01.2009     2000                                                      01.03.2009    5000 I have received quantity against this Po I want to k

  • Can I use two different greens for green screening and keep one without it being keyed out?

    I am using a green screen which is your standard light green fabric. I am also wearing a bottle green cape. I want to key out the standard green which is no problem. However it also takes out the bottle green on my cape. Is there a way on either Prem

  • How can i set the size of the task windows and text to something more suitable?

    When i bought my HP Touchsmart 600 pc the text size and window size on the desktop were tiny as Default, i manage to change it where it wasnt to big or small it was just right. but recently i had to restore my whole computer back to factory settings

  • Error 87

    hello i tried enabling dotnet feature in windows 8 but error message appeared Deployment Image Servicing and Management tool Version: 6.2.9200.16384 Image Version: 6.2.9200.16384 Error: 87 The limitacces option is not recognized in this context. befo