Application是个Excel的接口,通过ApplicationClass可以实现:
Excel.Application app = new Excel.ApplicationClass();
懂了吗?
Excel.Application app = new Excel.ApplicationClass();
懂了吗?
解决方案 »
- 为什么图片上传,报客户端的路径找不到?
- C# WINFORM 动态创建在panel上的button如何获取
- 原来c#中,类定义的花括号后,不用加分号呀,与c++语法差这么大?
- BeginInvoke的用法???
- 导入文件时,显示导入状态,winform完成
- 数据库设计
- PictureBox控件显示大尺寸图片的问题
- 讨论一个错误:>>创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke
- 请问:如何在Web窗体页中显示消息框(也就是MessageBox)
- 求一款好用的话python GUI工具
- 在form中用Datagrid ,Dataset最后显示不了数据
- 如何打开指定的excel文件并且 给指定的单元格更新一个数据
using System.Drawing ;
using System.Collections ;
using System.ComponentModel ;
using System.Windows.Forms ;
using System.Data ;
using System.Data.SqlClient ;
public class Form1 : Form
{
private Button button1 ;
private System.ComponentModel.Container components = null ;
public Form1 ( )
{//初始化窗体中的各个组件InitializeComponent ( ) ;
}
//清除程序中使用的各个资源
protected override void Dispose ( bool disposing )
{
if ( disposing ){if ( components != null ) {components.Dispose ( ) ;}}base.Dispose( disposing ) ;}
private void InitializeComponent ( )
{button1 = new Button ( ) ;SuspendLayout ( ) ;button1.Location = new System.Drawing.Point ( 32 , 72 ) ;button1.Name = "button1" ;button1.Size = new System.Drawing.Size ( 100 , 30 ) ;button1.TabIndex = 0 ;button1.Text = "调用Excel文件!" ;button1.Click += new System.EventHandler ( button1_Click ) ;AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;this.ClientSize = new System.Drawing.Size ( 292 , 273 ) ;this.Controls.Add ( button1 ) ;this.Name = "Form1" ;this.Text = "如何用Visual C#调用Excel表格!" ;this.ResumeLayout ( false ) ;}
static void Main ( )
{
Application.Run ( new Form1 ( ) ) ;
}
private void button1_Click ( object sender , System.EventArgs e )
{
Excel.Application excel = new Excel.Application( ) ;
excel.Application.Workbooks.Add ( true ) ;
excel.Cells[ 1 , 1 ] = "第一行第一列" ; excel.Cells[ 1 , 2 ] = "第一行第二列" ; excel.Cells[ 2 , 1 ] = "第二行第一列" ; excel.Cells[ 2 , 2 ] = "第二行第二列" ; excel.Cells[ 3 , 1 ] = "第三行第一列" ; excel.Cells[ 3 , 2 ] = "第三行第二列" ; excel.Visible = true ;
}}
看是否有帮助!
出现 未处理的“System.UnauthorizedAccessException”类型的异常出现在 WindowsApplication1.exe 中。其他信息: 拒绝访问。何解?