导出Excel
2015-11-02 16:54:03 访问(2922) 赞(0) 踩(0)
/// <summary>
/// 导出Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton_导出_Click(object sender, EventArgs e)
{
try
{
ExportExcelClick();
}
catch (Exception err)
{
MsgForm.MsgException(err);
}
}
/// <summary>
///
/// </summary>
/// <param name="depList"></param>
/// <param name="theList"></param>
/// <param name="pId"></param>
/// <param name="DepNoLen"></param>
protected void ExportDataBuildList
(
List<VtDepartmentModel> depList,
List<List<string>> theList,
string pId,
int DepNoLen
)
{
if (depList == null
|| depList.Count == 0)
return;
List<string> sonList = null;
foreach (VtDepartmentModel info in depList)
{
if (info.DNo.Length != DepNoLen)
continue;
if (pId.Length != 0)
{
if (!info.DNo.StartsWith(pId))
continue;
}
sonList = new List<string>();
sonList.Add(info.DID.ToString());
sonList.Add(info.DName);
sonList.Add(info.DNo);
sonList.Add(info.EK_EmDepFlagV.ToString());
theList.Add(sonList);
ExportDataBuildList
(
depList,
theList,
info.DNo,
DepNoLen + 3
);
}
}
/// <summary>
///
/// </summary>
protected void ExportExcelClick()
{
SaveFileDialog fd = new SaveFileDialog();
fd.Filter = "xls 文件(*.xls)|*.xls|csv 文件(*.csv)|*.csv";
fd.FileName = this.Text;
if (fd.ShowDialog() != DialogResult.OK)
return;
string fileName = fd.FileName;
ClientUtil cu = ClientUtil.instance;
IAppHelper ah = AppDriver.IAppHelperGet();
List<List<string>> theList
=
new List<List<string>>();
List<string> sonList = new List<string>();
sonList.Add("ID");
sonList.Add("名称");
sonList.Add("编号");
sonList.Add("状态");
theList.Add(sonList);
ExportDataBuildList
(
DepModelList,
theList,
"",
3
);
eKing.GpsApp.Enums.ExportModel.EmExportModel em
=
ah.EmExportModelGet(fileName);
ah.ExportToExcel
(
em,
fileName,
theList
);
cu.MessageBoxShowFileNameOpenYesNo(fileName);
}
标签:
导出Excel 


上一条:
下一条:
相关评论
发表评论