none
Can I use Excel file to store data in the PC that Excel is not installed? RRS feed

  • Question

  • I want to use MS Excel file to store data in my program.

    My program works in my PC because the MS Office is installed already.

    However I'm worrying that my program may not work in other PC that the MS Office is not installed.

    I have no extra PC that MS Office is not installed to test if my program can access MS Excel.

    Can anybody give me some advice regarding this issue?

    FYI, I'm developping program with Visual Studio 2005(.NET 2.0)

    Monday, December 3, 2018 8:27 PM

Answers

  • You cannot use the Office interop assemblies (aka COM) without Office installed. There is no workaround. To read .xslx files without Office change your code to use OpenXML instead and then you can use it without Office installed.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Jeff0803 Wednesday, December 5, 2018 9:25 PM
    Wednesday, December 5, 2018 9:07 PM
    Moderator
  • The code you are using is important for this answer. Are you using Excel interop? If so then you cannot use it on a computer without Office installed. Are you using ADO.NET? If so then you can use it on a computer without Office. Are you using OpenXML? If so then you can use it on a computer without Office. It is completely dependent upon the code you're using. We have no way of giving you a yes/no answer since we do not know what technology you're using to access the data.


    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Andrew B. Painter Thursday, December 6, 2018 4:29 PM
    • Marked as answer by Jeff0803 Friday, December 7, 2018 3:52 AM
    Thursday, December 6, 2018 4:12 PM
    Moderator

All replies

  • I am 99% sure that you can't do this, at least when using interop. When I do anything with Excel, an Excel process always starts in the background.

    Ethan


    Ethan Strauss

    Monday, December 3, 2018 10:37 PM
  • Hello,

    Excel automation requires Excel to be installed period.

    Your options are

    • Use OpenXML as shown in this TechNet Wiki which only works with Excel 2007 format or higher. Downsides is it will greatly increase the installation size and is not easy to learn.
    • Use a free third party library such as SpreadSheetLight which is a light install base, easy to learn. Downside is it works solely with Excel 2007 or higher.
    • Purchase a third party library e.g. Gembox SpreadSheet which works with all versions of Excel. Downside, it's not cheap but can attest it does everything you need. 
    • Place a blank Excel file in your executable folder and copy it to where is needed. Downside, will not work with Excel automation but will work with OleDb data provider but in this case you can not do formatting of cells or internal calculations.

    My first recommendation is SpreadSheetLight as it's completely free from needing Excel installed and you can get up to speed faster than other options. SpreadSheetLight is installed via NuGet package manager by searching for SpreadSheetLight and that's it.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, December 3, 2018 11:27 PM
    Moderator
  • You may need to use OpenXML or 3rd party libraries if you dont have MS Office installed. Take a look at spire.xls library (available on NuGet), as far as I can see it supports to work with .NET 2.0.
    Tuesday, December 4, 2018 3:14 AM
  • What I'm trying to do is not Excel Automation but just store data instead of MS Access.

    I need to edit data in Excel table manually, release with my program and program will load data from the Excel file.

    However I have no idea what happens when program run the PC MS office doesn't be installed.

    This is what I want to know.


    • Edited by Jeff0803 Tuesday, December 4, 2018 3:12 PM
    Tuesday, December 4, 2018 3:10 PM
  • What I'm trying to do is not Excel Automation but just store data instead of MS Access.

    I need to edit data in Excel table manually, release with my program and program will load data from the Excel file.

    However I have no idea what happens when program run the PC MS office doesn't be installed.

    This is what I want to know.


    Code for MS-Access is not done here, only reading known rows and columns and I return data typed e.g. first column is an int. If I didn't know the type we would use GetCellValueAsString. The code below also determines if the sheet exists or not.

    using System;
    using System.IO;
    using SpreadsheetLight;
    
    namespace SpreadSheetLight1
    {
        public class Operations
        {
            /// <summary>
            /// Read from an Excel in the same folder as the executable,
            /// sheet name People Iterate known rows/columns and get
            /// values strong typed
            /// </summary>
            public void Example1()
            {
                var fileName = Path.Combine(AppDomain
                    .CurrentDomain.BaseDirectory,"File1.xlsx");
    
                // does file exist?
                if (!File.Exists(fileName))
                {
                    throw new Exception("Dude where is the file");
                }
    
                string sheetName = "People";
    
                using (var doc = new SLDocument(fileName, sheetName))
                {
                    var sheetNames = doc.GetSheetNames(false);
                    // does sheet exists
                    if (!sheetNames.Contains(sheetName))
                    {
                        throw new Exception("Sheet does not exists");
                    }
    
                    SLWorksheetStatistics stats = doc.GetWorksheetStatistics();
    
                    int identifier = 0;
                    string firstName = "";
                    string lastName = "";
                    DateTime someDateTime = DateTime.Now;               
    
    
                    for (int rowIndexing = 1; rowIndexing < stats.EndRowIndex +1; rowIndexing++)
                    {
                        identifier = doc.GetCellValueAsInt32(rowIndexing, 1);
                        firstName = doc.GetCellValueAsString(rowIndexing, 2);
                        lastName = doc.GetCellValueAsString(rowIndexing, 3);
                        someDateTime = doc.GetCellValueAsDateTime(rowIndexing, 4);
    
                        Console.WriteLine($"{identifier}, {firstName}, {lastName}, {someDateTime.ToShortDateString()}");
    
                    }
                }
            }
        }
    }
    

    Results in the IDE Output window

    The sheet


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, December 4, 2018 3:49 PM
    Moderator
  • A .xls file can be read without Office (with StgOpenStorage and so on)

    But you said that your "program works because the MS Office is installed already."

    and  

    "What I'm trying to do is not Excel Automation"

    So, how do you read the .xls file actually ?

    Tuesday, December 4, 2018 3:57 PM
  • If you want to use Office then Office needs to be installed. If that isn't an option and you support the newer Office formats (e.g. xslx) then you can use OpenXML SDK instead. However you won't be able to do everything you can in Office and the Office interop assemblies won't work. So you'll have to decide which is more important to your app.

    Note that storing data in Excel isn't recommended or needed in most cases. If you want CSV support then you don't need Office (or OpenXML). ADO.NET already supports that. If you need something more elaborate then consider using JSON instead. You only need/want to use Excel (or Access or whatever) if those programs provide features you need (e.g. formulas, cell referencing, etc).


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, December 4, 2018 8:19 PM
    Moderator
  • What I want to exactly do is like following.

    1. My developement PC is already installed MS office.

    2. I'll edit data file manually using MS Excel and save it as .xls.

    3. My C# program will read Excel file using ADO.NET.

    4. I will release my program + data file(.xls)

    What I want to know is whether my program would work without any problem at the PC where no MS Office is installed or not.


    • Edited by Jeff0803 Wednesday, December 5, 2018 9:27 PM
    Wednesday, December 5, 2018 9:04 PM
  • You cannot use the Office interop assemblies (aka COM) without Office installed. There is no workaround. To read .xslx files without Office change your code to use OpenXML instead and then you can use it without Office installed.

    Michael Taylor http://www.michaeltaylorp3.net

    • Marked as answer by Jeff0803 Wednesday, December 5, 2018 9:25 PM
    Wednesday, December 5, 2018 9:07 PM
    Moderator
  • As mentioned already the answer to using Excel without Excel installed is no for .xls without using a third party libary.

    The majority of libraries are geared towards .xlsx. OpenXML is .xlsx based not .xls, same goes for SpreadSheetLight.

    I would suggest reading the following

    https://stackoverflow.com/questions/2654932/create-excel-files-from-c-sharp-without-office


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, December 5, 2018 9:28 PM
    Moderator
  • Sorry, final sentense in my comment is not clear.

    Here is new comment.

    "What I want to know is whether my program would work without any problem at the PC where no MS Office is installed or not."

    Wednesday, December 5, 2018 9:30 PM

  • You can do this with VBScript and VBA and C# or VB.NET.  You do not need any office application installed at all and you do not use COM Interop.  Just arrange your thinking to the point that Excel is nothing but a GUI on a database and the database is the .xls or .xlsx format.

    I already implemented reading Excel in my program.

    What I want to know is whether it works in the PC where no MS office is installed or not.


    • Edited by Jeff0803 Thursday, December 6, 2018 4:05 PM
    Wednesday, December 5, 2018 9:35 PM
  • We're going around and around here. Please post the code you are using. That it immediately give us the answer.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, December 5, 2018 9:51 PM
    Moderator
  • This is not code issue.

    As I mentioned several times, I already implemented the codes acquiring data from Excel file and works fine in my PC because MS Office is isntalled already.

    My program is not Excel automation but just a reading data from Excel.

    What I want to know is that whether my program will work in the PC where MS Office is not installed or not.


    • Edited by Jeff0803 Thursday, December 6, 2018 4:12 PM
    Thursday, December 6, 2018 4:09 PM
  • The code you are using is important for this answer. Are you using Excel interop? If so then you cannot use it on a computer without Office installed. Are you using ADO.NET? If so then you can use it on a computer without Office. Are you using OpenXML? If so then you can use it on a computer without Office. It is completely dependent upon the code you're using. We have no way of giving you a yes/no answer since we do not know what technology you're using to access the data.


    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Andrew B. Painter Thursday, December 6, 2018 4:29 PM
    • Marked as answer by Jeff0803 Friday, December 7, 2018 3:52 AM
    Thursday, December 6, 2018 4:12 PM
    Moderator
  • Yes I implemented code using ADO.NET.

    I understood that my program will work in the PC without MS Office.

    I'm trying finding PC to test for double check but I think it'll work without any problem.

    Thanks!

    Friday, December 7, 2018 3:56 AM