NPOI大数据分批写入同个Excel (四)

2014-11-23 22:04:27 ? 作者: ? 浏览: 19
umnName);
}
}

for (int i = 0; i < dt.Rows.Count; i++)
{
rowIndex++;
DataRow dr = dt.Rows[i];
IRow row = sheet.CreateRow(rowIndex);
for (int j = 0; j < columnsCount; j++)
{
row.CreateCell(j).SetCellValue(dr[j].ToString());
}

lblMsg.SafeCall(() =>
{
if(i == (dt.Rows.Count - 1))
txtSql.AppendText(" 行数:" + (i+1).ToString() + "\r\n");
lblMsg.Text = string.Format("正在导出第{0}个条件,第{1}行", sqlIndex.ToString(), (i + 1).ToString());
double x = rowIndex * 1.0 / recordCount * 100;
lblProgress.Text = string.Format("总行数:{0}, 当前完成总{1}行,百分占比:{2} %", recordCount.ToString(), rowIndex.ToString(), x.ToString("#0.0"));
});
}
FileStream outFs = new FileStream(fileName, FileMode.Open);
workbook.Write(outFs);
outFs.Close();
}
}).ContinueWith(TaskEnded);
}
catch (Exception ex)
{
MessageBox.Show("发生异常,错误提示:" + ex.Message);
}
}
private void TaskEnded(Task task)
{
txtSql.SafeCall(() =>
{
lblMsg.Text = "全部导出完成!";
txtSql.AppendText("处理完成!\r\n");
});
}
Extensions.cs


[csharp] view plaincopyprint
public static class Extensions
{
public static void SafeCall(this Control ctrl, Action callback)
{
if (ctrl.InvokeRequired)
ctrl.Invoke(callback);
else
callback();
}
public static void BindComboBox(this ComboBox cb, List list)
{
cb.DisplayMember = "Value";
cb.ValueMember = "Key";
cb.DataSource = list;
}
}

public static class Extensions
{
public static void SafeCall(this Control ctrl, Action callback)
{
if (ctrl.InvokeRequired)
ctrl.Invoke(callback);
else
callback();
}
public static void BindComboBox(this ComboBox cb, List list)
{
cb.DisplayMember = "Value";
cb.ValueMember = "Key";
cb.DataSource = list;
}
}Sql.cs


[csharp] view plaincopyprint
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataExport
{
public enum BusinessType
{
XA = 1,
XB = 2
}

public class Sql
{
///


/// 分批获取sql的where条件
///

public static string[] SqlWhereArray = {
" 条件1 ",
" 条件2 ",
" 条件3 "
};

///
/// sql的where条件说明
///

public static string[] DateRemarkArray = {
"20130101至20130331",
"20130401至20130630",
"20130701后",
};

///
/// 获取sql语句
///

///
///
///
///
private static string GetSql(BusinessType type, string columns, string sqlWhere)
{
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: