看看这段代码也许对你有帮助
xmlDoc.Load(xslFileStream);

XmlNodeList SpanNodes = xmlDoc.SelectNodes("//span[attribute::class='xdTextBox']");
for (i = 0; i <=SpanNodes.Count -1 ; i++)
{
//表示当前节点的类型是文本框的时候

strSpan = SpanNodes.Item(i).ParentNode.InnerXml; //节点本身所包括的XML代码
strSpan = strSpan.Replace("span","input");//将本身代码中包括span字符串替换成input
int Pos = strSpan.IndexOf("<xsl:",1);
strSpan = strSpan.Insert(Pos,strSAttribute);
Pos =strSpan.IndexOf("</input>",1);
strSpan = strSpan.Insert(Pos,strEAttribute);
SpanNodes.Item(i).ParentNode.InnerXml =strSpan;
} SpanNodes = xmlDoc.SelectNodes("//head");
XmlNode scriptNode = xmlDoc.CreateNode(XmlNodeType.Element,"script","");
XmlNode scriptAttribute = xmlDoc.CreateNode(XmlNodeType.Attribute, "src", "");
scriptAttribute.Value ="script.js";
scriptNode.InnerText =" ";
scriptNode.Attributes.SetNamedItem(scriptAttribute);
SpanNodes.Item(0).AppendChild(scriptNode); SpanNodes =xmlDoc.SelectNodes("//button/img");//替换日历控件上的图片
for ( i = 0; i <=SpanNodes.Count -1 ; i++)
{
if (SpanNodes.Item(i).Attributes.Item(0).Value =="res://infopath.exe/calendar.gif")
{
SpanNodes.Item(i).Attributes.Item(0).Value = "images/calendar.gif";
}
}

解决方案 »

  1.   

    这一段是读xml的吧,我是想读excel文件。对不起我不太懂,请明示,谢谢
      

  2.   

    Excel.ApplicationClass excel = new ApplicationClass();
    excel.Application.Workbooks.Add(true);
    excel.Visible = false;
    string ExcelFile ="D:\\111.xls";
    object missing = System.Reflection.Missing.Value;
    excel.Workbooks.Open(ExcelFile, missing, missing, missing, missing, missing, missing, missing,
    missing, missing, missing, missing, missing); this.textBox1.Text = ((System.Object)(((Excel.Range)(((Excel.Range)(excel.ActiveCell)).Cells)).FormulaR1C1Local)).ToString();
    //FormulaR1C1Local
    //row1col1得值
      

  3.   

    有两种方式:将*.xls作为数据源操作,另一种就是直接对*.xls文件操作
      

  4.   

    方式一、
    //创建一个数据链接
    string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = c:\\sample.xls;Extended Properties=Excel 8.0" ;
    OleDbConnection myConn = new OleDbConnection ( strCon ) ;
    string strCom = " SELECT * FROM [Sheet1$] " ;
    myConn.Open ( ) ;
    //打开数据链接,得到一个数据集
    OleDbDataAdapter myCommand = new OleDbDataAdapter ( strCom , myConn ) ;
    //创建一个 DataSet对象
    myDataSet = new DataSet ( ) ;
    //得到自己的DataSet对象
    myCommand.Fill ( myDataSet , "[Sheet1$]" ) ;
    //关闭此数据链接
    myConn.Close ( ) ;方式二、
    Excel.Application oXL;
    Excel._Workbook oWB;
    Excel._Worksheet oSheet;
    Excel.Range oRng; try
    {
    //Start Excel and get Application object.
    oXL = new Excel.Application();
    oXL.Visible = true; //Get a new workbook.
    oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));
    oSheet = (Excel._Worksheet)oWB.ActiveSheet; //Add table headers going cell by cell.
    oSheet.Cells[1, 1] = "First Name";
    oSheet.Cells[1, 2] = "Last Name";
    oSheet.Cells[1, 3] = "Full Name";
    oSheet.Cells[1, 4] = "Salary"; //Format A1:D1 as bold, vertical alignment = center.
    oSheet.get_Range("A1", "D1").Font.Bold = true;
    oSheet.get_Range("A1", "D1").VerticalAlignment = 
    Excel.XlVAlign.xlVAlignCenter;

    // Create an array to multiple values at once.
    string[,] saNames = new string[5,2];

    saNames[ 0, 0] = "John";
    saNames[ 0, 1] = "Smith";
    saNames[ 1, 0] = "Tom";
    saNames[ 1, 1] = "Brown";
    saNames[ 2, 0] = "Sue";
    saNames[ 2, 1] = "Thomas";
    saNames[ 3, 0] = "Jane";
    saNames[ 3, 1] = "Jones";
    saNames[ 4, 0] = "Adam";
    saNames[ 4, 1] = "Johnson";         //Fill A2:B6 with an array of values (First and Last Names).
            oSheet.get_Range("A2", "B6").Value2 = saNames; //Fill C2:C6 with a relative formula (=A2 & " " & B2).
    oRng = oSheet.get_Range("C2", "C6");
    oRng.Formula = "=A2 & \" \" & B2"; //Fill D2:D6 with a formula(=RAND()*100000) and apply format.
    oRng = oSheet.get_Range("D2", "D6");
    oRng.Formula = "=RAND()*100000";
    oRng.NumberFormat = "$0.00"; //AutoFit columns A:D.
    oRng = oSheet.get_Range("A1", "D1");
    oRng.EntireColumn.AutoFit(); //Manipulate a variable number of columns for Quarterly Sales Data.
    DisplayQuarterlySales(oSheet); //Make sure Excel is visible and give the user control
    //of Microsoft Excel's lifetime.
    oXL.Visible = true;
    oXL.UserControl = true;
    }
    catch( Exception theException ) 
    {
    String errorMessage;
    errorMessage = "Error: ";
    errorMessage = String.Concat( errorMessage, theException.Message );
    errorMessage = String.Concat( errorMessage, " Line: " );
    errorMessage = String.Concat( errorMessage, theException.Source ); MessageBox.Show( errorMessage, "Error" );
    }
      

  5.   

    请问Excel在哪个包里面?using System.什么?
      

  6.   

    还有如果将*.xls作为数据源操作,那么读出的xls文件中的内容在DataSet中是如何存放的?