我想在客户端输出excle怎么做,我会使用response在客户端输出csv文件,但是excle那样输出 的话,数据不能顺序写到对应的cell里。请大家告诉我一下。
解决方案 »
- 执行sql语句,不是反回的datatable和dataset吗,
- dataGridView 的columnType设为DataGridViewCheckBoxColumn的列为何不能自动排序
- 初学网络编程碰到关于“开始监听”的问题
- 正则表达式,请帮看看
- winform中dataGridView 点击删除按钮的事件时删除我选中的行
- 发分拉!!解决一个问题。
- winform下的datagrid问题请教
- 问题:基础连接已经关闭: 无法解析此远程名称。
- radiobuttonlist选中项加粗显示
- C#可否调用原先的MFC库
- 问个google上的网页控件
- 将dataGridView中显示的数据打印出来
改成你想要的顺序啊
比如:select c,b,d,b from tb
网上有很多代码的
http://www.withub-soft.com/Show_IT.asp?id=225
http://www.360doc.com/content/07/0824/10/12027_691547.shtml
{
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导入导出 你看看