EvotecIT / OfficeIMO

Fast and easy to use cross-platform .NET library that creates or modifies Microsoft Word (DocX) and later also Excel (XLSX) files without installing any software. Library is based on Open XML SDK
MIT License
263 stars 47 forks source link

implements muti para search and replace #149

Closed startewho closed 1 year ago

startewho commented 1 year ago

Till now, Office IMo can's find and replace the string from mutil para. after search the web .found two source to do it

Search and Replace Text in an Open XML WordprocessingML Document | Eric White

https://github.com/nissl-lab/npoi/blob/32435d9485181a08f6993d3e94c10a70e5bb810a/ooxml/XWPF/Usermodel/XWPFParagraph.cs#L1307C22-L1307C22

the import thing is found the string location index of paras.

Also modify the wrong test and examples.

Before image After image

PrzemyslawKlys commented 1 year ago

So I have some questions, because that seems like a very cool PR

  1. We are right now using CleanupDocument() to potentially clear paragraphs that are the same and therefore allow for better search/replace. But if I understand you right, with your code we don't need to do that anymore? Right?

  2. What happens if you are searching for Project Name which is not cleaned up because it's 2 different styles (say Red, Green) and you replace ProjectName to something else? It could be even more confusing if you replace string that is over 2 or more paragraphs, having different styles - how would it apply?

startewho commented 1 year ago

So I have some questions, because that seems like a very cool PR

  1. We are right now using CleanupDocument() to potentially clear paragraphs that are the same and therefore allow for better search/replace. But if I understand you right, with your code we don't need to do that anymore? Right?

yes.it does not needed.

  1. What happens if you are searching for Project Name which is not cleaned up because it's 2 different styles (say Red, Green) and you replace ProjectName to something else? It could be even more confusing if you replace string that is over 2 or more paragraphs, having different styles - how would it apply?

it use the first para style.and the last para will be empty. the mid paras will be remove usually.when we replace string.it use the same style most of time