看看这段代码也许对你有帮助
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";
}
}
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";
}
}
解决方案 »
- 今天看到一个关于dataGridView1.Controls.Clear的问题,不明白求解
- 程序连接sql server2008的效率问题
- [急]C#如何调用C++的函数,有结构体传递
- 通过月份判断出这月的天数?
- 在C#中,当类作为参数进行传递时,如果参数修改时,一定会修改类成员的值吗?
- js里获得GridView模板列的TextBox做批量增加的问题
- 发布c#游戏-连连看v1.41(修正版)全部源码
- 每个网页上都想要个查询、筛选、打印、下载的功能,请下载指明前进的方面。
- VLC视频流的存储问题?
- 关于C# 学习
- 希望有经验的人来看看,有关remoting代理类的问题。顶者有分!
- 哪有.NET 安装序列号?
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得值
//创建一个数据链接
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" );
}