如何使用Excel.Workbook操纵Excel工作簿 [英] How to manipulate an excel workbook with Excel.Workbook

查看:61
本文介绍了如何使用Excel.Workbook操纵Excel工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我找不到在 Excel.Workbook Excel.Application 中打开文件的任何方法,我想知道为什么.

So, I can't find any methods with file opening in Excel.Workbook or Excel.Application, and I am wondering why.

我有一个Excel文件的路径,我想对其进行操作.我了解我必须使用 Excel.Application Excel.Workbook Excel.Worksheet .Excel文件的文件是 ExcelFilePath ,我应该怎么做才能使它成为可能?

I have path to an Excel file, and I would like to manipulate it. I understand I have to use Excel.Application, Excel.Workbook, and Excel.Worksheet. The file to the Excel file is ExcelFilePath, what should I do to make it possible?

推荐答案

您首先需要将对 Microsoft.Office.Interop.Excel 的引用添加到您的项目中,以便使用Excel API,然后填写变量:

You first need to add the reference to Microsoft.Office.Interop.Excel to your project in order to use the Excel API, then fill the variables:

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWS As Excel.Worksheet

xlApp = New Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open(sFilePath)
xlWS = CType(xlWorkBook.Worksheets(sheetNameOrIndex), Excel.Worksheet)

然后您只需要使用它们具有的方法即可.例如:

And then you only need to use the methods they have. For example:

Dim sVar as String = xlWS.Range("C5").Value.ToString()

这篇关于如何使用Excel.Workbook操纵Excel工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆