日期:2014-05-17 浏览次数:21123 次
private void btnExcel_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt = DBHelper.GetData("SELECT * FROM TBNAME");//此处获取你数据库中数据
if (dt.Rows.Count > 0)
{
SaveFileDialog sd = new SaveFileDialog();
sd.Filter = "(*.xls)
------解决方案--------------------
*.xls";
sd.FilterIndex = 0;
sd.FileName = "filename.xls";
sd.RestoreDirectory = true;
sd.Title = "导出Excel";
if (sd.ShowDialog() == DialogResult.OK)
{
Stream sm;
sm = sd.OpenFile();
StreamWriter sw = new StreamWriter(sm, System.Text.Encoding.GetEncoding(-0));
string columnTitle = "";
try
{
for (int i = 0; i < dt.Columns.Count; i++)
{
if (i > 0)