日期:2014-05-18  浏览次数:20363 次

【寻求解决方案】将用户定单详细信息存到服务器的里面,调出打印
每个用户都有一个文件夹,现在需要把数据库里面的很多信息存到一个记事本或者Word文档里面,管理员可以从服务器雕出这个文件夹,然后打印出来;
现在问题是如何用程序生成一个记事本或者Word文件???
或者有更好的解决方案,大家可以告诉我!
拜托了!!

------解决方案--------------------
public static void SqlDataToExcel ( Page page, string strSql, string TableName, string ObjectName, string sqlconn )
{
HttpResponse resp;
string colHeaders = " ", ls_item = " ";
resp = page.Response;
string filename = ObjectName+ ".word ";
resp.ContentEncoding = System.Text.Encoding.GetEncoding ( "GB2312 " );
resp.AppendHeader ( "Content-Disposition ", "attachment;filename= " + System.Web.HttpUtility.UrlEncode(filename,System.Text.Encoding.UTF8));
resp.ContentType = "text/word ";

#region Excel
DataSet ds = new DataSet ( );
SqlDataAdapter Adapter = new SqlDataAdapter ( strSql, sqlconn );
Adapter.Fill ( ds, TableName);
int i, j;
/*定义表对象与行对像,同时用DataSet对其值进行初始化*/
DataTable dt = ds.Tables[ 0 ];
DataRow[ ] myRow = dt.Select ( " " );
/*取得数据表各列标题,各标题之间以\t分割,最后一个列标题后加回车符*/
for (i = 0 ; i < dt.Columns.Count - 1 ; i++)
colHeaders += dt.Columns[ i ].Caption.ToString ( ) + "\t ";
colHeaders += dt.Columns[ i ].Caption.ToString ( ) + "\n ";
/*向HTTP输出流中写入取得的数据信息*/
resp.Write ( colHeaders );
/*逐行处理数据*/
foreach (DataRow row in myRow)
{
//在当前行中,逐列获得数据,数据之间以\t分割,结束时加回车符\n
for (i = 0 ; i < row.Table.Columns.Count - 1 ; i++)
ls_item += row[ i ].ToString ( ) + "\t ";
ls_item += row[ i ].ToString ( ) + "\n ";
/*当前行数据写入HTTP输出流,并且置空ls_item以便下行数据*/
resp.Write ( ls_item );
ls_item = " ";
}
#endregion
resp.Flush ( );
resp.End ( );
}
------解决方案--------------------
/// <summary>
/// SmartGridView类的属性部分
/// </summary>
public partial class SmartGridView
{
/// <summary>
/// 导出SmartGridView的数据源的数据
/// </summary>
/// <param name= "fileName "> 文件名 </param>
/// <param name= "exportFormat "> 导出文件的格式 </param>
/// <param name= "encoding "> 编码 </param>
public void Export(string fileName, ExportFormat exportFormat, Encoding encoding)
{
DataTable dt = null;

if (this._dataSourceObject is DataTable)
dt = (DataTable)this._dataSourceObject;
else if (this._dataSourceObject is DataSet)
dt = ((DataSet)this._dataSourceObject).Tables[0];
else
throw new InvalidCastException( "若要导出SmartGridView,应保证其数据源为DataTable或DataSet类型 ");

if (dt == null)
throw new ArgumentNullException( "数据源 ", "数据源不能为NULL ");

Helper.Common.Export(dt, exportFormat, fileName, encoding);
}

/// <summary>
/// 导出SmartGridView的数据源的数据
/// </summary>
/// <param name= "fileName "> 文件名 </param>
/// <param name= "exportFormat "> 导出文件的格式 </param>
public void Export(string fileName, ExportFormat expo