none
Search and replace in sharedStrings RRS feed

  • Question

  • Im trying to perform a search and replace for my keywords in sharedStrings.
    This is what i have come up with so far. I cant find the way to update the value.

    using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
    {
    	using (SpreadsheetDocument doc = SpreadsheetDocument.Open(fs, true))
    	{
    	WorkbookPart workbookPart = doc.WorkbookPart;
    	SharedStringTablePart sstpart = workbookPart.GetPartsOfType<SharedStringTablePart>().First();
    	SharedStringTable sst = sstpart.SharedStringTable;
    
    	// Iterate through all the items in the SharedStringTable. If the text already exists.
    	foreach (SharedStringItem item in sstpart.SharedStringTable.Elements<SharedStringItem>())
    		{
    			if (item.Text.ToString() == "string here")
    				{
    					item.Text = "newvalue";
    				}
    		}
    		sstpart.SharedStringTable.Save();
    	}
    }


    • Edited by anhesweden Saturday, August 3, 2019 11:16 AM
    Saturday, August 3, 2019 11:16 AM