我想在客户端输出excle怎么做,我会使用response在客户端输出csv文件,但是excle那样输出 的话,数据不能顺序写到对应的cell里。请大家告诉我一下。

解决方案 »

  1.   

     不会把select a,b,c,d from tb
    改成你想要的顺序啊
    比如:select c,b,d,b from tb
      

  2.   

    不是这个意思,我想前台输出excle,数据怎么写到excle里。
      

  3.   

    控制Excel里的cell值就可以啊
    网上有很多代码的
    http://www.withub-soft.com/Show_IT.asp?id=225
      

  4.   

    你说的应该是编码问题不过直接输出html内容到一个文件改后缀名为.xls是个不错的办法
      

  5.   

    服务器生成之后,让客户端下载。
    http://www.360doc.com/content/07/0824/10/12027_691547.shtml
      

  6.   

                public JExcelImportExport()
                {
                    open_dlg.Title = "选择Excel文件";
                    open_dlg.Multiselect = false;
                    open_dlg.Filter = "Excel文件(*.xls;*.xlsx)|*.xls;*.xlsx";
                    open_dlg.CheckPathExists = true;
                    open_dlg.CheckFileExists = true;
                    open_dlg.RestoreDirectory = true;                save_dlg.Title = "另存为Excel文件";
                    save_dlg.Filter = "Excel2003文件(*.xls)|*.xls|Excel2007文件(*.xlsx)|*.xlsx";
                    save_dlg.CheckPathExists = true;
                    save_dlg.RestoreDirectory = true;
                    save_dlg.OverwritePrompt = true;
                }            #region 从Excel导入数据            public DataSet ImportFromExcel()
                {
                    DataSet ds = null;                if(open_dlg.ShowDialog() == DialogResult.OK)
                    {
                        ds = ImportFromExcel(open_dlg.FileName);
                    }                return ds;
                }            public DataSet ImportFromExcel(string file_path)
                {
                    if(file_path == "")
                    {
                        return null;
                    }                connection = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + file_path + ";" +
                                 "Extended Properties=Excel 12.0";
                    OleDbDataAdapter excel_data = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", connection);                DataSet excel_ds = new DataSet();                try
                    {
                        excel_data.Fill(excel_ds);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                        return null;
                    }                return excel_ds;
                }            #endregion            #region 数据导出到Excel            public void ExportToExcel(DataSet ds)
                {
                    if(save_dlg.ShowDialog() == DialogResult.OK)
                    {
                        ExportToExcel(ds, save_dlg.FileName);
                    }
                }            public void ExportToExcel(List<JCustomerGeomInfo> customer_geom_info_list)
                {
                    if(save_dlg.ShowDialog() == DialogResult.OK)
                    {
                        ExportToExcel(customer_geom_info_list, save_dlg.FileName);
                    }
                }            public void ExportToExcel(DataSet ds, string file_store_path)
                {
                    ApplicationClass excel = new ApplicationClass();                int row_index = 1;
                    int col_index = 1;                excel.Application.Workbooks.Add(true);                System.Data.DataTable dt = ds.Tables[0];
                    foreach(DataColumn dc in dt.Columns)
                    {
                        excel.Cells[row_index, col_index] = dc.ColumnName;
                        col_index++;
                    }                foreach(DataRow dr in dt.Rows)
                    {
                        row_index++;
                        col_index = 1;                    foreach(DataColumn dc in dt.Columns)
                        {
                            excel.Cells[row_index, col_index] = dr[dc.ColumnName].ToString();
                            col_index++;
                        }
                    }                excel.Visible = false;                try
                    {
                        excel.ActiveWorkbook.SaveAs(file_store_path, XlFileFormat.xlWorkbookDefault, null, null, false,
                                                    false,
                                                    XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);
                    }
                    catch(Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        excel.Quit();
                        GC.Collect();
                    }
                }
    我以前写的excel导入导出 你看看