/// <summary> /// 将表格生成excel /// </summary> /// <param name="dt"></param> private static void CreateExcelSheet(FX.Data.DataTable dt) { Microsoft.Office.Interop.Excel.Application app = new Application(); app.Visible = false; Workbook book = app.Workbooks.Add(Type.Missing); //Worksheet sheet = (Worksheet)(book.Sheets[1]); //生成字段 for (int i = 0; i < dt.Columns.Count; i++) { app.Cells[1, i + 1] = dt.Columns[i].Caption; } //填充数据 for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { app.Cells[i + 2, j + 1] = dt.Rows[i].Cells[dt.Columns[j].ColumnName].ToString(); } } book.SaveAs("E:\\output.xls"); app.Quit(); //app.SaveWorkspace("E:\\output.xls"); }
static void Main(string[] args) { DataQueryServiceClient client = new DataQueryServiceClient(); string pois = ""; //string pois = client.GetHotPoi(); //119410000001 //自行车 // string pois = client.GetThemeDataFromTable("119410000001"); //client. // string pois = client.Search("", "STAN_NAME", "THEMENAME;X;Y", "VW_PLACENAME", 10); pois = client.Search("4303", "ID", "NAME;STATE;CSVRID;CYCAVAIL;CYCBACK;TIME;ADDR;CALL;SERVICE;TYPE", "VW_BIKE", 10); //ID,X,Y,站点名称,值守状态,CSVRID,可租数量,可还数量,服务时间,站点地址,服务电话,其他服务,站点备注 //pois = client.GetPois("ID", "X", "Y", "NAME;STATE;CSVRID;CYCAVAIL;CYCBACK;TIME;ADDR;CALL;SERVICE;TYPE", "VW_BIKE"); //client.GetPoiStates("ID", "STATE", "CYCAVAIL;CYCBACK", "VM_BIKE"); byte[] bytes = FX.Security.AesCryptography.Decrypt(pois); byte[] results = Cellbi.SvZLib.Utils.Decompress(bytes); /////// FX.Data.DataTable tbResult = FX.Serialization.DataContractSerialization.Deserialize <FX.Data.DataTable>(results) as FX.Data.DataTable; //CreateExcelSheet(tbResult); // string poi2 = System.Text.Encoding.UTF8.GetString(results); client.Close(); }
public void ProcessRequest(HttpContext context) { //context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); //1:编号查询 2:名称 string type = context.Request.QueryString["type"]; string keyword = context.Request.QueryString["keyword"]; if (keyword == null || keyword == "") { context.Response.Write("没有指定查询参数"); return; } string searchField = "CSVRID"; if (type == "1") { searchField = "CSVRID"; } else if (type == "2") { searchField = "NAME"; } string responseStr = this._client.Search(keyword, searchField, "NAME;STATE;CSVRID;CYCAVAIL;CYCBACK;TIME;ADDR;CALL;SERVICE;TYPE", "VW_BIKE", 10); byte[] bytes = FX.Security.AesCryptography.Decrypt(responseStr); byte[] results = Cellbi.SvZLib.Utils.Decompress(bytes); FX.Data.DataTable tbResult = FX.Serialization.DataContractSerialization.Deserialize <FX.Data.DataTable>(results) as FX.Data.DataTable; StringBuilder sb = new StringBuilder(); int i = 0; string id; string name; string cycavail; string cycback; string time; string addr; string call; string service; string bktype; string state; sb.Append("["); foreach (var row in tbResult.Rows) { id = row.Cells["csvrid"].ToString(); name = row.Cells["name"].ToString(); cycavail = row.Cells["cycavail"].ToString(); cycback = row.Cells["cycback"].ToString(); time = row.Cells["time"].ToString(); addr = row.Cells["addr"].ToString(); state = row.Cells["state"].ToString(); service = row.Cells["service"].ToString(); call = row.Cells["call"].ToString(); bktype = row.Cells["type"].ToString(); string record = string.Format("{{CSVRID:'{0}', NAME:'{1}',STATE:'{2}',CYCAVAIL:'{3}',CYCBACK:'{4}',TIME:'{5}',ADDR:'{6}',SERVICE:'{7}',TYPE:'{8}'}}", id, name, state, cycavail, cycback, time, addr, service, type); if (i != 0) { sb.Append(","); } sb.Append(record); i++; } sb.Append("]"); context.Response.Write(sb.ToString()); }