Getting error: Read Range workbook - 'x' is an undeclared prefix. Line 2, position 2264

Greetings communities!

Here’s description of my process:

  1. Read Range workbook activity to read an Excel file (.xlsx) and store in a DataTable - InputFileDt.
  2. Read Range workbook activity to read exported SAP report (.xlsx) and store in a DataTable - ZM105Dt.
  3. For each row in InputFileDt, I check if the material code from input file match with any material code in ZM105Dt. If yes, input “True” in Remarks column in Input file. Otherwise, input “False”.
    image
  4. After done iterate all rows, robot proceeds to update the input file using Write Range Workbook acitvity.
    image

The first time I read range and update the file is working fine.
However, UiPath throws System.Xml.XmlException when I removed the updated data in “Remarks” column, save the file and rerun second time.

I checked there is no XML mapping/namespace declaration in the Excel file through ‘Developer’ tab → Source.

Has anyone encountered errors like this and what shall I do to resolve this other than recopy the original file to rerun?

22.10.10+Branch.support-v22.10.Sha.d796eef39ef460425a3cb2a072fd7b50e1c26930

Source: Read Range Workbook

Message: ‘x’ is an undeclared prefix. Line 2, position 2264.

Exception Type: System.Xml.XmlException

System.Xml.XmlException: ‘x’ is an undeclared prefix. Line 2, position 2264. at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg, Int32 lineNo, Int32 linePos)
at System.Xml.XmlTextReaderImpl.LookupNamespace(NodeData node)
at System.Xml.XmlTextReaderImpl.ElementNamespaceLookup()
at System.Xml.XmlTextReaderImpl.ParseAttributes()
at System.Xml.XmlTextReaderImpl.ParseElement()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at DocumentFormat.OpenXml.XmlConvertingReader.Read()
at DocumentFormat.OpenXml.OpenXmlCompositeElement.Populate(XmlReader xmlReader, OpenXmlLoadMode loadMode)
at DocumentFormat.OpenXml.OpenXmlElement.Load(XmlReader xmlReader, OpenXmlLoadMode loadMode)
at DocumentFormat.OpenXml.OpenXmlCompositeElement.Populate(XmlReader xmlReader, OpenXmlLoadMode loadMode)
at DocumentFormat.OpenXml.OpenXmlElement.Load(XmlReader xmlReader, OpenXmlLoadMode loadMode)
at DocumentFormat.OpenXml.OpenXmlPartRootElement.LoadFromPart(OpenXmlPart openXmlPart, Stream partStream)
at DocumentFormat.OpenXml.Packaging.OpenXmlPart.LoadDomTreeT
at ClosedXML.Excel.XLWorkbook.LoadSpreadsheetDocument(SpreadsheetDocument dSpreadsheet) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 0
at ClosedXML.Excel.XLWorkbook.LoadSheets(String fileName) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 43
at ClosedXML.Excel.XLWorkbook.Load(String file) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook_Load.cs:line 32
at ClosedXML.Excel.XLWorkbook…ctor(String file, XLEventTracking eventTracking) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook.cs:line 717
at ClosedXML.Excel.XLWorkbook…ctor(String file) in C:\projects\closedxml\ClosedXML\Excel\XLWorkbook.cs:line 707
at UiPath.Excel.WorkbookFile.InitializeExistingWorbookFile()
at UiPath.Excel.WorkbookFile…ctor(String workbookPath, String password, Boolean createNew)
at UiPath.Excel.Activities.WorkbookActivity1.ConstructWorkbook(String path, String password, Boolean createNew) at UiPath.Excel.Activities.WorkbookActivity1.BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, Object state)
at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Hi @Gwen thank you for reaching out to us :slight_smile: I’m wondering if @Anil_G or @ashokkarale can help :slight_smile: . I’ve seen them quite active in the Activities . Thank you for your patience.

@Gwen

Indtead of workbook activities can you try with excel scope activity and check…

Sometimes as workbook activities work on backend data they might be spoiling the excel data …basically workbook activities try to read as cml only…so may be some data that is present in excel is spoiling…so excel scope activities ahould solve your issue

Cheers

2 Likes

Hi @Anil_G,

Thanks for the suggestion and information. Din’t know that workbook activity read/write as xml.
I have tried with your solution and it works for me :smile:.

Below are my findings when tested with Excel Application Scope (Classic activity):

  1. Change Read Range Workbook and Write Range Workbook to Excel Application Scope Read Range and Write Range activities → Pass when run second time.

  2. Remain Read Range Workbook activity and changed Write Range Workbook activity to Excel Application Scope - Write Range activity → Pass when run second time.

  3. Changed Read Range Workbook activity to Excel Application Scope - Read Range activity and remain Write Range Workbook activity → Failed when run second time.

Throws exception: Excel Application Scope: Failed opening the Excel file (workbook path). Possible reasons: the file is corrupt, the file is already used by another process or you don’t have permissions to open the file.

I noticed the error which I mentioned in my first post happened in Write Range Workbook activity. It seems this activity causing the file corrupted which you’ve highlighted in your replies.

Besides, may I ask for your opinion whether should use classic Excel Application Scope activity or the modern Excel Process Scope activity?

1 Like

@Gwen

Both can be used…but i would say now try to go with modern as going forward those are used more…and it has more options to control excel…

But again modern activities currently are slow compared to classic especially on larger excels that might pose an issue.Hope UiPath team will fix them

Cheers

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.