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 4236594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:39:41+00:00 2026-05-21T02:39:41+00:00

I am creating an excel add-in in c#. In the add-in the user creates

  • 0

I am creating an excel add-in in c#. In the add-in the user creates ‘query’ objects then the query is performed and data is displayed in excel.
I want to save the ‘query’ object and to be able to fetch it given a worksheet to enable editing of it and re performing the query.

I have found the following possibility:

public static void SetDocumentProperty(string propertyName, String str)
        {
            DeleteDocumentProperty(propertyName);
            var workbook = Globals.ThisAddIn.GetActiveWorkBook();
            workbook.CustomDocumentProperties.Add(propertyName, false, Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString, str);
        }

which saves the query as a string (after serializing the object).
I still need a way to connect the query to the worksheet, I have tried using the sheet name – the trouble with this is the sheet name might change. so my question is:

  1. Is there any way of getting a unique
    identifier of the worksheet?
  2. Is there a better way of achieving what i am trying to do?

Thanks

  • 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-05-21T02:39:41+00:00Added an answer on May 21, 2026 at 2:39 am

    I ended up using this:

    public static void SetWorkSheetQuery(Microsoft.Office.Interop.Excel.Worksheet ws, EntityQuery q)
     {
                        var cp = GetCustomProperty(ws,"query");
                        if (cp == null)
                            ws.CustomProperties.Add("query", q.ToJson());
                        else cp.Value = q.ToJson();
     }
    

    This attaches the object to a custom property of a worksheet after serializing it.
    It can later be fetched by using (the name of the property being "query"):

    private static CustomProperty GetCustomProperty(Worksheet ws, String name)
            {
                for (int i = 1; i <= ws.CustomProperties.Count; i++)
                {
                    if (ws.CustomProperties.get_Item(i).Name == name)
                        return ws.CustomProperties.get_Item(i);
                }
    
                return null;
            }
    

    It can be deleted by using:

    var cp = GetCustomProperty(ws, "query");
                if (cp != null)
                    cp.Delete();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been scouring for information on how to add and query data within Excel
I am creating a macro to add data from my Excel sheet into my
I am creating an Excel add-in written in VB.NET. I would like to bind
I'm creating Excel files in a PHP project. Those files aren't just CSV data...
I am creating Excel file download using NOPI libraries. I have lot of data
I use VS 2010 for creating Excel 2007 xltx template. I want to remove
I'm creating an Excel chart using C++. My problem is that I want to
I am creating a new chart for each row of data in an Excel
I am dynamically creating a Excel File that is displayed to the users upon
I am in the process of creating a VBA add-in for Excel 2010, and

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.