Replacing text in sfdt format

I am using the document editor and saving in my backend the sfdt object.

I need to change text in the sfdt object.

after checking the format of the sfdt object I managed to retrieve the text from the "tlp" value but the text is getting splitted between several objects and its impossible to replace it because its not whole.

Is there a way to replace text in sfdt format?

thanks


1 Reply

DS Dhanush Sekar Syncfusion Team September 24, 2024 02:17 PM UTC

Hi Noam,


The Sfdt format is an internal document structure managed by the document editor. We advise against directly reading or writing in the Sfdt format, as it may lead to script errors when opening documents on the client side. Instead, you can fulfill your requirements by utilizing the find and replace functionality in DocIO. Please see the sample below for reference.

Documentation:  Find and replace in Word document | DocIO | Syncfusion

Code:

        public void Save([FromBody] SaveParameter data)
        {
            string name = data.FileName;
            string format = RetrieveFileType(name);
            if (string.IsNullOrEmpty(name))
            {
                name = "Document1.doc";
            }
            WDocument DocIOdocument = WordDocument.Save(data.Content);
            //Finds all occurrences of a misspelled word and replaces with properly spelled word
            DocIOdocument.Replace("name", "John", true, true);
            WordDocument EJ2document = WordDocument.Load(DocIOdocument);
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(EJ2document);
            FileStream fileStream = new FileStream(name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            DocIOdocument.Save(fileStream, GetWFormatType(format));
            DocIOdocument.Close();
            fileStream.Close();
        }



If the suggested approach does not align with your requirements, kindly provide more details so we can assist you further.


Regards,

Dhanush S


Attachment: ASP.NET_Core_(3)_ce34825.zip

Loader.
Up arrow icon