“object”未包含“get_Range”的定义
本帖最后由 a2562447 于 2012-03-24 02:20:00 编辑
各位大大 VS2010 EXCEL2003 版本 想把DATAGRIDVIEW数据导出成EXCEL 代码如下:
public static void GetStudentExcel(System.Windows.Forms.DataGridView dgvStuInfo)
{
Application excel = new Application();
excel.SheetsInNewWorkbook = 1;
excel.Workbooks.Add();
excel.Cells[1, 1] = "学号";
excel.Cells[1, 2] = "密码";
excel.Cells[1, 3] = "姓名";
excel.Cells[1, 4] = "性别";
excel.Cells[1, 5] = "年级";
excel.Cells[1, 6] = "电话";
excel.Cells[1, 7] = "地址";
excel.Cells[1, 8] = "出生日期";
excel.Cells[1, 9] = "邮箱";
//获取标题行的单元格
Range range = excel.get_Range(excel.Cells[1, 1], excel.Cells[1, 10]);
//设置字体加粗
range.Font.Bold = true;
//设置字体颜色
range.Font.ColorIndex = 0;
//设置颜色背景
range.Interior.ColorIndex = 15;
//设置边框样式
range.Borders.LineStyle = XlLineStyle.xlContinuous;
//循环DateGridView中的数据赋值到Excel中
int i = 0, j = 0;
for (i = 0; i < dgvStuInfo.Rows.Count; i++)
{
for (j = 0; j < 3; j++)
{
excel.Cells[i + 2, j + 1] =
dgv