如何在winform中打開一個Excel文件 我知道是要使用axSpreadSheet控件,但是如何把他和一個已存在的Excel文件關聯起來?也就是如何初始化這個axSpreadSheet控件?謝謝! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://dev.csdn.net/article/54/article/45/45299.shtm 先要添加对Excel的引用。选择项目-〉添加引用-〉COM-〉添加Microsoft Excel 9.0。(不同的office讲会有不同版本的dll文件)。 using Excel; using System.Reflection; //产生一个Excel.Application的新进程 Excel.Application app = new Excel.Application(); if (app == null) { statusBar1.Text = "ERROR: EXCEL couldn''t be started!"; return ; } app.Visible = true; //如果只想用程序控制该excel而不想让用户操作时候,可以设置为false app.UserControl = true; Workbooks workbooks =app.Workbooks; _Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet); //根据模板产生新的workbook// _Workbook workbook = workbooks.Add("c:\\a.xls"); //或者根据绝对路径打开工作簿文件a.xls Sheets sheets = workbook.Worksheets; _Worksheet worksheet = (_Worksheet) sheets.get_Item(1); if (worksheet == null) { statusBar1.Text = "ERROR: worksheet == null"; return; } // This paragraph puts the value 5 to the cell G1 Range range1 = worksheet.get_Range("A1", Missing.Value); if (range1 == null) { statusBar1.Text = "ERROR: range == null"; return; } const int nCells = 2345; range1.Value2 = nCells; to cheng362000(星之辰) 這種做法是在程序的外面打開了一個Excel應用,我是想在一個winform中打開一個excel文件。anyway ,thks for reply! winform里怎么自动获取访问者的ID,域名和访问时间呢? listview问题!! 小白求教:关于委托事件的理解(甚是搞不明白)! OWC画图 多线程每天定时执行一个方法,怎么做????在线等 求教:文档管理系统 高分求难题```高手请进``` datagrid中数据显示的问题 一个winform程序,使用了this.close()为何在后台中还能看到这个进程? 求助!C#将区位码转换为汉字,急急急!!! C#怎么读写映射共享内存,急急 ,谢谢了 大家看看这是哪的问题?为什么EXE在2000不能执行,在98就可以?
using Excel;
using System.Reflection;
//产生一个Excel.Application的新进程
Excel.Application app = new Excel.Application();
if (app == null)
{
statusBar1.Text = "ERROR: EXCEL couldn''t be started!";
return ;
}
app.Visible = true; //如果只想用程序控制该excel而不想让用户操作时候,可以设置为false
app.UserControl = true;
Workbooks workbooks =app.Workbooks;
_Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet); //根据模板产生新的workbook
// _Workbook workbook = workbooks.Add("c:\\a.xls"); //或者根据绝对路径打开工作簿文件a.xls Sheets sheets = workbook.Worksheets;
_Worksheet worksheet = (_Worksheet) sheets.get_Item(1);
if (worksheet == null)
{
statusBar1.Text = "ERROR: worksheet == null";
return;
} // This paragraph puts the value 5 to the cell G1
Range range1 = worksheet.get_Range("A1", Missing.Value);
if (range1 == null)
{
statusBar1.Text = "ERROR: range == null";
return;
}
const int nCells = 2345;
range1.Value2 = nCells;
這種做法是在程序的外面打開了一個Excel應用,我是想在一個winform中打開一個excel文件。
anyway ,thks for reply!