Hi,
I’m trying to search and replace 2 docx documents and then comparing. The search and replace is done right because I see the 2 documents with the changes, but when the script tries to compare them it returns error. The problem is the target document after saving the changes, because if I change the target document one of the originals it works. So, it seems after saving the documents, the comparison can’t be done.
Here is the script:
builder.OpenFile("http://192.168.1.45:45455/EditorDocumento/GetFile?documentId=3&type=2")
var oDocument = Api.GetDocument();
oDocument.SearchAndReplace({"searchString": "%titulo%", "replaceString": "editar externa test"});
oDocument.SearchAndReplace({"searchString": "%area%", "replaceString": "Gestión de calidad"});
oDocument.SearchAndReplace({"searchString": "%fecha%", "replaceString": "02/01/2025"});
builder.SaveFile("docx", "C:\Users\info\AppData\Local\Temp\output1_.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_sustitucion.docx")
builder.CloseFile()
builder.OpenFile("http://192.168.1.45:45455/EditorDocumento/GetFile?documentId=1004&type=2")
oDocument = Api.GetDocument();
oDocument.SearchAndReplace({"searchString": "%titulo%", "replaceString": "editar externa test"});
oDocument.SearchAndReplace({"searchString": "%area%", "replaceString": "Gestión de calidad"});
oDocument.SearchAndReplace({"searchString": "%fecha%", "replaceString": "01/11/2024"});
builder.SaveFile("docx", "C:\Users\info\AppData\Local\Temp\output2_.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_sustitucion.docx")
builder.CloseFile()
builder.OpenFile("C:\Users\info\AppData\Local\Temp\output1_.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_sustitucion.docx")
oDocument = Api.GetDocument();
const file = builderJS.OpenTmpFile("C:\Users\info\AppData\Local\Temp\output2_.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_sustitucion.docx")
AscCommonWord.CompareDocuments(Api, file, null)
file.Close()
builder.SaveFile("docx", "C:\Users\info\AppData\Local\Temp\output.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_comparacion.docx")
builder.CloseFile()
If I change the line
const file = builderJS.OpenTmpFile("C:\Users\info\AppData\Local\Temp\output2_.aaf9fb9b-8dcb-4a12-839e-4a65e7fc5ede.Resultado_sustitucion.docx")
with
const file = builderJS.OpenTmpFile("http://192.168.1.45:45455/EditorDocumento/GetFile?documentId=3&type=2")
It works, but is not ok because that is the document before the replace.
Here is the error:
TypeError: Cannot read property '5' of null
at window.AscCommonWord.rEa.KGb (<anonymous>:22370:254)
at window.AscCommonWord.rEa.Hq (<anonymous>:22371:195)
at <anonymous>:22625:458
at Object.X [as wf] (<anonymous>:12781:175)
at O (<anonymous>:22625:342)
at Object.window.AscCommonWord.CompareDocuments (<anonymous>:22714:1)
at <anonymous>:3:15
Thanks