导出EXCEL
来源:互联网 发布:如何注册域名 虚拟主机 编辑:程序博客网 时间:2024/06/05 20:47
private void tbExportExcel_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = true;
saveFileDialog.Title = "导出Excel文件到";
saveFileDialog.FileName = "*.xls";
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
{
return;
}
Stream myStream;
myStream = saveFileDialog.OpenFile();
StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding("gb2312"));
string str = "";
//写标题
for (int i = 0; i < dataGridView1.ColumnCount; i++)
{
if (dataGridView1.Columns[i].Visible == true)
{
str += dataGridView1.Columns[i].HeaderText + "\t";
}
}
sw.WriteLine(str);
//写内容
for (int j = 0; j < dataGridView1.Rows.Count; j++)
{
string tempStr = "";
for (int k = 0; k < dataGridView1.Columns.Count; k++)
{
if (dataGridView1.Rows[j].Cells[k].Visible == true)
{
string value = "";
if (dataGridView1.Rows[j].Cells[k].Value != null)
{
value = dataGridView1.Rows[j].Cells[k].Value.ToString() + "\t";
}
tempStr += value;
}
}
sw.WriteLine(tempStr);
}
sw.Close();
myStream.Close();
MessageBox.Show("导出成功");
}
catch (Exception ex)
{
throw ex;
}
}
- 导出EXCEL
- Excel导出
- 导出Excel
- 导出EXCEL
- 导出Excel
- EXCEL导出
- 导出Excel
- 导出excel
- 导出excel
- EXCEL导出
- 导出excel
- 导出Excel
- Excel导出。
- 导出excel
- Excel 导出
- 导出excel
- 导出excel
- 导出excel
- 数据类型/对象类型介绍(2)UINavigationController
- Copy Constructor and operator=
- sql server 2005 优化策略集合
- GXT之旅:第九章:Charts图表——BarChart(2)
- SQL语句复制表的方法
- 导出EXCEL
- php-Arrays 函数-array_flip-交换数组中键和值
- Linux下分区详解之—Parted
- 怎么让程序员觉得没有压力
- JTable常见用法细则
- volatile 与内存屏障
- UIAPPLICATIONDELEGATE 代理函数调用的时间(应用程序生命周期)
- response.queryString的简单用法
- windows server 2003 远程桌面最大连接数调整