我有一个类的数据,有的是string 有的是double数组等数据,想把这些数据导入到Excel表格中方便查看的编辑,寻求高手指示。
例如
string strName = "Table1";
string strTime = "2010-09-19";
double[] dValue = new double[500];样子是
strName Table1
strTime 2010-09-19
dValue
0 4
1 32.2
......
499 54.2
这样,有简便方法么?
例如
string strName = "Table1";
string strTime = "2010-09-19";
double[] dValue = new double[500];样子是
strName Table1
strTime 2010-09-19
dValue
0 4
1 32.2
......
499 54.2
这样,有简便方法么?
context.Response.ContentType = "text/plain";
HttpResponse resp;
resp = context.Response;
resp.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
resp.AppendHeader("Content-Disposition", "attachment;filename=" + 文件名+ ".csv");
System.Data.DataTable dt = DateTable(内容);
想要什么格式.在下面Wirte输出就行了.
resp.Write("你要输出的格式 \n"); 最后加一句
context.Response.End();
}
{
//导出到execl
try
{
//没有数据的话就不往下执行
if (dataGridView1.Rows.Count == 0)
return;
//实例化一个Excel.Application对象
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); //让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写
excel.Visible = false; //新增加一个工作簿,Workbook是直接保存,不会弹出保存对话框,加上Application会弹出保存对话框,值为false会报错
excel.Application.Workbooks.Add(true);
//生成Excel中列头名称
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
excel.Cells[1, i + 1] = list[i];
}
//把DataGridView当前页的数据保存在Excel中
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (dataGridView1[j, i].ValueType == typeof(string))
{
excel.Cells[i + 2, j + 1] = "'" + dataGridView1[j, i].Value.ToString();
}
else
{
excel.Cells[i + 2, j + 1] = dataGridView1[j, i].Value.ToString();
}
}
} //设置禁止弹出保存和覆盖的询问提示框
excel.DisplayAlerts = false;
excel.AlertBeforeOverwriting = false; //保存工作簿
excel.Application.Workbooks.Add(true).Save();
//保存excel文件
excel.Save("E:\\Region\\User_Region\\POS\\POS\\Excel" + "\\Model.xls"); //确保Excel进程关闭
excel.Quit();
excel = null; }
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误提示");
}
}
5楼的导出方式会不会很慢,如果我的数据量比较大时?
range.set_Value(Missing.Value, arrayData);
参考
http://support.microsoft.com/kb/302096/
range.set_Value(Missing.Value, arrayData);
参考
http://support.microsoft.com/kb/302096/
http://dotnet.aspx.cc/file/Export-Gridview-To-Excel-With-Multi-Sheet.aspx跟数据源没关系。你生成xml格式字符串,存成文件即可