高分询问 对excel的操作 详细方法? 我有,最近做了n表excel報表。你分都果給我呀給我發信[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://expert.csdn.net/Expert/topic/1454/1454452.xml?temp=.4400293 DataSet ds = new DataSet(); string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Book1.xls;Extended Properties=\"Excel 8.0;\""; OleDbConnection myConnection = new OleDbConnection(conn); string sql = "select * from [Sheet1$]"; OleDbCommand myCommand = new OleDbCommand(sql,myConnection); OleDbDataAdapter da = new OleDbDataAdapter(myCommand); da.Fill(ds); ListDataGrid.DataSource = ds; ListDataGrid.DataBind();我用上面的方法打开了一个excel问:可以直接打开服务器端的吗?问:怎么在datagrid上修改后改变原来的文件问:怎么把改过的文件也保存到服务端? 公司改变了做法,问:我怎么把数据库的数据,表现在excel上 <%@ Language=VBScript %><%Response.Buffer = TrueResponse.ContentType = "application/vnd.ms-excel"%><table border="2" cellpadding="20"> <tr> <th>项目 A</th> <th>项目 B</th> <th>总计</th> </tr> <tr> <td>4</td> <td>3</td> <td><font color="red">=sum(a2:b2)</font></td> </tr> <tr> <td>2</td> <td>1</td> <td><font color="red">=sum(a3:b3)</font></td> </tr></table> 给你一个方法。/// <summary>/// <author>bruce.pu</author>/// 要使用此方法,请先加入microsoft Office Web Component。/// 具体实现可以参照例子wms/vas/// </summary>/// <param name="mdv">主表数据</param>/// <param name="mstTableHead">主表头</param>/// <param name="mstCol">主表列名</param>/// <param name="dt">子表数据</param>/// <param name="tableHead">子表头</param>/// <param name="col">子表列</param>/// <param name="pathAndFileName">文件路径名,例如"d:\\test"请注意格式</param>/// <returns></returns> public static string WriteDataGrid2Excel(DataView mdv,ArrayList mstTableHead,ArrayList mstCol,DataView dt,ArrayList tableHead,ArrayList col,string pathAndFileName) { try { SpreadsheetClass xlsheet = new SpreadsheetClass(); int mstrowCount=0; /////////////主表信息 if(mdv.Table.Rows.Count!=0) { for(int msthead=0;msthead<mstTableHead.Count;msthead++) { xlsheet.ActiveSheet.Cells[1,msthead+1]=mstTableHead[msthead];// xlsheet.ActiveSheet.Cells[ 1,msthead+1].Color = "#ff0011"; } mstrowCount+=1; for(int mstContent=0;mstContent<(mdv.Table.Rows.Count);mstContent++) { DataRow mrw = mdv.Table.Rows[mstContent]; for(int mstCellCount=0;mstCellCount<mstCol.Count;mstCellCount++) { string mstCellContent=mrw[mstCol[mstCellCount].ToString()].ToString(); if(mstCellContent==" ") xlsheet.ActiveSheet.Cells[mstContent+mstrowCount+1,mstCellCount+1]=""; else xlsheet.ActiveSheet.Cells[mstContent+mstrowCount+1,mstCellCount+1]=mstCellContent; } } mstrowCount+=mdv.Table.Rows.Count; } //////////////子表信息 int i; for (int j=0;j<tableHead.Count;j++) { xlsheet.ActiveSheet.Cells[mstrowCount+1,j+1]=tableHead[j]; } for(i=0;i<dt.Table.Rows.Count;i++)//行 { DataRow rw = dt.Table.Rows[i]; for (int j=0;j<col.Count;j++) //列 { string cell=rw[col[j].ToString()].ToString(); if(cell==" ") xlsheet.ActiveSheet.Cells[mstrowCount+i+2,j+1] = ""; else xlsheet.ActiveSheet.Cells[mstrowCount+i+2,j+1] =cell; } } xlsheet.ActiveSheet.Export(pathAndFileName,OWC.SheetExportActionEnum.ssExportActionNone); return "true"; } catch(Exception ee) { return ee.Message.ToString(); } } http://www.csdn.net/Develop/read_article.asp?id=15544http://www.csdn.net/Subject/15/index.shtmhttp://www.linkmeng.com/article/listart.asp?artid=100 it's to hard to "保存到服务器数据库" , 除非自己写 VBA or Excel Application. 从表中取数据填充到DropDownList中,同时想可以在此基础上修改... 关于iframe取值问题 gv翻页 求教:ASP.NET 如何实现这样的爬虫程序(可能有些难度)? 如何让单选类表可以取消? 关于上传的问题 我都觉得自己太菜了 初学ADO 大家看看,FindControls为什么用数据绑定就不成了? 是程序员就进来看看! Page.MapPath和Server.MapPath ? 有一个Web User Control,我想在某aspx页面里动态生成多个这样的Web User Control,怎么办?
string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Book1.xls;Extended Properties=\"Excel 8.0;\"";
OleDbConnection myConnection = new OleDbConnection(conn);
string sql = "select * from [Sheet1$]";
OleDbCommand myCommand = new OleDbCommand(sql,myConnection);
OleDbDataAdapter da = new OleDbDataAdapter(myCommand);
da.Fill(ds);
ListDataGrid.DataSource = ds;
ListDataGrid.DataBind();
我用上面的方法打开了一个excel
问:可以直接打开服务器端的吗?
问:怎么在datagrid上修改后改变原来的文件
问:怎么把改过的文件也保存到服务端?
<%
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
%>
<table border="2" cellpadding="20">
<tr>
<th>项目 A</th>
<th>项目 B</th>
<th>总计</th>
</tr>
<tr>
<td>4</td>
<td>3</td>
<td><font color="red">=sum(a2:b2)</font></td>
</tr>
<tr>
<td>2</td>
<td>1</td>
<td><font color="red">=sum(a3:b3)</font></td>
</tr>
</table>
/// <summary>
/// <author>bruce.pu</author>
/// 要使用此方法,请先加入microsoft Office Web Component。
/// 具体实现可以参照例子wms/vas
/// </summary>
/// <param name="mdv">主表数据</param>
/// <param name="mstTableHead">主表头</param>
/// <param name="mstCol">主表列名</param>
/// <param name="dt">子表数据</param>
/// <param name="tableHead">子表头</param>
/// <param name="col">子表列</param>
/// <param name="pathAndFileName">文件路径名,例如"d:\\test"请注意格式</param>
/// <returns></returns>
public static string WriteDataGrid2Excel(DataView mdv,ArrayList mstTableHead,ArrayList mstCol,DataView dt,ArrayList tableHead,ArrayList col,string pathAndFileName)
{
try
{
SpreadsheetClass xlsheet = new SpreadsheetClass();
int mstrowCount=0;
/////////////主表信息
if(mdv.Table.Rows.Count!=0)
{
for(int msthead=0;msthead<mstTableHead.Count;msthead++)
{
xlsheet.ActiveSheet.Cells[1,msthead+1]=mstTableHead[msthead];
// xlsheet.ActiveSheet.Cells[ 1,msthead+1].Color = "#ff0011";
}
mstrowCount+=1;
for(int mstContent=0;mstContent<(mdv.Table.Rows.Count);mstContent++)
{
DataRow mrw = mdv.Table.Rows[mstContent];
for(int mstCellCount=0;mstCellCount<mstCol.Count;mstCellCount++)
{
string mstCellContent=mrw[mstCol[mstCellCount].ToString()].ToString();
if(mstCellContent==" ")
xlsheet.ActiveSheet.Cells[mstContent+mstrowCount+1,mstCellCount+1]="";
else
xlsheet.ActiveSheet.Cells[mstContent+mstrowCount+1,mstCellCount+1]=mstCellContent;
}
}
mstrowCount+=mdv.Table.Rows.Count;
}
//////////////子表信息
int i;
for (int j=0;j<tableHead.Count;j++)
{
xlsheet.ActiveSheet.Cells[mstrowCount+1,j+1]=tableHead[j];
}
for(i=0;i<dt.Table.Rows.Count;i++)//行
{
DataRow rw = dt.Table.Rows[i];
for (int j=0;j<col.Count;j++) //列
{
string cell=rw[col[j].ToString()].ToString();
if(cell==" ")
xlsheet.ActiveSheet.Cells[mstrowCount+i+2,j+1] = "";
else xlsheet.ActiveSheet.Cells[mstrowCount+i+2,j+1] =cell;
}
}
xlsheet.ActiveSheet.Export(pathAndFileName,OWC.SheetExportActionEnum.ssExportActionNone);
return "true";
}
catch(Exception ee)
{
return ee.Message.ToString();
}
}
http://www.csdn.net/Subject/15/index.shtm
http://www.linkmeng.com/article/listart.asp?artid=100