none
Reading an excel file embedded within an excel spreadsheet using .Net Excel Interop dll RRS feed

  • Question

  • Hello,

    I am using a WPF application, using which the user selects the excel files. I am able to read the text in the excel file, but unable to read excel file embedded within an excel spreadsheet. Can we read this excel file embedded within an excel spread sheet using .Net programming. I am using .Net Excel Interop Dll for reading excel file contents.

    Kindly share your thoughts !!!

    Thanks,

    Jothe Rengarajan


    Wednesday, July 15, 2015 8:52 AM

Answers

  • Hi,

    >>Any idea for reading embedded excel file within a spreadsheet

    The sample code below could read how many columns have used in the embeded sheet, you may take this as a reference  and adapt it for your project ,

            private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application app = new Excel.Application();
                Excel.Workbook wb = app.Workbooks.Add("D:\\ExcelObject.xlsx");
                app.Visible = true;
                Excel.Worksheet ws = wb.Worksheets[1];
                Excel.OLEObject obj = ws.OLEObjects(1);
                Excel.Worksheet wsh = (Excel.Worksheet)obj.Object.sheets(1);
                MessageBox.Show(wsh.UsedRange.Columns.Count.ToString ());   
            }

    Hope this could help you.

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by L.HlModerator Wednesday, July 29, 2015 9:23 AM
    Thursday, July 16, 2015 7:50 AM
    Moderator
  • Hello Jothe,

    It is not clear where and when you are going to read the file content. Of course, you can automate Excel to get the job done, take a look at the following pages for more information:

    How to automate Microsoft Excel from Microsoft Visual C#.NET

    How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays

    Be aware, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article in MSDN.

    As a workaround you may consider using the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.

    • Marked as answer by L.HlModerator Wednesday, July 29, 2015 9:31 AM
    Wednesday, July 15, 2015 9:12 AM

All replies

  • I am using a WPF application, using which the user selects the excel files. I am able to read the text in the excel file, but unable to read excel file embedded within an excel spreadsheet. Can we read this excel file embedded within an excel spread sheet using .Net programming. I am using .Net Excel Interop Dll for reading excel file contents.

    Kindly share your thoughts !!!


    Thanks,

    Jothe Rengarajan


    Wednesday, July 15, 2015 9:07 AM
  • Hello Jothe,

    It is not clear where and when you are going to read the file content. Of course, you can automate Excel to get the job done, take a look at the following pages for more information:

    How to automate Microsoft Excel from Microsoft Visual C#.NET

    How to automate Excel by using Visual C# to fill or to obtain data in a range by using arrays

    Be aware, Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution. Read more about that in the Considerations for server-side Automation of Office article in MSDN.

    As a workaround you may consider using the Open XML SDK, see Welcome to the Open XML SDK 2.5 for Office for more information.

    • Marked as answer by L.HlModerator Wednesday, July 29, 2015 9:31 AM
    Wednesday, July 15, 2015 9:12 AM
  • Thanks Eugene for the helpful links.

    In our project we are using a WPF application, to select the excel files through WPF UI. In the code behind we are reading the content in the selected excel files using the COM's - "Microsoft Excel Object Library". We are successful in reading the excel file text contents. But need help for reading the excel file embedded within the spreadsheet. Any idea for reading embedded excel file within a spreadsheet? Kindly share your thoughts.

    Thanks, Jothe Rengarajan

    Thursday, July 16, 2015 3:38 AM
  • Hi,

    >>Any idea for reading embedded excel file within a spreadsheet

    The sample code below could read how many columns have used in the embeded sheet, you may take this as a reference  and adapt it for your project ,

            private void button1_Click(object sender, EventArgs e)
            {
                Excel.Application app = new Excel.Application();
                Excel.Workbook wb = app.Workbooks.Add("D:\\ExcelObject.xlsx");
                app.Visible = true;
                Excel.Worksheet ws = wb.Worksheets[1];
                Excel.OLEObject obj = ws.OLEObjects(1);
                Excel.Worksheet wsh = (Excel.Worksheet)obj.Object.sheets(1);
                MessageBox.Show(wsh.UsedRange.Columns.Count.ToString ());   
            }

    Hope this could help you.

    Best Regards,

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by L.HlModerator Wednesday, July 29, 2015 9:23 AM
    Thursday, July 16, 2015 7:50 AM
    Moderator
  • Thursday, July 16, 2015 9:37 AM
  • Thank you all !!..

    I am able to retrieve the embedded doc.

    Best Regards,

    Jothe Rengarajan

    Tuesday, August 25, 2015 1:54 AM