首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

System.NullReferenceException:Objec reference not set to an instance of an objec

2014-01-28 
using System using System.Collections.Generic using System.Text using System.Windows.Forms using

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++)
{         

热点排行