0

i am exporting excel by transform xml,xslt into xls. Below is my coding :

 ds.WriteXml(MyXmlPath);

  XPathDocument xmlDoc = new XPathDocument(MyXmlPath);
  XslCompiledTransform XSLTransform = new XslCompiledTransform();
  XSLTransform.Load(AppBasePath + @"\Master\XSLT\" + strSelectedXSLT.ToString() + ".xslt");
  XSLTransform.Transform(MyXmlPath, MyExcelPath);

From the above coding i am write xml into disk for the given path by using dataset. And read from the disk path in order to transform xls file.

****PROBLEM : Instead of writing & Reading the xml content , why should i write the xml content into string and convert **BECAUSE ITS TAKE HEAVY TIME TO WRITE EXCEL. so i tried below coding . But its not working . ******

StringWriter sw = new StringWriter();
    ds.WriteXml(sw, XmlWriteMode.IgnoreSchema);
    string xmlcontent = sw.ToString();

XslCompiledTransform XSLTransform = new XslCompiledTransform();
 XSLTransform.Load(AppBasePath + @"\Master\XSLT\" + strSelectedXSLT.ToString() + ".xslt");
 XSLTransform.Transform(xmlcontent, MyExcelPath);

Any suggestions ?

Vicky Siddharth
  • 127
  • 1
  • 3
  • 13
  • "not working" is not helpful to us.. In what way is this not working? Are you getting an exception? On the point about strings, you could use a MemoryStream although I'm not sure that it would make much difference since Transform() will ingest it as text just as it would a string. – Phil Blackburn Jul 05 '16 at 12:25
  • not working means .. it doesn't create excel sheet. – Vicky Siddharth Jul 05 '16 at 14:56

1 Answers1

0

When using Transform(string,string) both of the parameters should be URI. In your first code example you're using a file URI for the BOTH parameters of Transform(). This is correct. For the second example, you have tried to pass in the xml content not a URI as a string for the first parameter. I dont know why you didn't see an exception at this point.

If you want to pass xml content directly into Transform() you will need to use one of other method signatures that accepts an XmlReader or IXPathNavigable for the xml input. However, when using one of these other Transform() signatures, you'll also need to Stream the output to a file or use XmlWriter

Check out this: How to transform XML as a string w/o using files in .NET?

Community
  • 1
  • 1
Phil Blackburn
  • 1,047
  • 1
  • 8
  • 13