问题描述
用Excel怎么生成Xml文件?小弟这有礼了,在线等,急,急,急。。。。
解决方案
解决方案二:
把xml看作一个数据源就行了
解决方案三:
stringsql="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\loglist.xls;ExtendedProperties="Excel8.0"";OleDbConnectionconn=newOleDbConnection(sql);OleDbCommandcmd=newOleDbCommand("select*fromloglist",conn);OleDbDataAdapterda=newOleDbDataAdapter(cmd);//读取Excel表格DataSetds=newDataSet();da.Fill(ds);ds.WriteXML();这个方法
解决方案四:
///<summary>///把Excel文档转换为Xml文档///</summary>///<paramname="excelPath"></param>///<paramname="xmlPath"></param>publicvoidchangeExcelToXml(stringexcelPath,stringxmlPath){ObjectNothing=System.Reflection.Missing.Value;ApplicationClassexcelApp;WorkbookexcelBook;excelApp=newApplicationClass();excelApp.Visible=false;excelApp.DisplayAlerts=false;excelApp.AlertBeforeOverwriting=false;excelApp.AskToUpdateLinks=false;//try{excelBook=excelApp.Workbooks.Open(excelPath,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing);excelBook.SaveAs(xmlPath,XlFileFormat.xlXMLSpreadsheet,Nothing,Nothing,Nothing,Nothing,XlSaveAsAccessMode.xlNoChange,Nothing,Nothing,Nothing,Nothing,Nothing);}finally{//closeif(excelBook!=null){excelBook.Close(Nothing,Nothing,Nothing);System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook);excelBook=null;}if(excelApp!=null){excelApp.Application.Quit();System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);excelApp=null;}GC.Collect();GC.WaitForPendingFinalizers();}}
解决方案五:
stringsql="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\loglist.xls;ExtendedProperties="Excel8.0"";这句话压根就能用呀
解决方案六:
就有能用,打错了
解决方案七:
超完整,刚刚做完,调试好.你看看.<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title>UntitledPage</title></head><body><formid="form1"runat="server"><div></div></form></body></html>
usingSystem;usingSystem.Data;usingSystem.Data.OleDb;usingSystem.Data.SqlClient;usingSystem.Configuration;usingSystem.Web;usingSystem.Web.Security;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingSystem.Web.UI.WebControls.WebParts;usingSystem.Web.UI.HtmlControls;publicpartialclass_Default:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){getDate();getXml();}publicDataSetgetDate(){stringsql="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=D:\sample.xls;ExtendedProperties="Excel8.0"";OleDbConnectionconn=newOleDbConnection(sql);OleDbCommandcmd=newOleDbCommand("select*from[Sheet1$]",conn);//工作表名就是Excel显示区下面的工作区名OleDbDataAdapterda=newOleDbDataAdapter(cmd);//读取Excel表格DataSetds=newDataSet();da.Fill(ds);returnds;}publicvoidgetXml(){DataSetds=newDataSet();ds.ReadXml(Server.MapPath("test.xml"));DataTabledt1=ds.Tables[0];DataTabledt2=getDate().Tables[0];for(inti=0;i<dt2.Rows.Count;i++){DataRowdr=dt1.NewRow();dr[0]=dt2.Rows[i][0];dr[1]=dt2.Rows[i][1].ToString();dt1.Rows.Add(dr);}ds.WriteXml(Server.MapPath("test.xml"));}}
test.xml<?xmlversion="1.0"standalone="yes"?><test><t><a>1</a><b>2</b></t><t><a>2</a><b>b</b></t><t><a>3</a><b>c</b></t><t><a>4</a><b>d</b></t><t><a>5</a><b>e</b></t></test>
sample.xls文件内容1a2b3c4d5e
解决方案八:
protectedvoidPage_Load(objectsender,EventArgse){//getDate();没有用,调试时用了.忘记删除了.getXml();}