Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8550145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:53:04+00:00 2026-06-11T13:53:04+00:00

I recently wanted to see if I could create an excel spreadsheet using c#

  • 0

I recently wanted to see if I could create an excel spreadsheet using c# for a task in my work. I wrote a quick program (see code below) to learn the basics and now everytime I open Excel the spreadsheet that was generated by my code is displayed. How do I stop this from happening?

namespace ExcelAddIn1
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            var bankAccounts = new List<Account>
            {
             new Account
             {
                ID = 1, 
                Balance = 50.00, 
                Payee = "Debit", 
                PayDate = DateTime.Today
             }
            };

            DisplayInExcel(bankAccounts, (account, cell) =>
                //This multiline lamda expression sets 
                //custom processing rules for bankAccounts.
                {
                    cell.Value = account.ID;
                    cell.Offset[0, 1].Value = account.Balance;
                    cell.Offset[0, 2].Value = account.Payee;
                    cell.Offset[0, 3].Value = account.PayDate;
                    if (account.Balance < 0)
                    {
                        cell.Interior.Color = 255;
                        cell.Offset[0, 1].Interior.Color = 255;
                    }
                });
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        void DisplayInExcel(
            IEnumerable<Account> accounts, 
            Action<Account, 
            Excel.Range> DisplayFunc)
        {
            var excelApp = this.Application;
            // Add a new Excel workbook.
            excelApp.Visible = true;
            excelApp.Workbooks.Add();

            #region cellValues
            excelApp.Range["A1"].Value = "ID";
            excelApp.Range["B1"].Value = "Balance";
            excelApp.Range["C1"].Value = "Payee";
            excelApp.Range["D1"].Value = "Date";
            excelApp.Range["A2"].Select();

            foreach (var ac in accounts)
            {
                DisplayFunc(ac, excelApp.ActiveCell);
                excelApp.ActiveCell.Offset[1, 0].Select();

            }
            #endregion

            // Copy the results to Clipboard.
            excelApp.Range["A1:D2"].Copy();

            excelApp.Columns[1].AutoFit();
            excelApp.Columns[2].AutoFit();
            excelApp.Columns[3].AutoFit();
            excelApp.Columns[4].AutoFit();
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:53:05+00:00Added an answer on June 11, 2026 at 1:53 pm

    Since you are using the Startup-event this code is launched every time you start Excel.
    Disabling the Add-in in Excel itself will solve your issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wanted to see if I am able to solve an easy sudoku
I have been working on a Java game and I recently wanted to see
I was using \documentclass{amsmath} for awhile with no issues, but I recently wanted to
Recently I've wanted to do a number of things using CSS only to find
I wanted to list all my Recently Used Items. I use this code: public
I've recently made a change stylistically and wanted to see how other c++ programmers
I recently installed Ubuntu to run alongside my Windows OS. I wanted to see
I recently wanted to build my own client-server system by using BSD sockets. After
A colleague recently was looking at call graphs and wanted to see what called
Recently we came across a situation where we wanted to see the debug info

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.