using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace CangKuGuanli.BLL
{
public class ExportXLS
{
private string tempStr;
private string str;
public void ExportDataGridViewToExcel(DataGridView dataGridview1)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "Execl files (*.xls)|*.xls ";
saveFileDialog.FilterIndex = 0;
saveFileDialog.RestoreDirectory = true;
saveFileDialog.CreatePrompt = false;
saveFileDialog.Title = "导出Excel文件到 ";
if (saveFileDialog.ShowDialog() == DialogResult.Cancel)
return;
Stream myStream = saveFileDialog.OpenFile();
StreamWriter sw = new StreamWriter(myStream,System.Text.Encoding.GetEncoding( "gb2312 ")); //gb2312
try
{
//写标题
for (int i = 0; i < dataGridview1.ColumnCount; i++)
{