【问题标题】:Writing in an Excel file from VB.net when you don't know the range name当您不知道范围名称时,从 VB.net 写入 Excel 文件
【发布时间】:2016-07-26 03:52:33
【问题描述】:

我想使用行号/列号而不是范围名称写入 excel。我发现这样做的唯一方法是使用 .Cells 属性,但是当我尝试使用它时总是会收到错误 0x800A03EC。我试图尽可能地简化它以弄清楚如何使它工作。下面的代码适用于“test1”,当它尝试编写“test2”时出现错误。我在 W10 上运行 excel 2016 和最新版本的 Visual Studio

Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet

xlWorkBook = xlApp.Workbooks.Add
xlApp.Visible = True
xlWorkSheet = xlWorkBook.Sheets("Sheet1")

With xlWorkSheet
    .Range("A1").Value = "test1"
    .Range(.Cells(8, 8)).Value = "test2"
End With

有人可以帮我弄清楚如何解决它或知道另一种方法吗?

【问题讨论】:

  • xlWorkSheet.Cells(8, 8) 返回一个 Excel.Range 对象,所以只需使用 xlWorkSheet.Cells(8, 8).Value = "test2"

标签: vb.net excel office-interop


【解决方案1】:
.Range(.Cells(8, 8)).Value = "test2"

取出 .Range()。该行只需要:

.Cells(8,8).Value = "test2"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多