map Schema to Excel thorugh xpath. C#.net

S

Saffy .Net

this is extension to post on page/url

http://social.msdn.microsoft.com/Forums/en-US/Offtopic/thread/475a313c-d67b-454f-915f-f700745de22b



try
{
Microsoft.Office.Interop.Excel.Application m_objExcel;
m_objExcel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks m_objBooks =
(Microsoft.Office.Interop.Excel.Workbooks)m_objExcel.Workbooks;
Microsoft.Office.Interop.Excel._Workbook m_objBook;

string filePath1 = "D:\\SMAS\\AppXmlGen\\TempFolder\\";

m_objBook =
(Microsoft.Office.Interop.Excel._Workbook)(m_objBooks.Add(filePath1+"Book3.xlsx"));


object m_objOpt = System.Reflection.Missing.Value;






string fpath = filePath1 + "XOA.xsd";

XmlMap xmp;

xmp = m_objBooks[1].XmlMaps.Add(fpath,
"TTSObjectCreateRequest");
xmp.Name = "TTSObjectCreateRequest_Map";


Microsoft.Office.Interop.Excel._Worksheet m_objSheet =
(Microsoft.Office.Interop.Excel._Worksheet)m_objBook.ActiveSheet;

string strNSDefinition="";
strNSDefinition =
"xmlns:"+xmp.Application.Workbooks[1].XmlNamespaces[1].Prefix+"='"+xmp.Application.Workbooks[1].XmlNamespaces[1].Uri+"'";


Microsoft.Office.Interop.Excel.Range m_objRange =
m_objSheet.get_Range("A1", m_objOpt);
m_objRange.Value2 = "sdf";
m_objRange = m_objSheet.get_Range("B3", m_objOpt);
XPath xp = m_objRange.XPath;// .get_Range("A1", ).XPath;

xp.SetValue(xmp, "/ns1:TTSObjectCreateRequest/ns1:SubmitID",
strNSDefinition, true);



}
catch (Exception e1)
{
MessageBox.Show(e1.Message);

}


in the above code I gets an exception that at

xp.SetValue(xmp, "/ns1:TTSObjectCreateRequest/ns1:SubmitID",
strNSDefinition, true);

exception as

"The XPath is not valid because either the XPath syntax is incorrect or not
supported by Excel"

above code Description:

Book3.xlsx is new excel file. no data is present its for reference.
XOA.xsd is schema with n number of root elements.

In error line the second parameter value (its XPATH)

/ns1:TTSObjectCreateRequest/ns1:SubmitID

where

ns1 is prefix
TTSObjectCreateRequest is root elemnt
SubmitID is element

even i change the XPath with different types its not working.

hope u have and idea!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top