C#中调用Exce一般采用下面的方法
Excel.Application xApp=new Excel.Application();
xBook = xApp.Workbooks._Open("abc.xls", Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value);如果Excel文件已经打开,怎么得到他
Excel.Application xApp=已经打开的Excel文件
哪位知道怎么实现
Excel.Application xApp=new Excel.Application();
xBook = xApp.Workbooks._Open("abc.xls", Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value ,Missing.Value,Missing.Value,Missing.Value,Missing.Value);如果Excel文件已经打开,怎么得到他
Excel.Application xApp=已经打开的Excel文件
哪位知道怎么实现
解决方案 »
- 【分享】C#制作的内存修改器
- 请教如何不触发KEYPRESS事件
- C# 如何高性能得到网络上的文件。(使用的文件是 多页的TIF文件)
- 高手请进!帮小妹看看这个是怎么回事?这个问题很棘手!
- 请问,大家如何做.net的排版的?vs下面做排版很难看啊,大家是怎么做的?还有如果我用DW开发.net,怎么在DW里有代码提示功能啊,象VS一样
- 求c#的sql server2000的数据库应用实例(图书管理系统)
- 怎样把数据表中的空值付值为零!谢谢!~~
- 请问如何简单编写打开文件夹的代码?
- 请问在contexMenu控件中show方法如何写
- 请问在窗口中显示Flash动画,用什么控件?
- 如何让程序在同一台机器上只可以有一个实例运行?
- 问各位大大一个关于数据绑定的问题:
DialogResult drl=this.ofdData.ShowDialog();
System.Data.DataSet ds=new DataSet();
ds.Tables.Add("tabPhone");
if(drl==DialogResult.OK)
{
try
{
foreach(string strFileName in this.ofdData.FileNames)
{
Excel.Application myExcel=new Excel.Application();
myExcel.Visible=false;
Excel.Workbook wb=myExcel.Workbooks.Open(strFileName,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
foreach(Excel.Worksheet ws in wb.Worksheets)
{
#region 读取单元格方式
// int intTitelRow=1,intTitelCol=1;
// for(int i=1;i<=ws.Rows.Count;i++)
// {
// if(ws.get_Range(ws.Cells[i,intTitelCol],ws.Cells[i,intTitelCol]).Value2==null)
// break;
// System.Data.DataRow dr=this.dsPhone1.tabPhone.NewRow();
// for(int j=1;j<=ws.Columns.Count;j++)
// {
// Excel.Range r=ws.get_Range(ws.Cells[i,j],ws.Cells[i,j]);
// Excel.Range r1=ws.get_Range(ws.Cells[intTitelRow,j],ws.Cells[intTitelRow,j]);
// if(r1.Value2==null)
// break;
// if(r.Value2.ToString().Trim()=="card_no")
// {
// intTitelRow=i;
// intTitelCol=j;
// break;
// }
// dr[r1.Value2.ToString()]=r.Value2.ToString();
// }
// this.dsPhone1.tabPhone.Rows.Add(dr);
// }
#endregion
#region 数据连拉方式
System.Data.OleDb.OleDbConnection oc=new OleDbConnection();
oc.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFileName + ";Extended Properties=Excel 8.0;";
System.Data.OleDb.OleDbDataAdapter oda=new OleDbDataAdapter("select * from ["+ws.Name+"$]",oc);
myExcel.Quit();
oda.Fill(ds,"tabPhone");
this.gexPhone.SetDataBinding(ds,"tabPhone");
this.gexPhone.RetrieveStructure();
oc.Close();
#endregion
}
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Sub GetExcel()
Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final release. ' Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application.
' If the application is not running, an error occurs.
MyXL = GetObject(, "Excel.Application")
If Err().Number <> 0 Then ExcelWasNotRunning = True
Err().Clear() ' Clear Err object in case error occurred. ' Check for Microsoft Excel. If Microsoft Excel is running,
' enter it into the Running Object table.
DetectExcel() ' Set the object variable to reference the file you want to see.
MyXL = GetObject("c:\vb\TEST.XLS") ' Show Microsoft Excel through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
' Do manipulations of your file here.
'
End Sub
private IntPtr _Handle; //用于保存Excel的窗口句柄
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);.......String WndClassCaption="Microsoft Excel - "+xlsName.Substring(xlsName.LastIndexOf (@"\")+1);
IntPtr hwnd_win = FindWindow("XLMAIN", WndClassCaption);
if(hwnd_win==IntPtr.Zero)
{
hwnd_win = FindWindow("MS-SDIa",xlsName.Substring(xlsName.LastIndexOf (@"\")+1));
if(hwnd_win==IntPtr.Zero)
{
MessageBox.Show ("没找到窗口类 "+xlsName.Substring(xlsName.LastIndexOf (@"\")+1));
return null;
}
}
////////XLMAIN,MS-SDIa 是用spy++看到的