C#WinForm怎样导出EXCEL,要求一定的格式
C#WinForm怎样导出EXCEL,我已经导出数据了,后面的格式我不知道怎么做。
比如数据从第几行开始导入;那位任兄知道,小弟在此谢谢了, 下面是我的代码:有不妥的地方请说一下,谢谢
using System.Data.OleDb;
//using Microsoft.Office.Interop.Excel;
using System.IO;
using System.Reflection;
namespace test0608
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string strcon = @" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\db1.mdb";
OleDbConnection cn = new OleDbConnection(strcon);
OleDbDataAdapter da = new OleDbDataAdapter("select * from liu", cn);
DataSet ds = new DataSet();
da.Fill(ds, "liu");
System.Data.DataTable dt = ds.Tables["liu"];
ExportToExcel(dt);
System.Windows.Forms.Application.Exit();
}
private void ExportToExcel(DataTable dataTable)
{
SaveFileDialog _saveFileDialog = new SaveFileDialog();
_saveFileDialog.Filter = "Microsoft Excel (*xls)|*.xls";
_saveFileDialog.Title = "输出统计结果";
if (MessageBox.Show("需要保存文件吗?", "提示框", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
if (_saveFileDialog.ShowDialog() == DialogResult.OK)
{
Stream _stream = _saveFileDialog.OpenFile();
StreamWriter _streamWriter = new StreamWriter(_stream, Encoding.GetEncoding("GB2312"));
string _columnName