none
Why when ThisAddIn.Application.Workbooks.Open(fullName) I lose the extension, is a bug in the model? RRS feed

  • Question

  • Hi all thank to read this,

    Why when i use ThisAddIn.Application.Workbooks.Open(fullName) to open a excel file I lose the extension, for instance

    if fullName = "xxx/xxx/xxx/file1.xltm" excel open the file, but if a look at the top of the excel where the name of the file is no extension there, then is imposible to get the extension of the file using FullName 

    Is this a bug?

    Friday, October 12, 2018 11:08 PM

All replies

  • Hi DiegoCurbelo14042014,

    >>Do you want to use FullName to get the extension of the Excel file?

    Please refer the following code:

    string fileToOpen = FD.FileName;
    
                        System.IO.FileInfo File = new System.IO.FileInfo(FD.FileName);
    
                        object misval = System.Reflection.Missing.Value;
    
                        Microsoft.Office.Interop.Excel.Application excapp;
    
                        excapp = new Microsoft.Office.Interop.Excel.Application();
    
                        Workbook wb = excapp.Workbooks.Open(File.FullName, misval, misval, misval, misval,
                            misval, misval, misval, misval, misval, misval, misval,
                            misval, misval, misval);

    If it still doesn't work, I suggest you to use the Path method, the following code to get the extension of the Excel file:

    using System;
    using System.IO;
    
    class Program
    {
        static void Main()
        {
            string path = "C:\\stagelist.xlsx";
    
            string extension = Path.GetExtension(path);
            string filename = Path.GetFileName(path);
            string filenameNoExtension =
                Path.GetFileNameWithoutExtension(path);
            string root = Path.GetPathRoot(path);
    
            Console.WriteLine("{0}\n{1}\n{2}\n{3}",
                extension,
                filename,
                filenameNoExtension,
                root);
        }
    }

    For more information, please refer the links as below:

    Opening an Excel file from within the Excel Addin

    C# program that uses Path methods

    Workbooks.Open

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 15, 2018 5:59 AM
  • Hi DiegoCurbelo14042014,

    Thanks for your asking. Please remember to mark the replies(Include your solution) as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

     

    Best Regards,

     

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Wednesday, October 17, 2018 6:03 AM