菜鸟 100分 求帮忙
用ASP 将数据库(sql access 都行)信息导入到word比如:数据库里面有个uesname字段
页面上有一个按钮 点击 就开始导入
word里面就有 该字段下面的用户姓名
求详细代码 --------------------编程问答-------------------- 你这个我觉得直接用word 的宏就完了
里面的VBA语法跟asp也差不多
asp操作word感觉不靠谱。。
下面是我们从Oracle取数的函数,sql 或者access只是连接字串不同
Public Function GetTableFieldData(sMostID As String, sTableName As String, sFieldName As String)
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sprojid As String
On Error GoTo errHandle
cn.Open "Provider=OraOLEDB.Oracle.1;Password=*;Persist Security Info=True;User ID=*;Data Source=*"
Set rs.ActiveConnection = cn
sSQL = "select * from tProjInfo where sMostID='" & sMostID & "'"
rs.CursorLocation = adUseClient
rs.LockType = adLockOptimistic
rs.Open sSQL
If rs.EOF Then
GetTableFieldData = ""
Exit Function
End If
If rs.RecordCount > 1 Then
GetTableFieldData = "Too many rows..."
Exit Function
End If
sprojid = rs.Fields("sProjID")
sSQL = "select " & sFieldName & " from " & sTableName & " where sProjID='" & sprojid & "'"
If rs.State = 1 Then rs.Close
rs.Open sSQL
If rs.EOF Then
GetTableFieldData = "No data returned"
Else
GetTableFieldData = rs.Fields(sFieldName)
End If
cn.Close
Set rs = Nothing
Set cn = Nothing
Exit Function
errHandle:
MsgBox Err.Description
End Function --------------------编程问答--------------------
只需要asp的 - - --------------------编程问答-------------------- 这就不是ASP的地盘么,你在这问,有几人知道噢。
换去WEB开发版-ASP吧。 --------------------编程问答--------------------
/// <summary>
/// 将Web控件导出
/// </summary>
/// <param name="source">控件实例</param>
/// <param name="type">类型:Excel或Word</param>
public void ExpertControl(System.Web.UI.Control source, DocumentType type)
{
//设置Http的头信息,编码格式
if (type == DocumentType.Excel)
{
//Excel
Response.AppendHeader("Content-Disposition","attachment;filename=result.xls");
Response.ContentType = "application/ms-excel";
}
else if (type == DocumentType.Word)
{
//Word
Response.AppendHeader("Content-Disposition","attachment;filename=result.doc");
Response.ContentType = "application/ms-word";
}
Response.Charset = "UTF-8";
Response.ContentEncoding = System.Text.Encoding.UTF8;
//关闭控件的视图状态
source.Page.EnableViewState =false;
//初始化HtmlWriter
System.IO.StringWriter writer = new System.IO.StringWriter() ;
System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(writer);
source.RenderControl(htmlWriter);
//输出
Response.Write(writer.ToString());
Response.End();
}
//文档类型
public enum DocumentType
{
Word,
Excel
}
参考
另外 你把数据取出来 存入DataSet也可以
用下面方法导出
--------------------编程问答-------------------- --------------------编程问答-------------------- Wxr0323代码贴出来,顶一个。 --------------------编程问答-------------------- 你这100分要浪费了, 主要是你方向都没搞正确,你发到asp.net 的地盘来了。 --------------------编程问答-------------------- asp里面可以考虑在js里面用activex来做
/// <summary>
/// 导出Excel
/// </summary>
/// <param name="ds">Dataset</param>
/// <param name="FileName">文件名,包括后缀。如:xxx.xls</param>
public void CreateExcel(DataSet ds, string FileName)
{
HttpResponse resp;
resp = Page.Response;
FileName = Page.Server.UrlEncode(FileName); //文件名编码,否则出现乱码
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
string colHeaders = "", ls_item = "";
//定义表对象与行对象,同时用DataSet对其值进行初始化
DataTable dt = ds.Tables[0];
DataRow[] myRow = dt.Select();//可以类似dt.Select("id>10")之形式达到数据筛选目的
int i = 0;
int cl = dt.Columns.Count;
//取得数据表各列标题,各标题之间以t分割,最后一个列标题后加回车符
colHeaders = "姓名\t性别\n";
resp.Write(colHeaders);
//向HTTP输出流中写入取得的数据信息
//逐行处理数据
foreach (DataRow row in myRow)
{
//当前行数据写入HTTP输出流,并且置空ls_item以便下行数据
ls_item += row["Uname"].ToString() + "\t" + row["U易做图"].ToString() + "\n";
resp.Write(ls_item);
ls_item = "";
}
resp.End();
}
补充:.NET技术 , ASP.NET