在asp.net中如何将 SQL2000的数据导出到Excel2010中... 在asp.net中如何将 SQL2000的数据导出到Excel2010中...以前都是Excel2003的, 现在是Excel2010的...请高人指点... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void InsertIntoExcel(Context.MainContext context) { Microsoft.Office.Interop.Excel.Application excelApp = new ApplicationClass(); object missingValue = Type.Missing; Workbook workBook = excelApp.Workbooks.Open(Directory.GetCurrentDirectory() + Program.SearchSingleMessage("M2"), missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue); // 试验扰动的数据时,活动的表单为第2个;记录正常数据时,活动的表单改为第1个 Worksheet workSheet; if (context.underDisturbance) { workSheet = (Worksheet)workBook.Sheets[2]; } else { workSheet = (Worksheet)workBook.Sheets[1]; } workSheet.Activate(); if (context.type == Program.ObjectType.DieselEngine) { for (int i = 0; i < Program.w.Length; i++) { workSheet.Cells[1 + i, 1] = Program.t[i].ToString(); workSheet.Cells[1 + i, 2] = Program.w[i].ToString(); workSheet.Cells[1 + i, 3] = Program.Td[i].ToString(); } } else if (context.type == Program.ObjectType.PowerStation) { for (int i = 0; i < Program.w.Length; i++) { workSheet.Cells[1 + i, 1] = Program.t[i].ToString(); workSheet.Cells[1 + i, 2] = Program.w[i].ToString(); workSheet.Cells[1 + i, 3] = Program.U[i].ToString(); workSheet.Cells[1 + i, 4] = Program.delta[i].ToString(); workSheet.Cells[1 + i, 5] = Program.Psai[i].ToString(); workSheet.Cells[1 + i, 6] = Program.I[i].ToString(); workSheet.Cells[1 + i, 7] = Program.Ia[i].ToString(); workSheet.Cells[1 + i, 8] = Program.Ib[i].ToString(); workSheet.Cells[1 + i, 9] = Program.Ic[i].ToString(); } } else if (context.type == Program.ObjectType.CUEP) { workSheet.Cells[1, 1] = "t"; workSheet.Cells[1, 2] = "w"; workSheet.Cells[1, 3] = "U"; workSheet.Cells[1, 4] = "delta"; workSheet.Cells[1, 5] = "Psai"; workSheet.Cells[1, 6] = "I"; workSheet.Cells[1, 7] = "Ia"; workSheet.Cells[1, 8] = "Ib"; workSheet.Cells[1, 9] = "Ic"; workSheet.Cells[1, 20] = "E'q"; workSheet.Cells[1, 21] = "Ud"; workSheet.Cells[1, 22] = "Uq"; for (int i = 0; i < Program.w.Length; i++) { try { workSheet.Cells[2 + i, 1] = Program.t[i].ToString(); workSheet.Cells[2 + i, 2] = Program.w[i].ToString(); workSheet.Cells[2 + i, 3] = Program.U[i].ToString(); workSheet.Cells[2 + i, 4] = Program.delta[i].ToString(); workSheet.Cells[2 + i, 5] = Program.Psai[i].ToString(); workSheet.Cells[2 + i, 6] = Program.I[i].ToString(); workSheet.Cells[2 + i, 7] = Program.Ia[i].ToString(); workSheet.Cells[2 + i, 8] = Program.Ib[i].ToString(); workSheet.Cells[2 + i, 9] = Program.Ic[i].ToString(); // 相关因子的字符形式与相关因子的模 workSheet.Cells[2 + i, 10] = ((Complex)((Complex[])Program.relatedFacotr[i])[0]).ToString(); workSheet.Cells[2 + i, 11] = ((Complex)((Complex[])Program.relatedFacotr[i])[0]).Abs().ToString(); workSheet.Cells[2 + i, 12] = ((Complex)((Complex[])Program.relatedFacotr[i])[1]).ToString(); workSheet.Cells[2 + i, 13] = ((Complex)((Complex[])Program.relatedFacotr[i])[1]).Abs().ToString(); workSheet.Cells[2 + i, 14] = ((Complex)((Complex[])Program.relatedFacotr[i])[2]).ToString(); workSheet.Cells[2 + i, 15] = ((Complex)((Complex[])Program.relatedFacotr[i])[2]).Abs().ToString(); workSheet.Cells[2 + i, 16] = ((Complex)((Complex[])Program.relatedFacotr[i])[3]).ToString(); workSheet.Cells[2 + i, 17] = ((Complex)((Complex[])Program.relatedFacotr[i])[3]).Abs().ToString(); workSheet.Cells[2 + i, 18] = ((Complex)((Complex[])Program.relatedFacotr[i])[4]).ToString(); workSheet.Cells[2 + i, 19] = ((Complex)((Complex[])Program.relatedFacotr[i])[4]).Abs().ToString(); // 除了转速与功角的状态变量记录下来 workSheet.Cells[2 + i, 20] = Program.E1q[i].ToString(); workSheet.Cells[2 + i, 21] = Program.Ud[i].ToString(); workSheet.Cells[2 + i, 22] = Program.Uq[i].ToString(); } catch (Exception ex) { break; } } } workBook.Save(); workBook.Close(true, null, null); System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); workSheet = null; workBook = null; excelApp = null; GC.Collect(); } http://www.javaeye.com/topic/205802 打开excel二维数组赋值gridview导出 xml形式导出 兼容2003,2010格式的导出方法http://dotnet.aspx.cc/file/Export-Gridview-To-Excel-With-Multi-Sheet.aspx 我原先的代码在调试时候,就可以正常导出,不调试运行,就不能正常导出错误提示是: Microsoft Jet 数据库引擎打不开文件...应该是权限的问题吧...请高手指点... 在文件夹给net用户写入的权限。 请问submit和button的区别 关于asp.net编译的问题? 重写 高手帮忙:asp.net 做安装打包时 是否安装"SQL server 2000 "的启动条件的Condition 如何写, FreeTextBox使用时的一个问题,有人碰到过吗? access问题 包含文件里的字符串在声明后的下一行赋值为什么总报错? 又一菜级问题(老问菜问题,自己都不好意思了) WebControl中包含的中文字显示不正常? 怎么让vs里已经与数据库链接了的表单再和其他asp之间实现跳转? asp 32位下编译的dll - 在x64下无法运行的错误
{
Microsoft.Office.Interop.Excel.Application excelApp = new ApplicationClass();
object missingValue = Type.Missing;
Workbook workBook = excelApp.Workbooks.Open(Directory.GetCurrentDirectory() + Program.SearchSingleMessage("M2"),
missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue,
missingValue, missingValue, missingValue, missingValue, missingValue, missingValue, missingValue);
// 试验扰动的数据时,活动的表单为第2个;记录正常数据时,活动的表单改为第1个
Worksheet workSheet;
if (context.underDisturbance)
{
workSheet = (Worksheet)workBook.Sheets[2];
}
else
{
workSheet = (Worksheet)workBook.Sheets[1];
}
workSheet.Activate(); if (context.type == Program.ObjectType.DieselEngine)
{
for (int i = 0; i < Program.w.Length; i++)
{
workSheet.Cells[1 + i, 1] = Program.t[i].ToString();
workSheet.Cells[1 + i, 2] = Program.w[i].ToString();
workSheet.Cells[1 + i, 3] = Program.Td[i].ToString();
}
}
else if (context.type == Program.ObjectType.PowerStation)
{
for (int i = 0; i < Program.w.Length; i++)
{
workSheet.Cells[1 + i, 1] = Program.t[i].ToString();
workSheet.Cells[1 + i, 2] = Program.w[i].ToString();
workSheet.Cells[1 + i, 3] = Program.U[i].ToString();
workSheet.Cells[1 + i, 4] = Program.delta[i].ToString();
workSheet.Cells[1 + i, 5] = Program.Psai[i].ToString();
workSheet.Cells[1 + i, 6] = Program.I[i].ToString();
workSheet.Cells[1 + i, 7] = Program.Ia[i].ToString();
workSheet.Cells[1 + i, 8] = Program.Ib[i].ToString();
workSheet.Cells[1 + i, 9] = Program.Ic[i].ToString();
}
}
else if (context.type == Program.ObjectType.CUEP)
{
workSheet.Cells[1, 1] = "t";
workSheet.Cells[1, 2] = "w";
workSheet.Cells[1, 3] = "U";
workSheet.Cells[1, 4] = "delta";
workSheet.Cells[1, 5] = "Psai";
workSheet.Cells[1, 6] = "I";
workSheet.Cells[1, 7] = "Ia";
workSheet.Cells[1, 8] = "Ib";
workSheet.Cells[1, 9] = "Ic";
workSheet.Cells[1, 20] = "E'q";
workSheet.Cells[1, 21] = "Ud";
workSheet.Cells[1, 22] = "Uq";
for (int i = 0; i < Program.w.Length; i++)
{
try
{
workSheet.Cells[2 + i, 1] = Program.t[i].ToString();
workSheet.Cells[2 + i, 2] = Program.w[i].ToString();
workSheet.Cells[2 + i, 3] = Program.U[i].ToString();
workSheet.Cells[2 + i, 4] = Program.delta[i].ToString();
workSheet.Cells[2 + i, 5] = Program.Psai[i].ToString();
workSheet.Cells[2 + i, 6] = Program.I[i].ToString();
workSheet.Cells[2 + i, 7] = Program.Ia[i].ToString();
workSheet.Cells[2 + i, 8] = Program.Ib[i].ToString();
workSheet.Cells[2 + i, 9] = Program.Ic[i].ToString();
// 相关因子的字符形式与相关因子的模
workSheet.Cells[2 + i, 10] = ((Complex)((Complex[])Program.relatedFacotr[i])[0]).ToString();
workSheet.Cells[2 + i, 11] = ((Complex)((Complex[])Program.relatedFacotr[i])[0]).Abs().ToString();
workSheet.Cells[2 + i, 12] = ((Complex)((Complex[])Program.relatedFacotr[i])[1]).ToString();
workSheet.Cells[2 + i, 13] = ((Complex)((Complex[])Program.relatedFacotr[i])[1]).Abs().ToString();
workSheet.Cells[2 + i, 14] = ((Complex)((Complex[])Program.relatedFacotr[i])[2]).ToString();
workSheet.Cells[2 + i, 15] = ((Complex)((Complex[])Program.relatedFacotr[i])[2]).Abs().ToString();
workSheet.Cells[2 + i, 16] = ((Complex)((Complex[])Program.relatedFacotr[i])[3]).ToString();
workSheet.Cells[2 + i, 17] = ((Complex)((Complex[])Program.relatedFacotr[i])[3]).Abs().ToString();
workSheet.Cells[2 + i, 18] = ((Complex)((Complex[])Program.relatedFacotr[i])[4]).ToString();
workSheet.Cells[2 + i, 19] = ((Complex)((Complex[])Program.relatedFacotr[i])[4]).Abs().ToString();
// 除了转速与功角的状态变量记录下来
workSheet.Cells[2 + i, 20] = Program.E1q[i].ToString();
workSheet.Cells[2 + i, 21] = Program.Ud[i].ToString();
workSheet.Cells[2 + i, 22] = Program.Uq[i].ToString();
}
catch (Exception ex)
{
break;
}
}
} workBook.Save();
workBook.Close(true, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workSheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);
workSheet = null;
workBook = null;
excelApp = null;
GC.Collect();
}
gridview导出
xml形式导出
http://dotnet.aspx.cc/file/Export-Gridview-To-Excel-With-Multi-Sheet.aspx
在文件夹给net用户写入的权限。