使用asp.net,把access数据库表导出到Excel表制定的位置,怎么做啊,谢谢高手帮助
------解决方案--------------------------------------------------------
给你部分参考代码
- C# code
//创建Excel对象 Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); //设置Excel标题 excel.Caption = "学生成绩"; //设置Excel列名 excel.Cells[1, 1] = "学生姓名"; excel.Cells[1, 2] = "科目"; excel.Cells[1, 3] = "成绩"; excel.Cells[1, 4] = "考试时间"; //设置Excel字体加粗 excel.get_Range(excel.Cells[1, 1], excel.Cells[1, 4]).Font.Bold = true; //设置Excel字体颜色 excel.get_Range(excel.Cells[1, 1], excel.Cells[1, 4]).Font.ColorIndex = 0; //设置Excel边框样式 excel.get_Range(excel.Cells[1, 1], excel.Cells[1, 4]).Borders.LineStyle = XlLineStyle.xlContinuous; //循环将DataGridView中的数据赋值到Excel中 for (int m = 0; m < dgvResult.Rows.Count; m++) { DataGridViewComboBoxCell dgvCbo = (DataGridViewComboBoxCell)dgvResult.Rows[m].Cells["StudentNo"]; excel.Cells[m + 2, 1] = dgvCbo.FormattedValue.ToString();//设置学生姓名 } int i; for (i = 0; i < dgvResult.Rows.Count; i++) { excel.Cells[i + 2, 2] = dgvResult.Rows[i].Cells["SubjectName"].Value.ToString(); excel.Cells[i + 2, 3] = dgvResult.Rows[i].Cells["StudentResult"].Value.ToString(); excel.Cells[i + 2, 4] = dgvResult.Rows[i].Cells["ExamDate"].Value.ToString(); } //设置Excel水平对齐方式 excel.get_Range(excel.Cells[1, 1], excel.Cells[i + 2, 4]).HorizontalAlignment = XlHAlign.xlHAlignLeft; //显示当前窗口 excel.Visible = true;