excel2003操作问题,在线~给个例子,大侠们:)

didibaba 2005-03-16 02:59:17
1、Excel里面的_ExcelApplication、_ExcelApplicationClass 这两个类有什么区别??
Dim ExcelFileClass As New Excel._ExcelApplication
Dim ExcelFileClass As New Excel._ExcelApplicationClass

2、我想打开一个Excel文件,用ExcelFileClass.Workbooks.open
居然没有open这个函数??

搞过的大侠帮帮兄弟我:D
...全文
306 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackie615 2005-03-16
  • 打赏
  • 举报
回复
mark
hedonister 2005-03-16
  • 打赏
  • 举报
回复
不错
尚和空四 2005-03-16
  • 打赏
  • 举报
回复
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);
}
myExcel.Quit();
#endregion
}
}
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
daisy8675 2005-03-16
  • 打赏
  • 举报
回复
mark
hamadou 2005-03-16
  • 打赏
  • 举报
回复
Dim xlApp As New Excel.Application()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

Dim rowIndex, colIndex As Integer
rowIndex = 1
colIndex = 0

xlBook = xlApp.Workbooks().Add
xlSheet = xlBook.Worksheets("sheet1")

Dim Table As New DataTable()
Table = CreaTable()

'将所得到的表的列名,赋值给单元格
Dim Col As DataColumn
Dim Row As DataRow
For Each Col In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(1, colIndex) = Col.ColumnName
Next

'得到的表所有行,赋值给单元格
For Each Row In Table.Rows
rowIndex = rowIndex + 1
colIndex = 0
For Each Col In Table.Columns
colIndex = colIndex + 1
xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)
Next
Next

With xlSheet
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑体"
'设标题为黑体字
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
'标题字体加粗
.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1
'设表格边框样式
End With

tianweima 2005-03-16
  • 打赏
  • 举报
回复
this.ofdData.Title="打开数据记录文件";
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)
{
try
{
#region 数据连拉方式
// System.Data.OleDb.OleDbConnection oc=new OleDbConnection();
// oc.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + strFileName + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
// 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
{
#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);
}
myExcel.Quit();
#endregion
}
}
}
}
catch(System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
landlordh 2005-03-16
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3819/3819168.xml?temp=.926037

http://blog.csdn.net/landlordh/archive/2005/01/14/253457.aspx

16,552

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧