赞
踩
1、调用
/// <summary>
/// 导出Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonExport_Click(object sender, EventArgs e)
{
ExportToExcel d = new ExportToExcel();
d.OutputAsExcelFile(dataGridView1);
}
2、引用
3。创建类
using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Threading;
using System.Windows.Forms;
using System.Collections.Generic;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
namespace 铸造数据分析与发送系统
{
public class ExportToExcel
{
public Excel.Application m_xlApp = null;
public void OutputAsExcelFile(DataGridView dataGridView)
{
if (dataGridView.Rows.Count <= 0)
{
MessageBox.Show("无数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
}
string filePath = "";
SaveFileDialog s = new SaveFileDialog();
s.Title = "保存Excel文件";
s.Filter = "Excel文件(*.xls)|*.xls";
s.FilterIndex = 1;
if (s.ShowDialog() == Dialog
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。