private static HttpGetHelper httpGetHelper; //定义HttpGetHelper获取经纬度对象 public static void Process(string originalFileName, int originalColumn, int targetColumn, int rows) { try { string workTmp = originalFileName; objExcelApp = new Application(); objExcelWorkBooks = objExcelApp.Workbooks; objExcelWorkbook = objExcelWorkBooks.Open(workTmp, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); objExcelWorkSheet = (Worksheet)objExcelWorkbook.Worksheets[1]; httpGetHelper = new HttpGetHelper(); for (int i = 2; /*objExcelWorkSheet.Cells[i, originalColumn].Text.ToString() != ""*/ i < rows + 2; i++) { string address = objExcelWorkSheet.Cells[i, originalColumn].Text.ToString(); string str = httpGetHelper.GaoDeAnalysis("key=3e0ded4b2852e194c63565d151c2e606&address=" + address); objExcelWorkSheet.Cells[i, targetColumn] = str; } string targetFileName = originalFileName.Insert(originalFileName.LastIndexOf('.'), "new"); objExcelWorkbook.SaveAs(targetFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); } finally { objExcelApp.Quit(); } }
private void Button_Click(object sender, RoutedEventArgs e) { Location.Text = httpGetHelper.GaoDeAnalysis("key=3e0ded4b2852e194c63565d151c2e606&address=" + Address.Text); }