“object”未包含“get_Range”的定义
各位大大 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] =
dgvStuInfo.Rows[i].Cells[j].Value.ToString();
}
//设置性别
excel.Cells[i + 2, 4] =
dgvStuInfo.Rows[i].Cells["Sex"].Value.ToString()
== "False" ? "男" : "女";
//设置显示的学生年级
System.Windows.Forms.DataGridViewComboBoxCell dgvCbo = (System.Windows.Forms.DataGridViewComboBoxCell)
dgvStuInfo.Rows[i].Cells["GradeId"];
excel.Cells[i + 2, 5] = dgvCbo.FormattedValue.ToString();
for (j = 5; j < 10; j++)
{
excel.Cells[i + 2, j + 1] =
dgvStuInfo.Rows[i].Cells[j].Value.ToString();
}
}
excel.get_Range(excel.Cells[2, 8], excel.Cells[i + 2, 8]).NumberFormat = "yyyy-m-d";
//显示当前窗口
excel.Visible = true;
}
总是说未包含get_Range的定义
求解决
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] =
dgvStuInfo.Rows[i].Cells[j].Value.ToString();
}
//设置性别
excel.Cells[i + 2, 4] =
dgvStuInfo.Rows[i].Cells["Sex"].Value.ToString()
== "False" ? "男" : "女";
//设置显示的学生年级
System.Windows.Forms.DataGridViewComboBoxCell dgvCbo = (System.Windows.Forms.DataGridViewComboBoxCell)
dgvStuInfo.Rows[i].Cells["GradeId"];
excel.Cells[i + 2, 5] = dgvCbo.FormattedValue.ToString();
for (j = 5; j < 10; j++)
{
excel.Cells[i + 2, j + 1] =
dgvStuInfo.Rows[i].Cells[j].Value.ToString();
}
}
excel.get_Range(excel.Cells[2, 8], excel.Cells[i + 2, 8]).NumberFormat = "yyyy-m-d";
//显示当前窗口
excel.Visible = true;
}
总是说未包含get_Range的定义
求解决
...全文
相关推荐
怎样在C#中把GRIDVIEW的数据导出为EXCEL
("\n", "")); } } excelCell = xSt.get_Range(excel.Cells[i + 2, 1], excel.Cells[i + 2, iVisable]); excelCell.Value2
Django Python 获取请求头信息Content-Range的方法
- REMOTE_HOST - 客户端的主机名。- REMOTE_USER - 如果有的话,由Web服务器认证的用户。- REQUEST_METHOD - 如"GET"或"POST"这样的字符串。
SAP自定义自增ID序号及调用代码
CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING nr_range_nr = '1' object = 'ZHLY_SID' IMPORTING number = p_id
get-range惰性数值范围生成器
get-range惰性数值范围生成器"是一个这样的工具,它专注于生成数值范围,但采用了一种称为“惰性计算”或“延迟评估”的策略。这种策略允许我们仅在需要时计算值,从而提高性能并降低内存占用。
取得number range的下一個數字的方式.doc
NR_RANGE_NR "Number Range的编号 OBJECT = OBJECT "对象类型,如'INVOICE'或'ORDER' IMPORTING NUMBER = NUMBER.


