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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:58:35+00:00 2026-05-21T22:58:35+00:00

I have a cell that contains the placeholder $$value in the Excel sheet, the

  • 0

I have a cell that contains the placeholder “$$value” in the Excel sheet, the thing is that I need to replace the placeholder’s actual value using Open XML and save it as separate workbook.

Here is the code that I tried…it is not replacing the actual value and also I’m unable to save the workbook. I need to sort out this issue.

WorksheetPart worksheetPart = (WorksheetPart)myWorkbook.WorkbookPart.GetPartById(sheet.Id);

DocumentFormat.OpenXml.Spreadsheet.Worksheet worksheet = worksheetPart.Worksheet;

string _txt1 = "$$value";

if (_txt1.Contains("$$"))

{

     worksheet.InnerText.Replace(_txt1, "test");

}
  • 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-21T22:58:36+00:00Added an answer on May 21, 2026 at 10:58 pm

    by default Excel stores strings in the global (1 per workbook) SharedStringTablePart. So, this is the one you need to target. However, the OpenXML format also allows inline text inside the WorksheetParts. hence, a complete solution needs to look there as well.

    Here’s a sample app (with some inline comments):

    using DocumentFormat.OpenXml.Packaging;
    using x = DocumentFormat.OpenXml.Spreadsheet;
    
    class Program
    {
    private static readonly string placeHolder = "$$value";
    
    static void Main()
    {
        var templatePath = @"C:\Temp\template.xlsx";
        var resultPath = @"C:\Temp\result.xlsx";
        string replacementText = "test";
    
        using (Stream xlsxStream = new MemoryStream())
        {
            // Read template from disk
            using (var fileStream = File.OpenRead(templatePath)) 
                fileStream.CopyTo(xlsxStream);
    
            // Do replacements
            ProcessTemplate(xlsxStream, replacementText);
    
            // Reset stream to beginning
            xlsxStream.Seek(0L, SeekOrigin.Begin);
    
            // Write results back to disk
            using (var resultFile = File.Create(resultPath))
                xlsxStream.CopyTo(resultFile);
        }
    }
    
    private static void ProcessTemplate(Stream template, string replacementText)
    {
        using (var workbook = SpreadsheetDocument.Open(template, true, new OpenSettings { AutoSave = true }))
        {
            // Replace shared strings
            SharedStringTablePart sharedStringsPart = workbook.WorkbookPart.SharedStringTablePart;
            IEnumerable<x.Text> sharedStringTextElements = sharedStringsPart.SharedStringTable.Descendants<x.Text>();
            DoReplace(sharedStringTextElements, replacementText);
    
            // Replace inline strings
            IEnumerable<WorksheetPart> worksheetParts = workbook.GetPartsOfType<WorksheetPart>();
            foreach (var worksheet in worksheetParts)
            {
                var allTextElements = worksheet.Worksheet.Descendants<x.Text>();
                DoReplace(allTextElements, replacementText);
            }
    
        } // AutoSave enabled
    }
    
    private static void DoReplace(IEnumerable<x.Text> textElements, string replacementText)
    {
        foreach (var text in textElements)
        {
            if (text.Text.Contains(placeHolder))
                text.Text = text.Text.Replace(placeHolder, replacementText);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have a cell that I want to be red if the value
I have a UITableView that contains a UITextField in each cell. I can't seem
I have a popover that contains a UITableView. This UITableView has a cell with
I'm working with Ms. Excel. I have a cell contains a person name. Eg
I have an array created in MATLAB that contains a number of cell type
I have UITableView that contains many cell. User can expand cell to see more
I have an HTML page (PHP, really) with a table cell that contains a
I have a table that has a column that contains links. Each cell in
I have a tableview, one of the rows contains a cell that contains a
I have a cell in column 3 that contains a datetime: 5/12/2011 8:13AM .

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.