protected void Button3_Click(object sender, EventArgs e) { ComSqlHelper csh = new ComSqlHelper(); DataTable contentData = csh.Query("SELECT * FROM [Qc_CarRunStatus]", "HRBKY").Tables[0]; contentData.Columns.Remove("CID"); contentData.Columns.Add("StartAddress"); contentData.Columns.Add("EndAddress"); List <CommLibrary.AddressConvert.DLngLat> corrds = new List <AddressConvert.DLngLat>(); for (int i = 0; i < contentData.Rows.Count; i++) { string sc = contentData.Rows[i]["StartCoord"].ToString(); sc = string.IsNullOrEmpty(sc) ? "0-0" : sc; string slng = sc.Split('-')[1]; string slat = sc.Split('-')[0]; string ec = contentData.Rows[i]["EndCoord"].ToString(); ec = string.IsNullOrEmpty(ec) ? "0-0" : ec; string elng = ec.Split('-')[1]; string elat = ec.Split('-')[0]; CommLibrary.AddressConvert.DLngLat sdl = new AddressConvert.DLngLat(); sdl.Lat = double.Parse(slat); sdl.Lng = double.Parse(slng); CommLibrary.AddressConvert.DLngLat edl = new AddressConvert.DLngLat(); edl.Lat = double.Parse(elat); edl.Lng = double.Parse(elng); corrds.Add(sdl); corrds.Add(edl); } string[] address = AddressConvert.AddConvertBatch(corrds); for (int i = 0; i < contentData.Rows.Count; i++) { contentData.Rows[i]["StartAddress"] = address[i * 2]; contentData.Rows[i]["EndAddress"] = address[i * 2 + 1]; } NPOIHelper npoiHelper = new NPOIHelper(); string[] headerDataArray = { "车牌号", "所属企业", "车辆用途", "运营线路", "开始时间", "开始速度", "结束时间", "结束速度", "开始经纬度", "结束经纬度", "开始地址", "结束地址" }; string[][] contentDataArray = npoiHelper.convertDataTableToStringArray(contentData); npoiHelper.WorkbookName = "车辆运行统计" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; // 设置导入内容 npoiHelper.HeaderData = headerDataArray; npoiHelper.ContentData = contentDataArray; string basepath = HttpRuntime.AppDomainAppPath.ToString(); string filePath = @"UI\Excel\Query\"; string sd = basepath + filePath; npoiHelper.saveExcel(sd); }