请教高手C#怎么操作 excel 为什么我的代码不能运行,求高手解答
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace writeExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Excel.Application excel = new Excel.Application();
object Nothing = System.Type.Missing;
Excel.Workbook wBook = Excel.Workbook.Add(true);
Excel.Worksheet wSheet = (Excel.Worksheet)wBook.ActiveSheet;
excel.Cells[3, 5] = "本公司电话: " + Phone;
excel.Cells[4, 5] = "本公司传真: " + Zhen;
excel.Cells[5, 5] = "联系人: " + ComName;
excel.Cells[4, 1] = "客户: " + CustomerName;
excel.Cells[5, 1] = "联系人: " + Associate;
excel.Cells[3, 8] = "户名:";
excel.Cells[3, 9] = AccountName;
excel.Cells[4, 8] = "开户行:";
excel.Cells[4, 9] = BranchName;
excel.Cells[5, 8] = "帐号:";
excel.Cells[5, 9] = "'" + AccountID;
}
}
我是对比了网上的几个代码 ,怎么会不能用呢 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace writeExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Excel.Application excel = new Excel.Application();
object Nothing = System.Type.Missing;
Excel.Workbook wBook = Excel.Workbook.Add(true);
Excel.Worksheet wSheet = (Excel.Worksheet)wBook.ActiveSheet;
excel.Cells[3, 5] = "本公司电话: " + Phone;
excel.Cells[4, 5] = "本公司传真: " + Zhen;
excel.Cells[5, 5] = "联系人: " + ComName;
excel.Cells[4, 1] = "客户: " + CustomerName;
excel.Cells[5, 1] = "联系人: " + Associate;
excel.Cells[3, 8] = "户名:";
excel.Cells[3, 9] = AccountName;
excel.Cells[4, 8] = "开户行:";
excel.Cells[4, 9] = BranchName;
excel.Cells[5, 8] = "帐号:";
excel.Cells[5, 9] = "'" + AccountID;
}
}
我是对比了网上的几个代码 ,怎么会不能用呢 展开
1个回答
展开全部
//Excel.Workbook wBook = Excel.Workbook.Add(true);//这一句有误。
//修改为
Excel.Workbook wBook = excel.Workbooks.Add(true);
//再在最后添加一句就可看到电子表格了。
excel.Visible = true;
//另外你的其他变量都赋值了吗?
//Phone Zhen .....
//如果这些变量未定义也会出错。这个你自己改
//修改为
Excel.Workbook wBook = excel.Workbooks.Add(true);
//再在最后添加一句就可看到电子表格了。
excel.Visible = true;
//另外你的其他变量都赋值了吗?
//Phone Zhen .....
//如果这些变量未定义也会出错。这个你自己改
追问
已经解决,是office2007没有正确安装,原来安装的时候出错了,安装的有问题,现在卸载了安装了office2010.不过分还给你。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询