当前位置:首页 > asp.net从数据库导出数据到word、excel、txt文本文件

asp.net从数据库导出数据到word、excel、txt文本文件

点击次数:1056  更新日期:2010-12-27
\n

using System;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using Excel;
using Word;
using System.IO;
namespace Common
{
/// <summary>
/// 把数据导入到.doc、.txt、.xls文件中
/// </summary>
public class Export
{
private const string DATAWORDPATH = @”C:\\folder\\doc\\datadoc\\”;
private const string IMAGEWORDPATH = @”C:\\folder\\doc\\imagedoc\\”;
private const string IMAGEPATH = @”C:\\folder\\image\\”;
private const string EXCELPATH = @”C:\\folder\\excel\\”;
private const string TXTPATH = @”C:\\folder\\txt\\”;
private const string IMAGEPOSTFIX = “.bmp”;
private const string WORDPOSTFIX = “.doc”;
private const string EXCELPOSTFIX = “.xls”;
private const string TXTPOSTFIX = “.txt”;
private const int DATADISTANCE = 5;
private const int TABDISTANCE = 8;

public Export()
{
//
// TOD 在此处添加构造函数逻辑
//
}
/// <summary>
/// 获得数据集Dataset——————————–用于调试
/// </summary>
/// <returns>Dataset</returns>
public DataSet GetData()
{
try
{
string sConnectionString;
sConnectionString = “workstation id=GUOFU;packet size=4096;user id=sa;data source=GUOFU;persist security info=True;initial catalog=YC;password=sc”;
SqlConnection objConn = new SqlConnection(sConnectionString);
objConn.Open();
SqlDataAdapter daPoint = new SqlDataAdapter(“Select * From Point”, objConn);
DataSet dsYC = new DataSet(“YC”);
daPoint.FillSchema(dsYC,SchemaType.Mapped, “Point”);
daPoint.Fill(dsYC,”Point”);
daPoint = new SqlDataAdapter(“Select * From Employee”, objConn);
daPoint.FillSchema(dsYC,SchemaType.Mapped, “Employee”);
daPoint.Fill(dsYC,”Employee”);
return dsYC;
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}

}

\n