/// <summary> /// 导出测点列表表格 /// </summary> [HttpGet] [AllowAnonymous] public void ExportMeasurePointData(string TreeID, string TreeType) { DataTable dtResult = new DataTable(); DataTable dtExcel = new DataTable(); try { string sql = string.Format("EXEC P_GET_ZXJG_TagList '{0}','{1}'", TreeID, TreeType); dtResult = QuerySQL.GetDataTable(sql); dtExcel = dtResult.Copy(); dtExcel.Columns.Add("xuhao", typeof(string)); dtExcel.Columns.Add("StrValueTime", typeof(string)); dtExcel.Columns["xuhao"].SetOrdinal(0); dtExcel.Columns["StrValueTime"].SetOrdinal(2); for (int i = 0; i < dtResult.Rows.Count; i++) { dtExcel.Rows[i]["xuhao"] = (i + 1).ToString(); dtExcel.Rows[i]["StrValueTime"] = Convert.ToDateTime(dtResult.Rows[i]["F_ValueTime"]).ToString("yyyy-MM-dd HH:mm:ss"); } List<NPOIModel> list = new List<NPOIModel>(); list.Add(new NPOIModel(dtExcel, "xuhao;F_Description;StrValueTime;F_Value;F_Unit;F_AlmLow;F_AlmUp", "sheet", "序号#监测点#采集时间#当前数值#工程单位#报警下限#报警上限")); ATNPOIHelper.Export("测点列表", list, 0); } catch (Exception ex) { } }
asp.net 利用NPOI导出Excel通用类的方法(2)
内容版权声明:除非注明,否则皆为本站原创文章。