0

我编写了一个测试代码,它从 XML 文件 (Data.xml) 读取数据并使用 XSLT 文件 (XSLTFile1.xslt) 过滤掉所需的记录并相应地对其进行格式化。此输出保存在另一个 output.xml 文件中。到目前为止,它工作正常。现在我想要的是在 excel 表中按原样显示这个输出。到目前为止,我能够将这些数据作为一个整体转储到 Excel 工作表中,但我想指定一些约束: • 我希望如果我有红色输​​出,则 Excel 单元格颜色也应该是红色的。• 我想指定一个像 G12 或 (12:7) 这样的单元格位置,我想在其中显示该数据。

DataSet dataSet = new DataSet();
dataSet.ReadXml("Data.xml");

System.IO.FileStream fs = new System.IO.FileStream(
"Customers.htm", System.IO.FileMode.Create);

//Create an XmlTextWriter for the FileStream.
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(
fs, System.Text.Encoding.Unicode);

//Transform the XML using the stylesheet.
XmlDataDocument xmlDoc = new XmlDataDocument(dataSet);
System.Xml.Xsl.XslTransform xslTran = new System.Xml.Xsl.XslTransform();
xslTran.Load("XSLTFile1.xslt");
xslTran.Transform(xmlDoc, null, xtw);

//Open the HTML file in Excel.
Microsoft.Office.Interop.Excel.Application oExcel = Globals.ThisAddIn.Application;
oExcel.Visible = true;
oExcel.UserControl = true;
Workbooks oBooks = oExcel.Workbooks;
object oOpt = System.Reflection.Missing.Value;
oBooks.Open("customers.htm", oOpt, oOpt, oOpt,
oOpt, oOpt, oOpt, oOpt, oOpt, oOpt, oOpt, oOpt,
oOpt, oOpt, oOpt);

输出文件数据:

4

0 回答 0